Skip to content

Commit ee0b4a6

Browse files
Adapt riscv64 CI test to the current workflow.
1 parent cd42ad4 commit ee0b4a6

5 files changed

Lines changed: 59 additions & 4 deletions

File tree

.github/workflows/kvrocks.yaml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,20 @@ jobs:
223223
os: ubuntu-24.04-arm
224224
compiler: clang
225225
arm_linux: true
226+
- name: Ubuntu RISC-V GCC without luaJIT (QEMU)
227+
os: ubuntu-24.04
228+
riscv_toolchain: true
229+
riscv_toolchain_url: "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"
230+
cmake_crosscompiling: -DCMAKE_CROSSCOMPILING=TRUE
231+
cmake_system_name: -DCMAKE_SYSTEM_NAME=Linux
232+
cmake_system_processor: -DCMAKE_SYSTEM_PROCESSOR=riscv64
233+
without_luajit: -DENABLE_LUAJIT=OFF
226234

227235
runs-on: ${{ matrix.os }}
228236
env:
229237
SONARCLOUD_OUTPUT_DIR: sonarcloud-data
230238
FORCE_JAVASCRIPT_ACTIONS_TO_NODE20: true
239+
RISCV_PATH: "/opt/riscv"
231240
steps:
232241
- name: Setup macOS
233242
if: ${{ startsWith(matrix.os, 'macos') }}
@@ -253,6 +262,20 @@ jobs:
253262
if: ${{ matrix.arm_linux }}
254263
run: |
255264
sudo apt install -y git build-essential cmake libtool python3 python3-pip libssl-dev
265+
- name: Setup RISC-V Toolchain
266+
if: ${{ matrix.riscv_toolchain }}
267+
run: |
268+
sudo apt install -y wget build-essential cmake git python3 \
269+
libgflags-dev libsnappy-dev zlib1g-dev liblz4-dev libzstd-dev \
270+
qemu-user qemu-user-static
271+
sudo mkdir -p $RISCV_PATH
272+
wget "${{ matrix.riscv_toolchain_url }}" -O riscv-toolchain.tar.xz
273+
sudo tar -xvf riscv-toolchain.tar.xz -C $RISCV_PATH --strip-components=1
274+
sudo sed -i "s|libdir='/mnt/riscv/riscv64-unknown-linux-gnu/lib'|libdir='$RISCV_PATH/riscv64-unknown-linux-gnu/lib'|g" \
275+
$RISCV_PATH/riscv64-unknown-linux-gnu/lib/libatomic.la
276+
echo "PATH=$RISCV_PATH/bin:$PATH" >> $GITHUB_ENV
277+
echo "LD_LIBRARY_PATH=/opt/riscv/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV
278+
echo "QEMU_LD_PREFIX=$RISCV_PATH/sysroot" >> $GITHUB_ENV
256279
257280
- name: Cache redis
258281
id: cache-redis
@@ -298,7 +321,7 @@ jobs:
298321
if: ${{ matrix.sonarcloud }}
299322

300323
- name: Build Kvrocks
301-
if: ${{ !matrix.sonarcloud }}
324+
if: ${{ !matrix.sonarcloud && !matrix.riscv_toolchain }}
302325
run: |
303326
./x.py build -j$NPROC --unittest --compiler ${{ matrix.compiler }} ${{ matrix.without_jemalloc }} \
304327
${{ matrix.without_luajit }} ${{ matrix.with_ninja }} ${{ matrix.with_sanitizer }} ${{ matrix.with_openssl }} \
@@ -311,6 +334,14 @@ jobs:
311334
cp -r build _build
312335
build-wrapper-linux-x86-64 --out-dir ${{ env.SONARCLOUD_OUTPUT_DIR }} ./x.py build -j$NPROC --unittest --compiler ${{ matrix.compiler }} ${{ matrix.sonarcloud }}
313336
337+
- name: Build Kvrocks (RISC-V)
338+
if: ${{ matrix.riscv_toolchain }}
339+
run: |
340+
CC=riscv64-unknown-linux-gnu-gcc \
341+
CXX=riscv64-unknown-linux-gnu-g++ \
342+
./x.py build -j$NPROC --unittest ${{ matrix.cmake_crosscompiling }} ${{ matrix.cmake_system_name }} \
343+
${{ matrix.cmake_system_processor }} ${{ matrix.without_luajit }}
344+
314345
- name: Setup Coredump
315346
if: ${{ startsWith(matrix.os, 'ubuntu') }}
316347
run: |
@@ -325,6 +356,7 @@ jobs:
325356
./x.py test cpp
326357
327358
- name: Run Go Integration Cases
359+
if: ${{ !matrix.riscv_toolchain }}
328360
run: |
329361
ulimit -c unlimited
330362
export LSAN_OPTIONS="suppressions=$(realpath ./tests/lsan-suppressions)"

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)