Debian Codegraph @

debian/patches/riscv64a23-support.patch

raw
1 From: Max Gilmour <[email protected]>
2 Date: Wed, 11 Mar 2026 14:26:16 -0400
3 Subject: Support RISC-V RVA23
4
5 As part of the general process of moving Ubuntu to RVA23, the default
6 riscv64 platform for the Ubuntu Rust toolchain is now
7 riscv64a23-unknown-linux-gnu.
8
9 The build configuration steps have been modified so the configuration
10 system is able to recognise riscv64a23 as a riscv64 architecture.
11
12 The Rust configuration file has been modified so that when RUST_TARGET
13 is set and exactly matches one of the available Rust target candidates,
14 that candidate is used directly. This disambiguates between riscv64gc
15 and riscv64a23 on systems where rustc supports both targets. This
16 applies to both the host and target triplet detection. If RUST_TARGET
17 is not set or does not match any candidate, the build falls back to
18 the normal behaviour.
19
20 Additionally, the vendored cc crate was patched so it's able to
21 properly translate the riscv64a23 target to its clang equivalent. This
22 change is based off the upstream addition of riscv64a23 in rust-cc
23 1.2.53: https://github.com/rust-lang/cc-rs/commit/66ceffe1884c
24
25 Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/mozjs140/+bug/2143666
26 ---
27 build/moz.configure/init.configure | 2 +-
28 build/moz.configure/rust.configure | 26 ++++++++++++++++++++------
29 third_party/rust/cc/src/lib.rs | 1 +
30 3 files changed, 22 insertions(+), 7 deletions(-)
31
32 diff --git a/build/moz.configure/init.configure b/build/moz.configure/init.configure
33 index 6162d68..42b8b89 100644
34 --- a/build/moz.configure/init.configure
35 +++ b/build/moz.configure/init.configure
36 @@ -562,7 +562,7 @@ def split_triplet(triplet, allow_wasi=False):
37 elif cpu.startswith("aarch64"):
38 canonical_cpu = "aarch64"
39 endianness = "little"
40 - elif cpu in ("riscv64", "riscv64gc"):
41 + elif cpu in ("riscv64", "riscv64gc", "riscv64a23"):
42 canonical_cpu = "riscv64"
43 endianness = "little"
44 elif cpu.startswith("loongarch64"):
45 diff --git a/build/moz.configure/rust.configure b/build/moz.configure/rust.configure
46 index 812dde1..988d728 100644
47 --- a/build/moz.configure/rust.configure
48 +++ b/build/moz.configure/rust.configure
49 @@ -279,9 +279,14 @@ def rust_supported_targets(rustc):
50 data.setdefault(key, []).append(namespace(rust_target=t, target=info))
51 return data
52
53 +option(env="RUST_TARGET", nargs=1, help="Rust compiler target triple override")
54 +
55 +@depends("RUST_TARGET")
56 +def rust_target_env(value):
57 + return value[0] if value else None
58
59 def detect_rustc_target(
60 - host_or_target, compiler_info, arm_target, rust_supported_targets
61 + host_or_target, compiler_info, arm_target, rust_supported_targets, rust_target_env=None
62 ):
63 # Rust's --target options are similar to, but not exactly the same
64 # as, the autoconf-derived targets we use. An example would be that
65 @@ -302,6 +307,14 @@ def detect_rustc_target(
66 elif not candidates:
67 return None
68
69 + # riscv64 has multiple Rust targets (e.g. riscv64gc, riscv64a23).
70 + # If RUST_TARGET is set and exactly matches one of the candidates,
71 + # use it to disambiguate.
72 + if host_or_target.cpu == "riscv64" and rust_target_env:
73 + for c in candidates:
74 + if c.rust_target == rust_target_env:
75 + return c.rust_target
76 +
77 # We have multiple candidates. There are two cases where we can try to
78 # narrow further down using extra information from the build system.
79 # - For windows targets, correlate with the C compiler type
80 @@ -483,15 +496,16 @@ def assert_rust_compile(host_or_target, rustc_target, rustc):
81 rustc_info.host,
82 rust_supported_targets,
83 arm_target,
84 + rust_target_env,
85 when=rust_compiler,
86 )
87 @checking("for rust host triplet")
88 @imports(_from="textwrap", _import="dedent")
89 def rust_host_triple(
90 - rustc, host, compiler_info, rustc_host, rust_supported_targets, arm_target
91 + rustc, host, compiler_info, rustc_host, rust_supported_targets, arm_target, rust_target_env
92 ):
93 rustc_target = detect_rustc_target(
94 - host, compiler_info, arm_target, rust_supported_targets
95 + host, compiler_info, arm_target, rust_supported_targets, rust_target_env=rust_target_env
96 )
97 if rustc_target != rustc_host:
98 if host.alias == rustc_target:
99 @@ -520,14 +534,14 @@ def rust_host_triple(
100
101
102 @depends(
103 - rustc, target, c_compiler, rust_supported_targets, arm_target, when=rust_compiler
104 + rustc, target, c_compiler, rust_supported_targets, arm_target, rust_target_env, when=rust_compiler
105 )
106 @checking("for rust target triplet")
107 def rust_target_triple(
108 - rustc, target, compiler_info, rust_supported_targets, arm_target
109 + rustc, target, compiler_info, rust_supported_targets, arm_target, rust_target_env
110 ):
111 rustc_target = detect_rustc_target(
112 - target, compiler_info, arm_target, rust_supported_targets
113 + target, compiler_info, arm_target, rust_supported_targets, rust_target_env=rust_target_env
114 )
115 assert_rust_compile(target, rustc_target, rustc)
116 return rustc_target
117 diff --git a/third_party/rust/cc/src/lib.rs b/third_party/rust/cc/src/lib.rs
118 index 0631584..e8fba49 100644
119 --- a/third_party/rust/cc/src/lib.rs
120 +++ b/third_party/rust/cc/src/lib.rs
121 @@ -3438,6 +3438,7 @@ impl Build {
122 "riscv-none-embed",
123 ]),
124 "riscv64gc-unknown-linux-gnu" => Some("riscv64-linux-gnu"),
125 + "riscv64a23-unknown-linux-gnu" => Some("riscv64-linux-gnu"),
126 "riscv32gc-unknown-linux-gnu" => Some("riscv32-linux-gnu"),
127 "riscv64gc-unknown-linux-musl" => Some("riscv64-linux-musl"),
128 "riscv32gc-unknown-linux-musl" => Some("riscv32-linux-musl"),