Skip to content

Commit 42b7263

Browse files
authored
ci: add riscv64-linux build via cross-compilation on ubuntu-24.04 (#621)
Rework of the riscv64-linux CI build to use CMake cross-compilation on a standard `ubuntu-24.04` runner, rather than a native RISE runner. ## What changed **`ci/docker/Dockerfile.riscv64-linux`** (new): - Ubuntu 24.04 base — has `crossbuild-essential-riscv64` in its package repos - Sets `CC=riscv64-linux-gnu-gcc` / `CXX=riscv64-linux-gnu-g++` so CMake detects cross-compilation and causes LLVM to build a native `llvm-tblgen` first, then cross-compile the rest of the toolchain - Sets `CARGO_TARGET_RISCV64_UNKNOWN_LINUX_GNU_LINKER` for Rust cross-builds - `XDG_CACHE_HOME=/tmp/cache` avoids write permission issues in the container **`ci/docker-build.sh`**: - Select `ci/docker/Dockerfile.<artifact>` if it exists, fall back to the default `ci/docker/Dockerfile` - Make the wasmtime volume mount conditional on `WASI_SDK_CI_SKIP_SYSROOT != 1` **`.github/workflows/main.yml`**: - New `riscv64-linux` matrix entry: `os: ubuntu-24.04`, `rust_target: riscv64-unknown-linux-gnu` - `cross_cmake_args: -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=riscv64 -DWASI_SDK_LLDB=OFF` - `WASI_SDK_CI_SKIP_SYSROOT: 1` - Handle `cross_cmake_args` in the cmake flags step ## Why WASI_SDK_CI_SKIP_SYSROOT The cross-compiled clang runs on riscv64, not on the x86_64 build host, so the wasm sysroot step is skipped. ## Why WASI_SDK_LLDB=OFF Avoids cross-compiling libedit and libxml2 in this first iteration; can be re-enabled as a follow-up. Closes #607 --------- Signed-off-by: Bruno Verachten <gounthar@gmail.com>
1 parent 62a1a88 commit 42b7263

4 files changed

Lines changed: 60 additions & 6 deletions

File tree

.github/workflows/main.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ jobs:
2828
- artifact: arm64-linux
2929
os: ubuntu-22.04-arm
3030

31+
- artifact: riscv64-linux
32+
os: ubuntu-24.04
33+
rust_target: riscv64gc-unknown-linux-gnu
34+
cross_cmake_args: >-
35+
-DCMAKE_SYSTEM_NAME=Linux
36+
-DCMAKE_SYSTEM_PROCESSOR=riscv64
37+
-DCMAKE_C_COMPILER=riscv64-linux-gnu-gcc
38+
-DCMAKE_CXX_COMPILER=riscv64-linux-gnu-g++
39+
-DWASI_SDK_LLDB=OFF
40+
env:
41+
WASI_SDK_CI_SKIP_SYSROOT: 1
42+
WASI_SDK_CI_TOOLCHAIN_LLVM_CMAKE_ARGS: >-
43+
-DCMAKE_SYSTEM_NAME=Linux
44+
-DCMAKE_SYSTEM_PROCESSOR=riscv64
45+
3146
- artifact: arm64-macos
3247
os: macos-14
3348
rust_target: aarch64-apple-darwin
@@ -85,6 +100,9 @@ jobs:
85100
rustup target add ${{ matrix.rust_target }}
86101
cmake_args="$cmake_args -DRUST_TARGET=${{ matrix.rust_target }}"
87102
fi
103+
if [ "${{ matrix.cross_cmake_args }}" != "" ]; then
104+
cmake_args="$cmake_args ${{ matrix.cross_cmake_args }}"
105+
fi
88106
echo WASI_SDK_CI_TOOLCHAIN_CMAKE_ARGS="$cmake_args" >> $GITHUB_ENV
89107
shell: bash
90108

ci/docker-build.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ fi
1515

1616
set -x
1717

18-
# Build the Docker imager
19-
docker build --tag wasi-sdk-builder ci/docker
18+
# Build the Docker image. Use an artifact-specific Dockerfile if one exists
19+
# (e.g. ci/docker/Dockerfile.riscv64-linux), otherwise use the default.
20+
dockerfile=ci/docker/Dockerfile
21+
if [ -f "ci/docker/Dockerfile.$1" ]; then
22+
dockerfile="ci/docker/Dockerfile.$1"
23+
fi
24+
docker build --tag wasi-sdk-builder --file "$dockerfile" ci/docker
2025

2126
# Perform the build in `/src`. The current directory is mounted read-write at
2227
# this location as well. To ensure that container-created files are reasonable
@@ -34,9 +39,11 @@ args="$args --volume $ccache_dir:/ccache:Z --env CCACHE_DIR=/ccache"
3439

3540
# Inherit some tools from the host into this container. This ensures that the
3641
# decision made on CI of what versions to use is the canonical source of truth
37-
# for theset ools
42+
# for these tools.
3843
args="$args --volume `rustc --print sysroot`:/rustc:ro"
39-
args="$args --volume $(dirname $(which wasmtime)):/wasmtime:ro"
44+
if [ "${WASI_SDK_CI_SKIP_SYSROOT:-}" != "1" ]; then
45+
args="$args --volume $(dirname $(command -v wasmtime)):/wasmtime:ro"
46+
fi
4047

4148
# Pass through some env vars that `build.sh` reads
4249
args="$args --env WASI_SDK_CI_TOOLCHAIN_CMAKE_ARGS"

ci/docker/Dockerfile.riscv64-linux

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Ubuntu 24.04 is used here (rather than AlmaLinux 8) because it has
2+
# riscv64 cross-compilation packages in its repositories.
3+
FROM ubuntu:24.04
4+
5+
RUN apt-get update && apt-get install -y --no-install-recommends \
6+
curl \
7+
ca-certificates \
8+
crossbuild-essential-riscv64 \
9+
clang \
10+
lld \
11+
python3 \
12+
git \
13+
unzip \
14+
cmake \
15+
ninja-build \
16+
ccache \
17+
&& rm -rf /var/lib/apt/lists/*
18+
19+
# Cargo needs an explicit linker when cross-compiling for riscv64.
20+
# The C/C++ cross-compiler is passed via CMAKE_C/CXX_COMPILER cmake flags
21+
# rather than CC/CXX env vars so that LLVM's native tblgen sub-build can
22+
# still find the host compiler (cmake cache vars are not inherited by
23+
# subprocess cmake invocations, but env vars are).
24+
ENV CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER=riscv64-linux-gnu-gcc
25+
26+
# Tell programs to cache in a location that both isn't a `--volume` mounted root
27+
# and isn't `/root` in the container as that won't be writable during the build.
28+
ENV XDG_CACHE_HOME=/tmp/cache

ci/merge-artifacts.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ make_deb() {
2121
fi
2222

2323
case $build in
24-
dist-x86_64-linux) deb_arch=amd64 ;;
25-
dist-arm64-linux) deb_arch=arm64 ;;
24+
dist-x86_64-linux) deb_arch=amd64 ;;
25+
dist-arm64-linux) deb_arch=arm64 ;;
26+
dist-riscv64-linux) deb_arch=riscv64 ;;
2627
*)
2728
echo "unknown build $build"
2829
exit 1

0 commit comments

Comments
 (0)