name: re3 cmake devkitA64 (Nintendo Switch)

on:
  pull_request:
  push:
    branches: [ main, master ]
  release:
    types: [ published ]

jobs:
  build-nintendo-switch:
    runs-on: ubuntu-latest
    container: devkitpro/devkita64:latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - { name: 10thae,  rt: "ON"  }
          - { name: vanilla, rt: "OFF" }

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          submodules: 'recursive'
          fetch-depth: 0

      - name: Build files (${{ matrix.name }})
        run: |
          mkdir -p build
          cd build
          /opt/devkitpro/portlibs/switch/bin/aarch64-none-elf-cmake \
            -DCMAKE_BUILD_TYPE=Release \
            -DRE3_AUDIO=OAL \
            -DLIBRW_PLATFORM=GL3 \
            -DLIBRW_GL3_GFXLIB=GLFW \
            -DRE3_WITH_OPUS=False \
            -DRE3_VENDORED_LIBRW=True \
            -DRE3_INSTALL=True \
            -DRE3_RT=${{ matrix.rt }} \
            ..
          cmake --build . --parallel $(nproc)

      - name: Create binary package (cpack)
        working-directory: ./build
        run: |
          cpack -G TXZ

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: "switch-gl3-${{ matrix.name }}"
          path: build//*.tar.xz
          if-no-files-found: error
