name: Cross-Compilation CI

on:
  push:
    branches:
      - master

  workflow_dispatch:
  pull_request:
    branches: [master]

jobs:
  tests:
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        target:
          # Test big and little-endian architectures, 32-bit and 64-bit
          - arm64-unknown-linux-gnu
          - arm64eb-unknown-linux-gnu
          - mipsel-unknown-linux-gnu
          - mips-unknown-linux-gnu
          - riscv64-unknown-linux-gnu

    steps:
      - uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: 3.7

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          python -m pip install xcross==0.1.7

      - name: Configure
        run: xcross --target ${{ matrix.target }}
          cmake -Ssubproject/test -Bbuild/test
          -DCMAKE_BUILD_TYPE:STRING=Debug

      - name: Build
        run: xcross --target ${{ matrix.target }}
          cmake --build build/test --config Debug

      - name: Test
        run: |
          cd build/test
          xcross --target ${{ matrix.target }} run ./test_all_shorter_interval_cases
          xcross --target ${{ matrix.target }} run ./uniform_random_test
          xcross --target ${{ matrix.target }} run ./verify_compressed_cache
          xcross --target ${{ matrix.target }} run ./verify_fast_multiplication
          xcross --target ${{ matrix.target }} run ./verify_log_computation
          xcross --target ${{ matrix.target }} run ./verify_magic_division
