name: Build & test

on:
  push:
  pull_request:

env:
  SCCACHE_GHA_ENABLED: "true"
  RUSTC_WRAPPER: "sccache"

jobs:
  build:
    name: Build & test
    strategy:
      fail-fast: false
      matrix:
        os:
          - ubuntu-latest
          - macos-latest
          - windows-latest
        build_type:
          - RelWithDebInfo
          - Debug
    runs-on: ${{ matrix.os }}

    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Install dependencies (Ubuntu)
        if: ${{ matrix.os == 'ubuntu-latest' }}
        run: |
          sudo apt-get update
          sudo apt-get install build-essential git make pkg-config cmake ninja-build \
            libasound2-dev libpulse-dev libaudio-dev libfribidi-dev libjack-dev libsndio-dev \
            libx11-dev libxext-dev libx11-xcb-dev libxrandr-dev libxcursor-dev libxfixes-dev \
            libxi-dev libxss-dev libxtst-dev libxkbcommon-dev libdrm-dev libgbm-dev \
            libgl1-mesa-dev libgles2-mesa-dev libegl1-mesa-dev libdbus-1-dev libibus-1.0-dev \
            libudev-dev libthai-dev libpipewire-0.3-dev libwayland-dev libdecor-0-dev \
            liburing-dev

      - name: Install dependencies (macOS)
        if: ${{ matrix.os == 'macos-latest' }}
        run: brew install sdl3

      - name: Setup sccache
        uses: mozilla-actions/sccache-action@v0.0.10

      - name: Set up MSVC env
        if: ${{ matrix.os == 'windows-latest' }}
        uses: ilammy/msvc-dev-cmd@v1

      - name: Configure
        run: >
          cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
          -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache
          -DCMAKE_MSVC_DEBUG_INFORMATION_FORMAT=Embedded

      - name: Build
        run: cmake --build build

      - name: Test
        run: ctest --test-dir build --output-on-failure
