Skip to content

Commit 680b1b9

Browse files
Add riscv64 CI test with qemu.
1 parent 16e7783 commit 680b1b9

5 files changed

Lines changed: 74 additions & 5 deletions

File tree

.github/workflows/kvrocks.yaml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,21 @@ 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+
toolchain_file: cmake/riscv64.cmake
230+
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"
231+
cmake_crosscompiling: -DCMAKE_CROSSCOMPILING=TRUE
232+
cmake_system_name: -DCMAKE_SYSTEM_NAME=Linux
233+
cmake_system_processor: -DCMAKE_SYSTEM_PROCESSOR=riscv64
234+
without_luajit: -DENABLE_LUAJIT=OFF
226235

227236
runs-on: ${{ matrix.os }}
228237
env:
229238
SONARCLOUD_OUTPUT_DIR: sonarcloud-data
230239
FORCE_JAVASCRIPT_ACTIONS_TO_NODE20: true
240+
RISCV_PATH: "/opt/riscv"
231241
steps:
232242
- name: Setup macOS
233243
if: ${{ startsWith(matrix.os, 'macos') }}
@@ -253,6 +263,20 @@ jobs:
253263
if: ${{ matrix.arm_linux }}
254264
run: |
255265
sudo apt install -y git build-essential cmake libtool python3 python3-pip libssl-dev
266+
- name: Setup RISC-V Toolchain
267+
if: ${{ matrix.riscv_toolchain }}
268+
run: |
269+
sudo apt install -y wget build-essential cmake git python3 \
270+
libgflags-dev libsnappy-dev zlib1g-dev liblz4-dev libzstd-dev \
271+
qemu-user qemu-user-static
272+
sudo mkdir -p $RISCV_PATH
273+
wget "${{ matrix.riscv_toolchain_url }}" -O riscv-toolchain.tar.xz
274+
sudo tar -xvf riscv-toolchain.tar.xz -C $RISCV_PATH --strip-components=1
275+
sudo sed -i "s|libdir='/mnt/riscv/riscv64-unknown-linux-gnu/lib'|libdir='$RISCV_PATH/riscv64-unknown-linux-gnu/lib'|g" \
276+
$RISCV_PATH/riscv64-unknown-linux-gnu/lib/libatomic.la
277+
echo "PATH=$RISCV_PATH/bin:$PATH" >> $GITHUB_ENV
278+
echo "LD_LIBRARY_PATH=/opt/riscv/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV
279+
echo "QEMU_LD_PREFIX=$RISCV_PATH/sysroot" >> $GITHUB_ENV
256280
257281
- name: Cache redis
258282
id: cache-redis
@@ -298,7 +322,7 @@ jobs:
298322
if: ${{ matrix.sonarcloud }}
299323

300324
- name: Build Kvrocks
301-
if: ${{ !matrix.sonarcloud }}
325+
if: ${{ !matrix.sonarcloud && !matrix.riscv_toolchain }}
302326
run: |
303327
./x.py build -j$NPROC --unittest --compiler ${{ matrix.compiler }} ${{ matrix.without_jemalloc }} \
304328
${{ matrix.without_luajit }} ${{ matrix.with_ninja }} ${{ matrix.with_sanitizer }} ${{ matrix.with_openssl }} \
@@ -311,6 +335,11 @@ jobs:
311335
cp -r build _build
312336
build-wrapper-linux-x86-64 --out-dir ${{ env.SONARCLOUD_OUTPUT_DIR }} ./x.py build -j$NPROC --unittest --compiler ${{ matrix.compiler }} ${{ matrix.sonarcloud }}
313337
338+
- name: Build Kvrocks (RISC-V)
339+
if: ${{ matrix.riscv_toolchain }}
340+
run: |
341+
./x.py build -j$NPROC --unittest --toolchain ${{ matrix.toolchain_file }}
342+
314343
- name: Setup Coredump
315344
if: ${{ startsWith(matrix.os, 'ubuntu') }}
316345
run: |

