Skip to content

Commit 7088261

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

File tree

5 files changed

+164
-38
lines changed

5 files changed

+164
-38
lines changed

.github/workflows/build_and_test.yml

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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+
cmake --install build
79+
80+
- name: Upload build artifacts
81+
uses: actions/upload-artifact@v3
82+
with:
83+
name: build
84+
path: |
85+
build
86+
install
87+
if: always()
88+
89+
test:
90+
runs-on: ubuntu-latest
91+
needs: [build]
92+
strategy:
93+
fail-fast: false
94+
matrix:
95+
include:
96+
- qemu_cpu: "rv64,zba=true,zbb=true,zbs=true,v=true,vlen=128,elen=64,vext_spec=v1.0"
97+
- qemu_cpu: "rv64,zba=true,zbb=true,zbs=true,v=true,vlen=256,elen=64,vext_spec=v1.0"
98+
- qemu_cpu: "rv64,zba=true,zbb=true,zbs=true,v=true,vlen=512,elen=64,vext_spec=v1.0"
99+
100+
name: "test (qemu_cpu: \"${{ matrix.qemu_cpu }}\")"
101+
steps:
102+
- uses: actions/checkout@v4.1.1
103+
with:
104+
persist-credentials: false
105+
106+
- name: Setup QEMU
107+
uses: docker/setup-qemu-action@v3.0.0
108+
109+
- name: Check sysroot cache
110+
id: check-sysroot-cache
111+
uses: actions/cache@v3
112+
with:
113+
path: sysroot
114+
key: sysroot-${{ hashFiles('./.github/workflows/build_and_test.yml') }}
115+
116+
- name: Install dependencies
117+
run: |
118+
sudo apt-get update -y -qq
119+
sudo apt-get install -y -qq libgmp-dev libmpfr-dev
120+
121+
- name: Download build artifacts
122+
uses: actions/download-artifact@v3
123+
with:
124+
name: build
125+
126+
- name: Fix build permissions
127+
run: |
128+
find .
129+
chmod +x build/test/test_*
130+
131+
- name: Test
132+
env:
133+
CTEST_OUTPUT_ON_FAILURE: "TRUE"
134+
run: |
135+
if [[ -n "${{ matrix.qemu_cpu }}" ]]; then
136+
export QEMU_CPU="${{ matrix.qemu_cpu }}"
137+
fi
138+
export QEMU_LD_PREFIX=$(pwd)/sysroot
139+
cd build
140+
ctest -j$(nproc)
141+
142+
- name: Upload test-${{ strategy.job-index }} artifacts
143+
uses: actions/upload-artifact@v3
144+
with:
145+
name: test-${{ strategy.job-index }}
146+
path: |
147+
build/Testing
148+
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)