name: Build for Linux and Windows (x86, x64)

on:
  workflow_call:
    inputs:
      update-caches:
        description: "Whether to update the `ccache` or `bazel` caches, where possible."
        default: false
        required: false
        type: boolean

jobs:

  cmake-linux-x86_64:
    runs-on: ubuntu-latest
    timeout-minutes: 60
    steps:
      - uses: actions/checkout@v4
      - name: Update apt
        run: sudo apt update
      - name: Install ninja
        run: sudo apt install ninja-build
      - name: Setup ccache
        uses: hendrikmuhs/ccache-action@v1.2
        with:
          key: ${{ github.job }}
          max-size: "500M"
          save: ${{ inputs.update-caches }}
      - name: Configure and build
        run: scripts/build-local.sh
        working-directory: ${{ github.workspace }}
      - name: Upload Build Artifacts
        uses: actions/upload-artifact@v4
        with:
          name: build-artifacts-linux-x86_64
          path: build/local

  cmake-windows-x86_64:
    runs-on: windows-latest
    timeout-minutes: 60
    strategy:
      matrix:
        arch: [x86, x64]
    steps:
      - uses: actions/checkout@v4
      - name: Setup ccache
        uses: hendrikmuhs/ccache-action@v1.2
        with:
          key: ${{ github.job }}
          max-size: "500M"
          save: ${{ inputs.update-caches }}
      - name: Install Ninja
        uses: seanmiddleditch/gha-setup-ninja@master
      - name: Setup build environment
        shell: bash
        run: |
          echo "VCVARSALL=$(vswhere -products \* -latest -property installationPath)\\VC\\Auxiliary\\Build\\vcvarsall.bat" >> $GITHUB_ENV
      - name: Configure and build
        run: scripts/build-windows-${{ matrix.arch }}.cmd
        shell: cmd
        working-directory: ${{ github.workspace }}
        env:
          CFLAGS: "/UNDEBUG"
          CXXFLAGS: "/UNDEBUG"
      - name: Upload Build Artifacts
        uses: actions/upload-artifact@v4
        with:
          name: build-artifacts-windows-${{ matrix.arch }}
          path: build/windows/${{ matrix.arch }}/