name: Build (C/P Actions)

on: [push, pull_request]

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
  cancel-in-progress: true

jobs:
  freebsd:
    runs-on: ubuntu-latest
    name: '${{ matrix.platform.name }} ${{ matrix.platform.os-version }}'
    timeout-minutes: 30
    strategy:
      fail-fast: false
      matrix:
        platform:
          - { name: FreeBSD,  os: freebsd,  os-version: 13.2, os-arch: x86-64,  artifact: SDL-freebsd-x64,
              sdl-cmake-configure-arguments: '-DSDL_CHECK_REQUIRED_INCLUDES="/usr/local/include" -DSDL_CHECK_REQUIRED_LINK_OPTIONS="-L/usr/local/lib"',
              setup-cmd: 'sudo pkg update',
              install-cmd: 'sudo pkg install -y cmake ninja pkgconf libXcursor libXext libXinerama libXi libXfixes libXrandr libXScrnSaver libXxf86vm wayland wayland-protocols libxkbcommon mesa-libs libglvnd evdev-proto libinotify alsa-lib jackit pipewire pulseaudio sndio dbus zh-fcitx ibus libudev-devd',
            }
          - { name: NetBSD,   os: netbsd,   os-version: 9.3,  os-arch: x86-64,  artifact: SDL-netbsd-x64,
              sdl-cmake-configure-arguments: '',
              setup-cmd: 'export PATH="/usr/pkg/sbin:/usr/pkg/bin:/sbin:$PATH";export PKG_CONFIG_PATH="/usr/pkg/lib/pkgconfig";export PKG_PATH="https://cdn.netBSD.org/pub/pkgsrc/packages/NetBSD/$(uname -p)/$(uname -r|cut -f "1 2" -d.)/All/";echo "PKG_PATH=$PKG_PATH";echo "uname -a -> \"$(uname -a)\"";sudo -E sysctl -w security.pax.aslr.enabled=0;sudo -E sysctl -w security.pax.aslr.global=0;sudo -E pkgin clean;sudo -E pkgin update',
              install-cmd: 'sudo -E pkgin -y install cmake dbus pkgconf ninja-build pulseaudio libxkbcommon wayland wayland-protocols libinotify libusb1',
            }
    steps:
    - uses: actions/checkout@v3
    - name: Build
      uses: cross-platform-actions/action@v0.21.1
      with:
        operating_system: ${{ matrix.platform.os }}
        architecture: ${{ matrix.platform.os-arch }}
        version: ${{ matrix.platform.os-version }}
        run: |
          ${{ matrix.platform.setup-cmd }}
          ${{ matrix.platform.install-cmd }}
          cmake -S . -B build -GNinja  \
            -Wdeprecated -Wdev -Werror \
            -DCMAKE_BUILD_TYPE=Release \
            -DSDL_WERROR=ON \
            ${{ matrix.platform.sdl-cmake-configure-arguments }}
          cmake --build build/ --config Release --verbose
          cmake --build build/ --config Release --target package

          cmake --build build/ --config Release --target clean
          rm -rf build/dist/_CPack_Packages
          rm -rf build/CMakeFiles
          rm -rf build/docs

    - uses: actions/upload-artifact@v3
      with:
        if-no-files-found: error
        name: ${{ matrix.platform.artifact }}
        path: build/dist/SDL3*
