|
| 1 | + |
| 2 | +name: "Build & Test" |
| 3 | + |
| 4 | +on: |
| 5 | + # allow direct trigger |
| 6 | + workflow_dispatch: |
| 7 | + push: |
| 8 | + pull_request: |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 12 | + cancel-in-progress: true |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + |
| 17 | +env: |
| 18 | + GCC_VERSION: "12" |
| 19 | + LLVM_VERSION: "18" |
| 20 | + |
| 21 | +jobs: |
| 22 | + build: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v4.1.1 |
| 27 | + with: |
| 28 | + persist-credentials: false |
| 29 | + |
| 30 | + - name: Install dependencies |
| 31 | + run: | |
| 32 | + sudo apt-get update -y -qq |
| 33 | + sudo apt-get install -y -qq build-essential curl ninja-build debootstrap |
| 34 | +
|
| 35 | + # Needed for some target toolchains like ld |
| 36 | + - name: Install gcc |
| 37 | + run: | |
| 38 | + sudo apt-get install -y -qq gcc-${GCC_VERSION} gcc-${GCC_VERSION}-riscv64-linux-gnu g++-${GCC_VERSION} g++-${GCC_VERSION}-riscv64-linux-gnu |
| 39 | +
|
| 40 | + - name: Install llvm |
| 41 | + run: | |
| 42 | + curl -o llvm.sh https://apt.llvm.org/llvm.sh |
| 43 | + chmod u+x llvm.sh |
| 44 | + sudo ./llvm.sh ${LLVM_VERSION} |
| 45 | + rm llvm.sh |
| 46 | +
|
| 47 | + - name: Setup QEMU |
| 48 | + uses: docker/setup-qemu-action@v3.0.0 |
| 49 | + |
| 50 | + - name: Check sysroot cache |
| 51 | + id: check-sysroot-cache |
| 52 | + uses: actions/cache@v4 |
| 53 | + with: |
| 54 | + path: sysroot |
| 55 | + key: sysroot-${{ hashFiles('./.github/workflows/build_and_test.yml') }} |
| 56 | + |
| 57 | + - name: Create sysroot |
| 58 | + run: | |
| 59 | + sudo debootstrap --arch=riscv64 --verbose --include=fakeroot,symlinks --resolve-deps --variant=minbase --components=main,universe focal sysroot |
| 60 | + # Remove unused files to minimize cache |
| 61 | + sudo chroot sysroot symlinks -cr . |
| 62 | + sudo chown ${USER} -R sysroot |
| 63 | + rm -rf sysroot/{dev,proc,run,sys,var} |
| 64 | + rm -rf sysroot/usr/{sbin,bin,share} |
| 65 | + rm -rf sysroot/usr/lib/{apt,gcc,udev,systemd} |
| 66 | + rm -rf sysroot/usr/libexec/gcc |
| 67 | + if: steps.check-sysroot-cache.outputs.cache-hit != 'true' |
| 68 | + |
| 69 | + - name: Build |
| 70 | + shell: bash -ex -o pipefail {0} |
| 71 | + run: | |
| 72 | + cmake -S . -B build -GNinja \ |
| 73 | + -DCMAKE_INSTALL_PREFIX="$(pwd)/install" \ |
| 74 | + -DCMAKE_TOOLCHAIN_FILE=$(pwd)/CMakeToolchain/riscv.clang.cross.cmake \ |
| 75 | + -DCMAKE_SYSROOT=$(pwd)/sysroot |
| 76 | + cmake --build build |
| 77 | + cmake --install build |
| 78 | +
|
| 79 | + - name: Upload build artifacts |
| 80 | + uses: actions/upload-artifact@v4 |
| 81 | + with: |
| 82 | + name: build |
| 83 | + path: | |
| 84 | + build |
| 85 | + install |
| 86 | + if: always() |
| 87 | + |
| 88 | + test: |
| 89 | + runs-on: ubuntu-latest |
| 90 | + needs: [build] |
| 91 | + strategy: |
| 92 | + fail-fast: false |
| 93 | + matrix: |
| 94 | + include: |
| 95 | + - qemu_cpu: "rv64,zba=true,zbb=true,zbs=true,v=true,vlen=128,elen=64,vext_spec=v1.0" |
| 96 | + - qemu_cpu: "rv64,zba=true,zbb=true,zbs=true,v=true,vlen=256,elen=64,vext_spec=v1.0" |
| 97 | + - qemu_cpu: "rv64,zba=true,zbb=true,zbs=true,v=true,vlen=512,elen=64,vext_spec=v1.0" |
| 98 | + |
| 99 | + name: "test (qemu_cpu: \"${{ matrix.qemu_cpu }}\")" |
| 100 | + steps: |
| 101 | + - uses: actions/checkout@v4.1.1 |
| 102 | + with: |
| 103 | + persist-credentials: false |
| 104 | + |
| 105 | + - name: Setup QEMU |
| 106 | + uses: docker/setup-qemu-action@v3.0.0 |
| 107 | + |
| 108 | + - name: Check sysroot cache |
| 109 | + id: check-sysroot-cache |
| 110 | + uses: actions/cache@v4 |
| 111 | + with: |
| 112 | + path: sysroot |
| 113 | + key: sysroot-${{ hashFiles('./.github/workflows/build_and_test.yml') }} |
| 114 | + |
| 115 | + - name: Install dependencies |
| 116 | + run: | |
| 117 | + sudo apt-get update -y -qq |
| 118 | + sudo apt-get install -y -qq libgmp-dev libmpfr-dev |
| 119 | +
|
| 120 | + - name: Download build artifacts |
| 121 | + uses: actions/download-artifact@v4 |
| 122 | + with: |
| 123 | + name: build |
| 124 | + |
| 125 | + - name: Fix build permissions |
| 126 | + run: | |
| 127 | + chmod +x build/test/test_* |
| 128 | +
|
| 129 | + - name: Test |
| 130 | + env: |
| 131 | + CTEST_OUTPUT_ON_FAILURE: "TRUE" |
| 132 | + run: | |
| 133 | + if [[ -n "${{ matrix.qemu_cpu }}" ]]; then |
| 134 | + export QEMU_CPU="${{ matrix.qemu_cpu }}" |
| 135 | + fi |
| 136 | + export QEMU_LD_PREFIX=$(pwd)/sysroot |
| 137 | + cd build |
| 138 | + ctest -j$(nproc) |
| 139 | +
|
| 140 | + - name: Upload test-${{ strategy.job-index }} artifacts |
| 141 | + uses: actions/upload-artifact@v4 |
| 142 | + with: |
| 143 | + name: test-${{ strategy.job-index }} |
| 144 | + path: | |
| 145 | + build/Testing |
| 146 | + if: always() |
0 commit comments