Skip to content

Commit 6d28482

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

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