Skip to content

Commit 1dd3704

Browse files
authored
Enable cross-compiling for riscv64 architecture (#7346)
Lighthouse currently lacks support for cross-compilation targeting the `riscv64` architecture. This PR introduces initial support for cross-compiling Lighthouse to `riscv64`. The following changes were made: - **Makefile**: Updated to support `cross` with `riscv64` as a target. - **Cross.toml**: Added configuration specific to `riscv64`. - **Documentation**: List 'build-riscv64' in `book/src/installation_cross_compiling.md`.
1 parent c13e069 commit 1dd3704

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

Cross.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ pre-build = ["apt-get install -y cmake clang-5.0"]
44
[target.aarch64-unknown-linux-gnu]
55
pre-build = ["apt-get install -y cmake clang-5.0"]
66

7+
[target.riscv64gc-unknown-linux-gnu]
8+
pre-build = ["apt-get install -y cmake clang"]
9+
# Use the most recent Cross image for RISCV because the stable 0.2.5 image doesn't work
10+
image = "ghcr.io/cross-rs/riscv64gc-unknown-linux-gnu:main"
11+
712
# Allow setting page size limits for jemalloc at build time:
813
# For certain architectures (like aarch64), we must compile
914
# jemalloc with support for large page sizes, otherwise the host's

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ X86_64_TAG = "x86_64-unknown-linux-gnu"
1010
BUILD_PATH_X86_64 = "target/$(X86_64_TAG)/release"
1111
AARCH64_TAG = "aarch64-unknown-linux-gnu"
1212
BUILD_PATH_AARCH64 = "target/$(AARCH64_TAG)/release"
13+
RISCV64_TAG = "riscv64gc-unknown-linux-gnu"
14+
BUILD_PATH_RISCV64 = "target/$(RISCV64_TAG)/release"
1315

1416
PINNED_NIGHTLY ?= nightly
1517

@@ -67,6 +69,8 @@ build-aarch64:
6769
# pages, which are commonly used by aarch64 systems.
6870
# See: https://github.com/sigp/lighthouse/issues/5244
6971
JEMALLOC_SYS_WITH_LG_PAGE=16 cross build --bin lighthouse --target aarch64-unknown-linux-gnu --features "portable,$(CROSS_FEATURES)" --profile "$(CROSS_PROFILE)" --locked
72+
build-riscv64:
73+
cross build --bin lighthouse --target riscv64gc-unknown-linux-gnu --features "portable,$(CROSS_FEATURES)" --profile "$(CROSS_PROFILE)" --locked
7074

7175
build-lcli-x86_64:
7276
cross build --bin lcli --target x86_64-unknown-linux-gnu --features "portable" --profile "$(CROSS_PROFILE)" --locked
@@ -75,6 +79,8 @@ build-lcli-aarch64:
7579
# pages, which are commonly used by aarch64 systems.
7680
# See: https://github.com/sigp/lighthouse/issues/5244
7781
JEMALLOC_SYS_WITH_LG_PAGE=16 cross build --bin lcli --target aarch64-unknown-linux-gnu --features "portable" --profile "$(CROSS_PROFILE)" --locked
82+
build-lcli-riscv64:
83+
cross build --bin lcli --target riscv64gc-unknown-linux-gnu --features "portable" --profile "$(CROSS_PROFILE)" --locked
7884

7985
# Create a `.tar.gz` containing a binary for a specific target.
8086
define tarball_release_binary
@@ -95,6 +101,9 @@ build-release-tarballs:
95101
$(call tarball_release_binary,$(BUILD_PATH_X86_64),$(X86_64_TAG),"")
96102
$(MAKE) build-aarch64
97103
$(call tarball_release_binary,$(BUILD_PATH_AARCH64),$(AARCH64_TAG),"")
104+
$(MAKE) build-riscv64
105+
$(call tarball_release_binary,$(BUILD_PATH_RISCV64),$(RISCV64_TAG),"")
106+
98107

99108
# Runs the full workspace tests in **release**, without downloading any additional
100109
# test vectors.

book/src/installation_cross_compiling.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ project.
1818
The `Makefile` in the project contains two targets for cross-compiling:
1919

2020
- `build-x86_64`: builds an optimized version for x86_64 processors (suitable for most users).
21-
- `build-aarch64`: builds an optimized version for 64-bit ARM processors (suitable for Raspberry Pi 4).
21+
- `build-aarch64`: builds an optimized version for 64-bit ARM processors (suitable for Raspberry Pi 4/5).
22+
- `build-riscv64`: builds an optimized version for 64-bit RISC-V processors.
2223

2324
### Example
2425

0 commit comments

Comments
 (0)