name: Linux emulated build
on: [push, pull_request]
concurrency:
  group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
  cancel-in-progress: true
defaults:
  run:
    shell: bash -l {0}
jobs:
  build:
    runs-on: ubuntu-latest
    name: '${{ matrix.sys.compiler }} ${{ matrix.sys.version }} - emulated'
    strategy:
      matrix:
        sys:
          - { compiler: 'gcc',   version: '14'}
          - { compiler: 'clang', version: '18'}
    steps:
    - name: Setup compiler
      if: ${{ matrix.sys.compiler == 'gcc' }}
      run: |
        GCC_VERSION=${{ matrix.sys.version }}
        sudo apt-get update
        sudo apt-get --no-install-suggests --no-install-recommends install g++-$GCC_VERSION
        CC=gcc-$GCC_VERSION
        echo "CC=$CC" >> $GITHUB_ENV
        CXX=g++-$GCC_VERSION
        echo "CXX=$CXX" >> $GITHUB_ENV
        CXXFLAGS="-Wno-noexcept-type -Wno-stringop-overflow -Wno-maybe-uninitialized"
        echo "CXXFLAGS=$CXXFLAGS" >> $GITHUB_ENV
    - name: Setup compiler
      if: ${{ matrix.sys.compiler == 'clang' }}
      run: |
        LLVM_VERSION=${{ matrix.sys.version }}
        sudo apt-get update || exit 1
        sudo apt-get --no-install-suggests --no-install-recommends install clang-$LLVM_VERSION || exit 1
        sudo apt-get --no-install-suggests --no-install-recommends install g++ g++-multilib || exit 1
        sudo ln -s /usr/include/asm-generic /usr/include/asm
        CC=clang-$LLVM_VERSION
        echo "CC=$CC" >> $GITHUB_ENV
        CXX=clang++-$LLVM_VERSION
        echo "CXX=$CXX" >> $GITHUB_ENV
    - name: Checkout xsimd
      uses: actions/checkout@v3
    - name: Install mamba
      uses: mamba-org/setup-micromamba@v1
      with:
        environment-file: environment.yml
    - name: Configure build
      env:
        CC: ${{ env.CC }}
        CXX: ${{ env.CXX }}
      run: |

        mkdir _build
        cd _build
        cmake  .. -DBUILD_TESTS=ON \
                  -DBUILD_BENCHMARK=ON \
                  -DBUILD_EXAMPLES=ON \
                  -DCMAKE_BUILD_TYPE=Release \
                  -DCMAKE_C_COMPILER=$CC \
                  -DCMAKE_CXX_COMPILER=$CXX \
                  -DXSIMD_ENABLE_WERROR=ON \
                  -DCMAKE_CXX_FLAGS="-DXSIMD_DEFAULT_ARCH=emulated\<128\> -DXSIMD_WITH_EMULATED=1 ${CXXFLAGS}" \
                  -G Ninja
    - name: Build
      run: ninja -C _build
    - name: Test
      run: |
        cd _build/test
        ./test_xsimd