cmake/jemalloc.cmake

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

43+
if(NOT DEFINED JEMALLOC_CROSS_FLAGS)
44+
set(JEMALLOC_CROSS_FLAGS "")
45+
endif()
46+
4347
execute_process(COMMAND autoconf
4448
WORKING_DIRECTORY ${jemalloc_SOURCE_DIR}
4549
)
46-
execute_process(COMMAND ${jemalloc_SOURCE_DIR}/configure CC=${CMAKE_C_COMPILER} -C --enable-autogen
50+
execute_process(COMMAND ${jemalloc_SOURCE_DIR}/configure CC=${CMAKE_C_COMPILER} -C ${JEMALLOC_CROSS_FLAGS} --enable-autogen
4751
--disable-shared --disable-libdl ${DISABLE_CACHE_OBLIVIOUS} ${ENABLE_JEMALLOC_PROFILING}
4852
--with-jemalloc-prefix=""
4953
WORKING_DIRECTORY ${jemalloc_BINARY_DIR}

cmake/riscv64.cmake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
set(CMAKE_SYSTEM_NAME Linux)
19+
set(CMAKE_SYSTEM_PROCESSOR riscv64)
20+
set(CMAKE_CROSSCOMPILING TRUE)
21+
22+
set(CMAKE_C_COMPILER "riscv64-unknown-linux-gnu-gcc")
23+
set(CMAKE_CXX_COMPILER "riscv64-unknown-linux-gnu-g++")
24+
25+
add_compile_options("-march=rv64gc")
26+
27+
set(JEMALLOC_CROSS_FLAGS
28+
"--host=riscv64-unknown-linux-gnu"
29+
"--build=${CMAKE_HOST_SYSTEM_PROCESSOR}-pc-linux-gnu"
30+
"--with-lg-vaddr=48"
31+
CACHE STRING "jemalloc flags for RISC-V cross-compilation"
32+
)
33+
set(ENABLE_LUAJIT OFF CACHE BOOL "Disable LuaJIT on RISC-V" FORCE)

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

x.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def prepare() -> None:
114114
print(f"{hook.name} installed at {dst}.")
115115

116116
def build(dir: str, jobs: Optional[int], ninja: bool, unittest: bool, compiler: str, cmake_path: str, D: List[str],
117-
skip_build: bool) -> None:
117+
skip_build: bool, toolchain: Optional[str] = None) -> None:
118118
basedir = Path(__file__).parent.absolute()
119119

120120
find_command("autoconf", msg="autoconf is required to build jemalloc")
@@ -129,6 +129,8 @@ def build(dir: str, jobs: Optional[int], ninja: bool, unittest: bool, compiler:
129129
os.makedirs(dir, exist_ok=True)
130130

131131
cmake_options = ["-DCMAKE_BUILD_TYPE=RelWithDebInfo"]
132+
if toolchain:
133+
cmake_options.append(f"-DCMAKE_TOOLCHAIN_FILE={toolchain}")
132134
if ninja:
133135
cmake_options.append("-G Ninja")
134136
if compiler == 'gcc':
@@ -389,6 +391,7 @@ def test_go(dir: str, cli_path: str, rest: List[str]) -> None:
389391
parser_build.add_argument('--unittest', default=False, action='store_true', help='build unittest target')
390392
parser_build.add_argument('--compiler', default='auto', choices=('auto', 'gcc', 'clang'),
391393
help="compiler used to build kvrocks")
394+
parser_build.add_argument('--toolchain', metavar='FILE', help="path to CMake toolchain file for cross-compiling")
392395
parser_build.add_argument('--cmake-path', default='cmake', help="path of cmake binary used to build kvrocks")
393396
parser_build.add_argument('-D', action='append', metavar='key=value', help='extra CMake definitions')
394397
parser_build.add_argument('--skip-build', default=False, action='store_true',

0 commit comments

Comments
 (0)