Skip to content

Commit 222f7f2

Browse files
committed
Add CI on GitHub Actions
1 parent 0751065 commit 222f7f2

File tree

5 files changed

+162
-38
lines changed

5 files changed

+162
-38
lines changed

.github/workflows/build_and_test.yml

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
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()

.gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5-
build*
5+
build/
6+
install/
7+
sysroot/
68
compile_commands.json
79
LOCAL
8-
.*

CMakeToolchain/riscv.clang.cross.cmake

+13-32
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,20 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5-
if (RISCV_TOOLCHAIN_INCLUDED)
6-
return()
7-
endif()
8-
set(RISCV_TOOLCHAIN_INCLUDED)
5+
SET (CMAKE_CROSSCOMPILING TRUE)
6+
SET (CMAKE_SYSTEM_NAME "Linux")
7+
SET (CMAKE_SYSTEM_PROCESSOR "riscv64")
98

10-
set(CMAKE_SYSTEM_NAME Linux)
11-
set(CMAKE_SYSTEM_PROCESSOR riscv)
9+
SET(CMAKE_FIND_ROOT_PATH /usr/riscv64-linux-gnu /usr/include/riscv64-linux-gnu /usr/lib/riscv64-linux-gnu /lib/riscv64-linux-gnu)
1210

13-
set(CMAKE_C_COMPILER clang)
14-
set(CMAKE_C_COMPILER_TARGET riscv64-unknown-linux-gnu)
15-
set(CMAKE_CXX_COMPILER clang++)
16-
set(CMAKE_CXX_COMPILER_TARGET riscv64-unknown-linux-gnu)
11+
find_program(CMAKE_C_COMPILER NAMES clang-18 clang)
12+
set(CMAKE_C_COMPILER_TARGET riscv64-linux-gnu)
13+
set(CMAKE_C_FLAGS "-march=rv64gcv_zba_zbb_zbs")
1714

18-
set(RISCV_TOOL_BASE /opt/riscv)
19-
set(SYSROOT_PATH ${RISCV_TOOL_BASE}/sysroot)
15+
find_program(CMAKE_CXX_COMPILER NAMES clang++-18 clang++)
16+
set(CMAKE_CXX_COMPILER_TARGET riscv64-linux-gnu)
17+
set(CMAKE_CXX_FLAGS "-march=rv64gcv_zba_zbb_zbs")
2018

21-
set(CMAKE_FIND_ROOT_PATH ${SYSROOT_PATH})
22-
set(CMAKE_SYSROOT ${SYSROOT_PATH})
23-
24-
# Find includes and libraries in the target environment
25-
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
26-
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
27-
28-
# General options to enable cross-compilation
29-
set(MARCH_OR_CPU -march=rv64gcv)
30-
set(GCC_TOOLCHAIN --gcc-toolchain=${RISCV_TOOL_BASE})
31-
set(ISYSTEM -isystem${RISCV_TOOL_BASE}/${CMAKE_C_COMPILER_TARGET}/include/c++/12.1.0/riscv64-unknown-linux-gnu -isystem${RISCV_TOOL_BASE}/${CMAKE_C_COMPILER_TARGET}/include/c++/12.1.0)
32-
33-
add_compile_options(
34-
${MARCH_OR_CPU} ${GCC_TOOLCHAIN} ${ISYSTEM}
35-
)
36-
37-
add_link_options(
38-
${MARCH_OR_CPU}
39-
${GCC_TOOLCHAIN}
40-
)
19+
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
20+
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
21+
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

include/rvvlm_erfD.inc.h

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#define F_VER1 RVVLM_ERFDI_STD
99
#endif
1010

11-
#include <fenv.h>
12-
1311
// T is 2.0
1412
#define T 0x1.0p+1
1513

include/rvvlm_erfcD.inc.h

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ static_assert(false,
1919
"Must compile for ERFC or CDFNORM when including " __FILE__);
2020
#endif
2121

22-
#include <fenv.h>
23-
2422
#if defined(COMPILE_FOR_ERFC)
2523
// polynomial coefficients Q62
2624
#define P_0 0x4f33682d757709e8

0 commit comments

Comments
 (0)