name: Arm-SVE cross-compilation build
on: [push, pull_request]
concurrency:
  group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
  cancel-in-progress: true
jobs:
  build:
    runs-on: ubuntu-20.04
    name: 'Arm SVE${{ matrix.vector_bits }}'
    strategy:
      matrix:
        vector_bits:
          - 128
          - 256
          - 512
    steps:
    - name: Setup compiler
      run: |
        sudo apt-get update || exit 1
        sudo apt-get --no-install-suggests --no-install-recommends install g++-10-aarch64-linux-gnu || exit 1
        sudo update-alternatives --install /usr/bin/aarch64-linux-gnu-gcc aarch64-linux-gnu-gcc /usr/bin/aarch64-linux-gnu-gcc-10 20
        sudo update-alternatives --install /usr/bin/aarch64-linux-gnu-g++ aarch64-linux-gnu-g++ /usr/bin/aarch64-linux-gnu-g++-10 20
    - name: Setup QEMU
      run: |
        sudo apt-get --no-install-suggests --no-install-recommends install qemu-user
    - name: Setup Ninja
      run: |
        sudo apt-get install ninja-build
    - name: Checkout xsimd
      uses: actions/checkout@v2
    - name: Setup
      run: |
        mkdir _build
        cd _build && cmake .. -GNinja -DBUILD_TESTS=ON -DDOWNLOAD_DOCTEST=ON -DCMAKE_BUILD_TYPE=Release -DTARGET_ARCH=generic -DCMAKE_C_FLAGS="-march=armv8-a+sve -msve-vector-bits=${{ matrix.vector_bits }}" -DCMAKE_CXX_FLAGS="-march=armv8-a+sve -msve-vector-bits=${{ matrix.vector_bits }}" -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/.github/toolchains/gcc-aarch64-linux-gnu.cmake
    - name: Build
      run: cmake --build _build
    - name: Testing xsimd
      run: |
        qemu-aarch64 --cpu max,sve${{ matrix.vector_bits }}=on -L /usr/aarch64-linux-gnu/ ./test/test_xsimd
      working-directory: ${{ github.workspace }}/_build
