Skip to content

Commit fb56f80

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

File tree

5 files changed

+165
-38
lines changed

5 files changed

+165
-38
lines changed

.github/workflows/build_and_test.yml

+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
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+
sudo ln -srf $(which clang-${LLVM_VERSION}) /usr/bin/clang
46+
rm llvm.sh
47+
48+
- name: Setup QEMU
49+
uses: docker/setup-qemu-action@v3.0.0
50+
51+
- name: Check sysroot cache
52+
id: check-sysroot-cache
53+
uses: actions/cache@v3
54+
with:
55+
path: sysroot
56+
key: sysroot-${{ hashFiles('./.github/workflows/build_and_test.yml') }}
57+
58+
- name: Create sysroot
59+
run: |
60+
sudo debootstrap --arch=riscv64 --verbose --include=fakeroot,symlinks --resolve-deps --variant=minbase --components=main,universe focal sysroot
61+
# Remove unused files to minimize cache
62+
sudo chroot sysroot symlinks -cr .
63+
sudo chown ${USER} -R sysroot
64+
rm -rf sysroot/{dev,proc,run,sys,var}
65+
rm -rf sysroot/usr/{sbin,bin,share}
66+
rm -rf sysroot/usr/lib/{apt,gcc,udev,systemd}
67+
rm -rf sysroot/usr/libexec/gcc
68+
if: steps.check-sysroot-cache.outputs.cache-hit != 'true'
69+
70+
- name: Build
71+
shell: bash -ex -o pipefail {0}
72+
run: |
73+
cmake -S . -B build -GNinja \
74+
-DCMAKE_INSTALL_PREFIX="$(pwd)/install" \
75+
-DCMAKE_TOOLCHAIN_FILE=$(pwd)/CMakeToolchain/riscv.clang.cross.cmake \
76+
-DCMAKE_SYSROOT=$(pwd)/sysroot
77+
cmake --build build
78+
79+
- name: Upload build artifacts
80+
uses: actions/upload-artifact@v3
81+
with:
82+
name: build
83+
path: |
84+
build
85+
if: always()
86+
87+
test:
88+
runs-on: ubuntu-latest
89+
needs: [build]
90+
strategy:
91+
fail-fast: false
92+
matrix:
93+
include:
94+
- qemu_cpu: "rv64,zba=true,zbb=true,zbs=true,v=true,vlen=128,elen=64,vext_spec=v1.0"
95+
- qemu_cpu: "rv64,zba=true,zbb=true,zbs=true,v=true,vlen=256,elen=64,vext_spec=v1.0"
96+
- qemu_cpu: "rv64,zba=true,zbb=true,zbs=true,v=true,vlen=512,elen=64,vext_spec=v1.0"
97+
98+
name: "test (qemu_cpu: \"${{ matrix.qemu_cpu }}\")"
99+
steps:
100+
- uses: actions/checkout@v4.1.1
101+
with:
102+
persist-credentials: false
103+
104+
- name: Setup QEMU
105+
uses: docker/setup-qemu-action@v3.0.0
106+
107+
- name: Check sysroot cache
108+
id: check-sysroot-cache
109+
uses: actions/cache@v3
110+
with:
111+
path: sysroot
112+
key: sysroot-${{ hashFiles('./.github/workflows/build_and_test.yml') }}
113+
114+
- name: Install dependencies
115+
run: |
116+
sudo apt-get update -y -qq
117+
sudo apt-get install -y -qq libgmp-dev libmpfr-dev
118+
119+
- name: Print host CPU info
120+
run: |
121+
cat /proc/cpuinfo
122+
123+
- name: Download build artifacts
124+
uses: actions/download-artifact@v3
125+
with:
126+
name: build
127+
128+
- name: Fix build-native and build permissions
129+
run: |
130+
chmod +x build/test/*
131+
132+
- name: Test
133+
env:
134+
CTEST_OUTPUT_ON_FAILURE: "TRUE"
135+
run: |
136+
if [[ -n "${{ matrix.qemu_cpu }}" ]]; then
137+
export QEMU_CPU="${{ matrix.qemu_cpu }}"
138+
fi
139+
export QEMU_LD_PREFIX=$(pwd)/sysroot
140+
cd build
141+
ctest -j$(nproc)
142+
143+
- name: Upload test-${{ strategy.job-index }} artifacts
144+
uses: actions/upload-artifact@v3
145+
with:
146+
name: test-${{ strategy.job-index }}
147+
path: |
148+
build/Testing
149+
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)