Skip to content

Commit 1c8edbb

Browse files
Add riscv64 CI test with qemu.
1 parent cc82eea commit 1c8edbb

5 files changed

Lines changed: 98 additions & 3 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: riscv64-qemu-test
19+
20+
on: [push, pull_request]
21+
22+
jobs:
23+
test:
24+
runs-on: ubuntu-latest
25+
env:
26+
RISCV_CROSSCOMPILE: "ON"
27+
riscv_gnu_toolchain_download_path: "https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/2025.07.03/riscv64-glibc-ubuntu-24.04-gcc-nightly-2025.07.03-nightly.tar.xz"
28+
RISCV_PATH: "/opt/riscv"
29+
30+
steps:
31+
- uses: actions/checkout@v4
32+
with:
33+
submodules: recursive
34+
35+
- name: Install dependencies
36+
run: |
37+
sudo apt update
38+
sudo apt install -y --no-install-recommends \
39+
qemu-user qemu-user-static \
40+
wget \
41+
build-essential \
42+
cmake \
43+
libgflags-dev \
44+
libsnappy-dev \
45+
zlib1g-dev \
46+
libbz2-dev \
47+
liblz4-dev \
48+
libzstd-dev \
49+
git \
50+
python3 \
51+
clang \
52+
golang \
53+
libboost-dev \
54+
libstdc++-12-dev
55+
sudo mkdir -p $RISCV_PATH
56+
wget ${riscv_gnu_toolchain_download_path} -O riscv-toolchain.tar.xz
57+
sudo tar -xvf riscv-toolchain.tar.xz -C $RISCV_PATH --strip-components=1
58+
sudo sed -i "s|libdir='/mnt/riscv/riscv64-unknown-linux-gnu/lib'|libdir='$RISCV_PATH/riscv64-unknown-linux-gnu/lib'|g" $RISCV_PATH/riscv64-unknown-linux-gnu/lib/libatomic.la
59+
60+
- name: Build and test
61+
run: |
62+
export PATH=$RISCV_PATH/bin:$PATH
63+
export LD_LIBRARY_PATH="/opt/riscv/lib:$LD_LIBRARY_PATH"
64+
export QEMU_LD_PREFIX=$RISCV_PATH/sysroot
65+
CC=riscv64-unknown-linux-gnu-gcc \
66+
CXX=riscv64-unknown-linux-gnu-g++ \
67+
./x.py build \
68+
-DCMAKE_SYSTEM_NAME=Linux \
69+
-DCMAKE_SYSTEM_PROCESSOR=riscv64 \
70+
-DCMAKE_CROSSCOMPILING=TRUE \
71+
--unittest -j4
72+
qemu-riscv64 -L $QEMU_LD_PREFIX -cpu rv64,v=true,vext_spec=v1.0,zba=true,zbb=true ./build/unittest

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
# under the License.
1717

1818
cmake_minimum_required(VERSION 3.16)
19+
if(DEFINED ENV{RISCV_CROSSCOMPILE})
20+
set(CMAKE_SYSTEM_NAME Linux CACHE STRING "")
21+
set(CMAKE_SYSTEM_PROCESSOR riscv64 CACHE STRING "")
22+
set(CMAKE_CROSSCOMPILING TRUE CACHE BOOL "")
23+
endif()
24+
1925
project(kvrocks
2026
DESCRIPTION "NoSQL which is based on RocksDB and compatible with the Redis protocol"
2127
LANGUAGES C CXX)
@@ -29,6 +35,9 @@ option(ENABLE_UBSAN "enable undefined behavior sanitizer" OFF)
2935
option(ASAN_WITH_LSAN "enable leak sanitizer while address sanitizer is enabled" ON)
3036
option(ENABLE_STATIC_LIBSTDCXX "link kvrocks with static library of libstd++ instead of shared library" ON)
3137
option(ENABLE_LUAJIT "enable use of luaJIT instead of lua" ON)
38+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "riscv64")
39+
set(ENABLE_LUAJIT OFF)
40+
endif()
3241
option(ENABLE_OPENSSL "enable openssl to support tls connection" OFF)
3342
option(ENABLE_LTO "enable link-time optimization" ON)
3443
set(SYMBOLIZE_BACKEND "" CACHE STRING "symbolization backend library for cpptrace (libbacktrace, libdwarf, or empty)")

cmake/jemalloc.cmake

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,21 @@ FetchContent_GetProperties(jemalloc)
4040
if(NOT jemalloc_POPULATED)
4141
FetchContent_Populate(jemalloc)
4242

43+
if(CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_PROCESSOR MATCHES "riscv64")
44+
message(STATUS "Configuring jemalloc for RISC-V cross-compilation")
45+
set(JEMALLOC_CROSS_FLAGS
46+
"--host=riscv64-unknown-linux-gnu"
47+
"--build=${CMAKE_HOST_SYSTEM_PROCESSOR}-pc-linux-gnu"
48+
"--with-lg-vaddr=48"
49+
)
50+
else()
51+
set(JEMALLOC_CROSS_FLAGS "")
52+
endif()
53+
4354
execute_process(COMMAND autoconf
4455
WORKING_DIRECTORY ${jemalloc_SOURCE_DIR}
4556
)
46-
execute_process(COMMAND ${jemalloc_SOURCE_DIR}/configure CC=${CMAKE_C_COMPILER} -C --enable-autogen
57+
execute_process(COMMAND ${jemalloc_SOURCE_DIR}/configure CC=${CMAKE_C_COMPILER} -C ${JEMALLOC_CROSS_FLAGS} --enable-autogen
4758
--disable-shared --disable-libdl ${DISABLE_CACHE_OBLIVIOUS} ${ENABLE_JEMALLOC_PROFILING}
4859
--with-jemalloc-prefix=""
4960
WORKING_DIRECTORY ${jemalloc_BINARY_DIR}

cmake/rocksdb.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ FetchContent_MakeAvailableWithArgs(rocksdb
5454
PORTABLE=${PORTABLE}
5555
)
5656

57+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "riscv64")
58+
target_compile_options(rocksdb PRIVATE "-march=rv64gc")
59+
endif()
5760
add_library(rocksdb_with_headers INTERFACE)
5861
target_include_directories(rocksdb_with_headers INTERFACE ${rocksdb_SOURCE_DIR}/include)
5962
target_link_libraries(rocksdb_with_headers INTERFACE rocksdb)

cmake/tbb.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ include_guard()
2020
include(cmake/utils.cmake)
2121

2222
FetchContent_DeclareGitHubWithMirror(tbb
23-
uxlfoundation/oneTBB v2022.2.0
24-
MD5=b00d733b2adf0fba1d33855689631b4d
23+
uxlfoundation/oneTBB v2022.1.0
24+
MD5=4a8940795f7e414727a1c443b94fd686
2525
)
2626

2727
FetchContent_MakeAvailableWithArgs(tbb

0 commit comments

Comments
 (0)