name: Build

on: [push, pull_request]

jobs:
  build-current-toolchain:
    name: 'Current ${{ matrix.toolchain.name }}'
    runs-on: windows-latest
    defaults:
      run:
        shell: ${{ matrix.toolchain.shell }}
    strategy:
      fail-fast: false
      matrix:
        toolchain:
        - { name: 'MSVC (32-bit)',  shell: 'sh',  setup-cmake: true, setup-ninja: true, setup-msvc: true, vc-arch: 'amd64_x86', dx5-libs: true,   d3drm-from-wine: false }
        - { name: 'MSVC (64-bit)',  shell: 'sh',  setup-cmake: true, setup-ninja: true, setup-msvc: true, vc-arch: 'amd64',     dx5-libs: false,  d3drm-from-wine: true }
        - { name: 'msys2 mingw32',  shell: 'msys2 {0}', msystem: mingw32, msys-env: mingw-w64-i686,        clang-tidy: true, werror: true, dx5-libs: false, d3drm-from-wine: true }
        - { name: 'msys2 mingw64',  shell: 'msys2 {0}', msystem: mingw64, msys-env: mingw-w64-x86_64,      clang-tidy: true, werror: true, dx5-libs: false, d3drm-from-wine: true }
        # - { name: 'msys2 clang32',  shell: 'msys2 {0}', msystem: clang32, msys-env: mingw-w64-clang-i686,  clang-tidy: true, werror: true, dx5-libs: true, d3drm-from-wine: true }

    steps:
      - name: Setup vcvars
        if: matrix.toolchain.setup-msvc
        uses: ilammy/msvc-dev-cmd@v1
        with:
          arch: ${{ matrix.toolchain.vc-arch }}
      # Figure out how to build for 32-bit arch
      # - name: Set up SDL
      #   id: sdl
      #   uses: libsdl-org/setup-sdl@main
      #   with:
      #     version: sdl3-head

      - name: Set up MSYS2
        if: ${{ !!matrix.toolchain.msystem }}
        uses: msys2/setup-msys2@v2
        with:
          msystem: ${{ matrix.toolchain.msystem }}
          install: >-
            ${{ matrix.toolchain.msys-env }}-cc
            ${{ matrix.toolchain.msys-env }}-cmake
            ${{ matrix.toolchain.msys-env }}-ninja
            ${{ matrix.toolchain.msys-env }}-clang-tools-extra

      - name: Setup cmake
        if: matrix.toolchain.setup-cmake
        uses: jwlawson/actions-setup-cmake@v1.13

      - name: Setup ninja
        if: matrix.toolchain.setup-ninja
        uses: ashutoshvarma/setup-ninja@master

      - uses: actions/checkout@v4
        with:
          submodules: true

      - name: Build
        # Add -DDOWNLOAD_DEPENDENCIES=OFF once setup-sdl works
        run: |
          cmake -S . -B build -GNinja \
            -DCMAKE_BUILD_TYPE=Debug \
            -DISLE_USE_DX5=${{ matrix.toolchain.dx5-libs }} \
            -DISLE_D3DRM_FROM_WINE=${{ matrix.toolchain.d3drm-from-wine }} \
            -DENABLE_CLANG_TIDY=${{ !!matrix.toolchain.clang-tidy }} \
            -DISLE_WERROR=${{ !!matrix.toolchain.werror }} \
            -Werror=dev
          cmake --build build -- -k0
