Skip to content

Commit

Permalink
Add CI on GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
luhenry committed Feb 15, 2024
1 parent 0751065 commit 44f7533
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 38 deletions.
145 changes: 145 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@

name: "Build & Test"

on:
# allow direct trigger
workflow_dispatch:
push:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

env:
GCC_VERSION: "11"
LLVM_VERSION: "18"

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4.1.1
with:
persist-credentials: false

- name: Install dependencies
run: |
sudo apt-get update -y -qq
sudo apt-get install -y -qq build-essential curl ninja-build debootstrap
# Needed for llvm builds as well for target libraries
- name: Install gcc
run: |
sudo apt-get install -y -qq gcc-${GCC_VERSION}
- name: Install llvm
run: |
curl -o llvm.sh https://apt.llvm.org/llvm.sh
chmod u+x llvm.sh
sudo ./llvm.sh ${LLVM_VERSION}
sudo ln -srf $(which clang-${LLVM_VERSION}) /usr/bin/clang
rm llvm.sh
- name: Setup QEMU
uses: docker/setup-qemu-action@v3.0.0

- name: Check sysroot cache
id: check-sysroot-cache
uses: actions/cache@v3
with:
path: sysroot
key: sysroot-${{ hashFiles('./.github/workflows/build_and_test.yml') }}

- name: Create sysroot
run: |
sudo debootstrap --arch=riscv64 --verbose --include=fakeroot,symlinks --resolve-deps --variant=minbase --components=main,universe focal sysroot
# Remove unused files to minimize cache
sudo chroot sysroot symlinks -cr .
sudo chown ${USER} -R sysroot
rm -rf sysroot/{dev,proc,run,sys,var}
rm -rf sysroot/usr/{sbin,bin,share}
rm -rf sysroot/usr/lib/{apt,gcc,udev,systemd}
rm -rf sysroot/usr/libexec/gcc
if: steps.check-sysroot-cache.outputs.cache-hit != 'true'

- name: Build
shell: bash -ex -o pipefail {0}
run: |
cmake -S . -B build -GNinja \
-DCMAKE_INSTALL_PREFIX="$(pwd)/install" \
-DCMAKE_TOOLCHAIN_FILE=$(pwd)/CMakeToolchain/riscv.clang.cross.cmake \
-DCMAKE_SYSROOT=$(pwd)/sysroot
cmake --build build
cmake --install build
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: build
path: |
build
install
sysroot
if: always()

test:
runs-on: ubuntu-latest
needs: [build]
strategy:
fail-fast: false
matrix:
include:
- qemu_cpu: "rv64,zba=true,zbb=true,zbs=true,v=true,vlen=128,elen=64,vext_spec=v1.0"
- qemu_cpu: "rv64,zba=true,zbb=true,zbs=true,v=true,vlen=256,elen=64,vext_spec=v1.0"
- qemu_cpu: "rv64,zba=true,zbb=true,zbs=true,v=true,vlen=512,elen=64,vext_spec=v1.0"

name: "test (qemu_cpu: \"${{ matrix.qemu_cpu }}\")"
steps:
- uses: actions/checkout@v4.1.1
with:
persist-credentials: false

- name: Setup QEMU
uses: docker/setup-qemu-action@v3.0.0

- name: Install dependencies
run: |
sudo apt-get update -y -qq
sudo apt-get install -y -qq libgmp-dev libmpfr-dev
- name: Print host CPU info
run: |
cat /proc/cpuinfo
- name: Download build artifacts
uses: actions/download-artifact@v3
with:
name: build

- name: Fix build-native and build permissions
run: |
chmod +x build/test/*
- name: Test
env:
CTEST_OUTPUT_ON_FAILURE: "TRUE"
run: |
if [[ -n "${{ matrix.qemu_cpu }}" ]]; then
export QEMU_CPU="${{ matrix.qemu_cpu }}"
fi
export QEMU_LD_PREFIX=$(pwd)/sysroot
cd build
ctest -j$(nproc)
- name: Upload test-${{ strategy.job-index }} artifacts
uses: actions/upload-artifact@v3
with:
name: test-${{ strategy.job-index }}
path: |
build/Testing
if: always()
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#
# SPDX-License-Identifier: Apache-2.0

build*
build/
install/
sysroot/
compile_commands.json
LOCAL
.*
45 changes: 13 additions & 32 deletions CMakeToolchain/riscv.clang.cross.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,20 @@
#
# SPDX-License-Identifier: Apache-2.0

if (RISCV_TOOLCHAIN_INCLUDED)
return()
endif()
set(RISCV_TOOLCHAIN_INCLUDED)
SET (CMAKE_CROSSCOMPILING TRUE)
SET (CMAKE_SYSTEM_NAME "Linux")
SET (CMAKE_SYSTEM_PROCESSOR "riscv64")

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR riscv)
SET(CMAKE_FIND_ROOT_PATH /usr/riscv64-linux-gnu /usr/include/riscv64-linux-gnu /usr/lib/riscv64-linux-gnu /lib/riscv64-linux-gnu)

set(CMAKE_C_COMPILER clang)
set(CMAKE_C_COMPILER_TARGET riscv64-unknown-linux-gnu)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_COMPILER_TARGET riscv64-unknown-linux-gnu)
find_program(CMAKE_C_COMPILER NAMES clang-18 clang)
set(CMAKE_C_COMPILER_TARGET riscv64-linux-gnu)
find_program(CMAKE_CXX_COMPILER NAMES clang++-18 clang++)
set(CMAKE_CXX_COMPILER_TARGET riscv64-linux-gnu)

set(RISCV_TOOL_BASE /opt/riscv)
set(SYSROOT_PATH ${RISCV_TOOL_BASE}/sysroot)
set(CMAKE_C_FLAGS "-march=rv64gcv_zba_zbb_zbs")
set(CMAKE_CXX_FLAGS "-march=rv64gcv_zba_zbb_zbs")

set(CMAKE_FIND_ROOT_PATH ${SYSROOT_PATH})
set(CMAKE_SYSROOT ${SYSROOT_PATH})

# Find includes and libraries in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

# General options to enable cross-compilation
set(MARCH_OR_CPU -march=rv64gcv)
set(GCC_TOOLCHAIN --gcc-toolchain=${RISCV_TOOL_BASE})
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)

add_compile_options(
${MARCH_OR_CPU} ${GCC_TOOLCHAIN} ${ISYSTEM}
)

add_link_options(
${MARCH_OR_CPU}
${GCC_TOOLCHAIN}
)
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
2 changes: 0 additions & 2 deletions include/rvvlm_erfD.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#define F_VER1 RVVLM_ERFDI_STD
#endif

#include <fenv.h>

// T is 2.0
#define T 0x1.0p+1

Expand Down
2 changes: 0 additions & 2 deletions include/rvvlm_erfcD.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ static_assert(false,
"Must compile for ERFC or CDFNORM when including " __FILE__);
#endif

#include <fenv.h>

#if defined(COMPILE_FOR_ERFC)
// polynomial coefficients Q62
#define P_0 0x4f33682d757709e8
Expand Down

0 comments on commit 44f7533

Please sign in to comment.