name: build on ubuntu base platform

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

env:
  # Customize CMake build type here
  BUILD_TYPE: Release

jobs:
  build:
    # This build won't be entirely reproducible, given ubuntu changes on github runners may
    # introduce regressions.
    #
    runs-on: ubuntu-latest

    steps:
      - name: checkout source
        uses: actions/checkout@v4

      - name: install apt deps
        run: |
          sudo apt update

          echo "::group::cmake install"
          sudo apt install -y cmake
          echo "::endgroup"

          echo "::group::git install"
          sudo apt install -y git
          echo "::endgroup"

          echo "::group::pybind11-dev install"
          sudo apt install -y pybind11-dev
          echo "::endgroup"

          echo "::group::libjsoncpp-dev install"
          sudo apt install -y libjsoncpp-dev
          echo "::endgroup"

          echo "::group::libwebsockets-dev install"
          sudo apt install -y libwebsockets-dev
          echo "::endgroup"

          echo "::group::llvm18 install"
          sudo apt install -y llvm-18-dev
          echo "::endgroup"

          echo "::group::doxygen install"
          sudo apt install -y doxygen
          echo "::endgroup"

          echo "::group::sphinx install"
          sudo apt install -y sphinx
          echo "::endgroup"

          echo "::group::libvulkan-dev install"
          sudo apt install -y libvulkan-dev
          echo "::endgroup"

          echo "::group::vulkan-tools install"
          sudo apt install -y vulkan-tools
          echo "::endgroup"

          echo "::group::vulkan-utility-libraries-dev install"
          sudo apt install -y vulkan-utility-libraries-dev
          echo "::endgroup"

          echo "::group::libsdl2-dev"
          sudo apt install -y libsdl2-dev
          echo "::endgroup"

          echo "::group::libbsd-dev"
          sudo apt install -y libbsd-dev
          echo "::endgroup"

          #echo "::group::clang18 install"
          #sudo apt install -y clang-18
          #echo "::group::lldb18 install"
          #sudo apt install -y lldb-18
          #echo "::group::lld18 install"
          #sudo apt install -y lld-18

      - name: build+install catch2
        run: |
          echo "::group::clone catch2"
          git clone https://github.com/catchorg/Catch2.git
          cd Catch2
          git checkout v2.13.8
          echo "::group::catch2 configure"
          mkdir .build
          cmake -B .build -S .
          echo "::endgroup"
          echo "::group::catch2 install"
          sudo cmake --build .build --target install
          echo "::endgroup"

          # this should be sufficient for find_package(Catch2) to work

      - name: clone imgui
        run: |

          echo "::group::clone imgui"
          git clone https://github.com/ocornut/imgui.git
          echo "::endgroup"

      - name: list /usr/lib
        run: |
          ls /usr/lib

      - name: bootstrap xo-cmake
        run: |
          PREFIX=${{github.workspace}}/local
          mkdir -p ${PREFIX}
          echo "::group::xo-cmake configure"
          cmake -B .build0 -S xo-cmake -DCMAKE_INSTALL_PREFIX=${PREFIX}
          echo "::endgroup"
          echo "::group::xo-cmake build"
          cmake --build .build0
          echo "::endgroup"
          echo "::group::xo-cmake install"
          cmake --install .build0
          echo "::endgroup"

      - name: build xo subprojects
        run: |
          PREFIX=${{github.workspace}}/local
          PATH=${{github.workspace}}/local/bin:${PATH}
          echo "::group::xo configure"
          cmake -B .build -S . -DCMAKE_INSTALL_PREFIX=${PREFIX} -DCMAKE_PREFIX_PATH=/usr/local # -DCMAKE_FIND_DEBUG_MODE=ON
          echo "::endgroup"

          # note: xo-foo targets exist, but don't build anything

          echo "::group::xo build"
          cmake --build .build #--verbose
          echo "::endgroup"

          echo "::group::xo install"
          cmake --install .build
          echo "::endgroup"

      - name: print install path
        run: |
          tree ${{github.workspace}}/local
