name: Emscripten

on: [push, pull_request]

jobs:
  build-linux:
    defaults:
      run:
        shell: bash
    name: Emscripten-C++${{matrix.std}}-${{matrix.build_type}}-${{matrix.lib}}
    runs-on: ubuntu-22.04
    permissions:
      actions: read
      contents: read
      security-events: write
    container: emscripten/emsdk
    strategy:
      fail-fast: true
      matrix:
        build_type: [Release, Debug]
        lib: [static]
        std: [14, 17, 20, 23]

    steps:
      - uses: actions/checkout@v4

      - name: Initialize CodeQL
        uses: github/codeql-action/init@v3
        with:
          languages: cpp

      - name: Setup Dependencies
        run: |
          sudo apt-get update
          DEBIAN_FRONTEND=noninteractive sudo apt-get install -y \
            cmake \
            ninja-build

      - name: Configure
        env:
          CXXFLAGS: -Wall -Wextra -Wsign-conversion -Wtautological-compare -Wformat-nonliteral -Wundef -Werror -Wno-error=wasm-exception-spec ${{env.CXXFLAGS}}
        run: |
          emcmake cmake -S . -B build_${{matrix.build_type}} \
            -DBUILD_SHARED_LIBS=${{matrix.lib == 'shared'}} \
            -DCMAKE_CXX_STANDARD=${{matrix.std}} \
            -DCMAKE_CXX_STANDARD_REQUIRED=ON \
            -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install \
            -G Ninja \
            -Werror

      - name: Build
        run: |
          cmake --build build_${{matrix.build_type}} \
                --config ${{matrix.build_type}}

      - name: Perform CodeQL Analysis
        uses: github/codeql-action/analyze@v3
