Skip to content

Commit 3b132ce

Browse files
sagar-a16zzouguangxian
authored andcommitted
fix: target-pointer-width must be an integer in target spec JSON
rustc 1.91 (rust-lang/rust#144443) changed target-pointer-width in custom target JSON from a string to an integer. Bump the pinned toolchain to 1.94 to pick up that requirement and fix the template. zeroos-build now detects the active rustc minor version at runtime and emits the value as a quoted string for toolchains older than 1.91, keeping the tool portable. Also fix a direct function-item-to-integer cast in zeroos-arch-riscv that became a hard error under -D warnings once the function_casts_as_integer lint (rust-lang/rust#141470, stable in 1.93) was active.
1 parent fc2e6cd commit 3b132ce

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

crates/zeroos-arch-riscv/src/ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub const ARCH_OPS: ArchOps = ArchOps {
130130
thread_ctx_set_ra: crate::thread_ctx::thread_ctx_set_ra,
131131
thread_ctx_set_retval: crate::thread_ctx::thread_ctx_set_retval,
132132
switch_to,
133-
ret_from_fork: || ret_from_fork as usize,
133+
ret_from_fork: || ret_from_fork as *const () as usize,
134134
trap_frame_clone,
135135
trap_frame_init,
136136
trap_frame_set_retval,

crates/zeroos-build/src/files/generic-linux.json.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"llvm-abiname": "{{ ABI }}",
77
"data-layout": "{{ DATA_LAYOUT }}",
88
"target-endian": "{{ ENDIAN }}",
9-
"target-pointer-width": "{{ POINTER_WIDTH }}",
9+
"target-pointer-width": {{ POINTER_WIDTH }},
1010
"os": "{{ OS }}",
1111
"env": "{{ ENV }}",
1212
"vendor": "{{ VENDOR }}",

crates/zeroos-build/src/spec/utils.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ use crate::spec::llvm::LLVMConfig;
44
use crate::spec::ArchSpec;
55
use mini_template as ztpl;
66

7+
/// Returns the rustc minor version (e.g. 91 for 1.91.0), or None if it cannot be determined.
8+
/// Respects the RUSTC env var so that callers running inside a Cargo build script use the
9+
/// correct toolchain.
10+
fn rustc_minor_version() -> Option<u32> {
11+
let rustc = std::env::var("RUSTC").unwrap_or_else(|_| "rustc".to_string());
12+
let output = std::process::Command::new(rustc)
13+
.arg("--version")
14+
.output()
15+
.ok()?;
16+
// "rustc 1.94.0 (4a4ef493e 2026-03-02)"
17+
let stdout = String::from_utf8(output.stdout).ok()?;
18+
let version = stdout.split_whitespace().nth(1)?;
19+
version.split('.').nth(1)?.parse().ok()
20+
}
21+
722
#[derive(Debug, Clone, Copy)]
823
pub struct TargetRenderOptions {
924
/// Whether to emit DWARF unwind tables (.eh_frame sections)
@@ -54,14 +69,21 @@ impl TargetConfig {
5469
) -> Result<String, String> {
5570
let template = GENERIC_LINUX_TEMPLATE;
5671

72+
// target-pointer-width changed from a JSON string to a JSON integer in rustc 1.91
73+
// (rust-lang/rust#144443). Default to the integer form for unknown/new versions.
74+
let pointer_width_json = match rustc_minor_version() {
75+
Some(minor) if minor < 91 => format!("\"{}\"", arch_spec.pointer_width),
76+
_ => arch_spec.pointer_width.to_string(),
77+
};
78+
5779
let ctx = ztpl::Context::new()
5880
.with_str("ARCH", arch_spec.arch)
5981
.with_str("CPU", arch_spec.cpu)
6082
.with_str("FEATURES", &llvm_config.features)
6183
.with_str("LLVM_TARGET", &llvm_config.llvm_target)
6284
.with_str("ABI", &llvm_config.abi)
6385
.with_str("DATA_LAYOUT", &llvm_config.data_layout)
64-
.with_str("POINTER_WIDTH", arch_spec.pointer_width)
86+
.with_str("POINTER_WIDTH", &pointer_width_json)
6587
.with_str("ENDIAN", arch_spec.endian)
6688
.with_str("OS", &self.os)
6789
.with_str("ENV", &self.abi)

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[toolchain]
2-
channel = "1.90"
2+
channel = "1.94"
33
targets = [
44
"riscv64imac-unknown-none-elf",
55
"riscv32imac-unknown-none-elf",

0 commit comments

Comments
 (0)