From: Max Gilmour Date: Wed, 11 Mar 2026 14:26:16 -0400 Subject: Support RISC-V RVA23 As part of the general process of moving Ubuntu to RVA23, the default riscv64 platform for the Ubuntu Rust toolchain is now riscv64a23-unknown-linux-gnu. The build configuration steps have been modified so the configuration system is able to recognise riscv64a23 as a riscv64 architecture. The Rust configuration file has been modified so that when RUST_TARGET is set and exactly matches one of the available Rust target candidates, that candidate is used directly. This disambiguates between riscv64gc and riscv64a23 on systems where rustc supports both targets. This applies to both the host and target triplet detection. If RUST_TARGET is not set or does not match any candidate, the build falls back to the normal behaviour. Additionally, the vendored cc crate was patched so it's able to properly translate the riscv64a23 target to its clang equivalent. This change is based off the upstream addition of riscv64a23 in rust-cc 1.2.53: https://github.com/rust-lang/cc-rs/commit/66ceffe1884c Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/mozjs140/+bug/2143666 --- build/moz.configure/init.configure | 2 +- build/moz.configure/rust.configure | 26 ++++++++++++++++++++------ third_party/rust/cc/src/lib.rs | 1 + 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/build/moz.configure/init.configure b/build/moz.configure/init.configure index 6162d68..42b8b89 100644 --- a/build/moz.configure/init.configure +++ b/build/moz.configure/init.configure @@ -562,7 +562,7 @@ def split_triplet(triplet, allow_wasi=False): elif cpu.startswith("aarch64"): canonical_cpu = "aarch64" endianness = "little" - elif cpu in ("riscv64", "riscv64gc"): + elif cpu in ("riscv64", "riscv64gc", "riscv64a23"): canonical_cpu = "riscv64" endianness = "little" elif cpu.startswith("loongarch64"): diff --git a/build/moz.configure/rust.configure b/build/moz.configure/rust.configure index 812dde1..988d728 100644 --- a/build/moz.configure/rust.configure +++ b/build/moz.configure/rust.configure @@ -279,9 +279,14 @@ def rust_supported_targets(rustc): data.setdefault(key, []).append(namespace(rust_target=t, target=info)) return data +option(env="RUST_TARGET", nargs=1, help="Rust compiler target triple override") + +@depends("RUST_TARGET") +def rust_target_env(value): + return value[0] if value else None def detect_rustc_target( - host_or_target, compiler_info, arm_target, rust_supported_targets + host_or_target, compiler_info, arm_target, rust_supported_targets, rust_target_env=None ): # Rust's --target options are similar to, but not exactly the same # as, the autoconf-derived targets we use. An example would be that @@ -302,6 +307,14 @@ def detect_rustc_target( elif not candidates: return None + # riscv64 has multiple Rust targets (e.g. riscv64gc, riscv64a23). + # If RUST_TARGET is set and exactly matches one of the candidates, + # use it to disambiguate. + if host_or_target.cpu == "riscv64" and rust_target_env: + for c in candidates: + if c.rust_target == rust_target_env: + return c.rust_target + # We have multiple candidates. There are two cases where we can try to # narrow further down using extra information from the build system. # - For windows targets, correlate with the C compiler type @@ -483,15 +496,16 @@ def assert_rust_compile(host_or_target, rustc_target, rustc): rustc_info.host, rust_supported_targets, arm_target, + rust_target_env, when=rust_compiler, ) @checking("for rust host triplet") @imports(_from="textwrap", _import="dedent") def rust_host_triple( - rustc, host, compiler_info, rustc_host, rust_supported_targets, arm_target + rustc, host, compiler_info, rustc_host, rust_supported_targets, arm_target, rust_target_env ): rustc_target = detect_rustc_target( - host, compiler_info, arm_target, rust_supported_targets + host, compiler_info, arm_target, rust_supported_targets, rust_target_env=rust_target_env ) if rustc_target != rustc_host: if host.alias == rustc_target: @@ -520,14 +534,14 @@ def rust_host_triple( @depends( - rustc, target, c_compiler, rust_supported_targets, arm_target, when=rust_compiler + rustc, target, c_compiler, rust_supported_targets, arm_target, rust_target_env, when=rust_compiler ) @checking("for rust target triplet") def rust_target_triple( - rustc, target, compiler_info, rust_supported_targets, arm_target + rustc, target, compiler_info, rust_supported_targets, arm_target, rust_target_env ): rustc_target = detect_rustc_target( - target, compiler_info, arm_target, rust_supported_targets + target, compiler_info, arm_target, rust_supported_targets, rust_target_env=rust_target_env ) assert_rust_compile(target, rustc_target, rustc) return rustc_target diff --git a/third_party/rust/cc/src/lib.rs b/third_party/rust/cc/src/lib.rs index 0631584..e8fba49 100644 --- a/third_party/rust/cc/src/lib.rs +++ b/third_party/rust/cc/src/lib.rs @@ -3438,6 +3438,7 @@ impl Build { "riscv-none-embed", ]), "riscv64gc-unknown-linux-gnu" => Some("riscv64-linux-gnu"), + "riscv64a23-unknown-linux-gnu" => Some("riscv64-linux-gnu"), "riscv32gc-unknown-linux-gnu" => Some("riscv32-linux-gnu"), "riscv64gc-unknown-linux-musl" => Some("riscv64-linux-musl"), "riscv32gc-unknown-linux-musl" => Some("riscv32-linux-musl"),