---
name: linux-riscv64-gcc
on:
  push:
    paths:
      - .gitea/workflows/linux-riscv64-gcc.yml
      - "cmake/**"
      - toolchains/riscv64-linux-gnu.toolchain.cmake
      - third_party/**
      - tile/**
      - "!tile/fiber/detail/asm/*"
      - "tile/fiber/detail/asm/ucontext_riscv64.*"
      - CMakeLists.txt
      - cmake/**
  pull_request:
    paths:
      - .gitea/workflows/linux-riscv64-gcc.yml
      - "cmake/**"
      - toolchains/riscv64-linux-gnu.toolchain.cmake
      - third_party/**
      - tile/**
      - "!tile/fiber/detail/asm/*"
      - "tile/fiber/detail/asm/ucontext_riscv64.*"
      - CMakeLists.txt
      - cmake/**
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  linux-gcc-riscv64:
    runs-on: ubuntu-20.04
    strategy:
      matrix:
        build_type: [Debug, Release]
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: recursive
      - name: install-tools
        run: |
          sudo apt-get update -y
          sudo apt-get install -y g++-riscv64-linux-gnu qemu-user-binfmt ninja-build
      - name: configure
        run: |
          mkdir build && cd build
          cmake -GNinja -DCMAKE_TOOLCHAIN_FILE=../toolchains/riscv64-linux-gnu.toolchain.cmake -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DTILE_BUILD_TESTS=ON -DTILE_BUILD_BENCHMARKS=ON ..
      - name: build
        run: cmake --build build --target all -j $(nproc)
      - name: test
        run: |-
          cd build 
          sudo ln -sf /usr/riscv64-linux-gnu/lib/ld-linux-riscv64-lp64d.so.1 /lib/ld-linux-riscv64-lp64d.so.1
          export LD_LIBRARY_PATH=/usr/riscv64-linux-gnu/lib
          ctest --output-on-failure -j $(nproc)
