diff --git a/crates/zeroos-arch-riscv/src/ops.rs b/crates/zeroos-arch-riscv/src/ops.rs index 8d7f768..7ac7237 100644 --- a/crates/zeroos-arch-riscv/src/ops.rs +++ b/crates/zeroos-arch-riscv/src/ops.rs @@ -130,7 +130,7 @@ pub const ARCH_OPS: ArchOps = ArchOps { thread_ctx_set_ra: crate::thread_ctx::thread_ctx_set_ra, thread_ctx_set_retval: crate::thread_ctx::thread_ctx_set_retval, switch_to, - ret_from_fork: || ret_from_fork as usize, + ret_from_fork: || ret_from_fork as *const () as usize, trap_frame_clone, trap_frame_init, trap_frame_set_retval, diff --git a/crates/zeroos-build/src/files/generic-linux.json.template b/crates/zeroos-build/src/files/generic-linux.json.template index 2932085..889670f 100644 --- a/crates/zeroos-build/src/files/generic-linux.json.template +++ b/crates/zeroos-build/src/files/generic-linux.json.template @@ -6,7 +6,7 @@ "llvm-abiname": "{{ ABI }}", "data-layout": "{{ DATA_LAYOUT }}", "target-endian": "{{ ENDIAN }}", - "target-pointer-width": "{{ POINTER_WIDTH }}", + "target-pointer-width": {{ POINTER_WIDTH }}, "os": "{{ OS }}", "env": "{{ ENV }}", "vendor": "{{ VENDOR }}", diff --git a/crates/zeroos-build/src/spec/utils.rs b/crates/zeroos-build/src/spec/utils.rs index 89dac11..181c48d 100644 --- a/crates/zeroos-build/src/spec/utils.rs +++ b/crates/zeroos-build/src/spec/utils.rs @@ -4,6 +4,21 @@ use crate::spec::llvm::LLVMConfig; use crate::spec::ArchSpec; use mini_template as ztpl; +/// Returns the rustc minor version (e.g. 91 for 1.91.0), or None if it cannot be determined. +/// Respects the RUSTC env var so that callers running inside a Cargo build script use the +/// correct toolchain. +fn rustc_minor_version() -> Option { + let rustc = std::env::var("RUSTC").unwrap_or_else(|_| "rustc".to_string()); + let output = std::process::Command::new(rustc) + .arg("--version") + .output() + .ok()?; + // "rustc 1.94.0 (4a4ef493e 2026-03-02)" + let stdout = String::from_utf8(output.stdout).ok()?; + let version = stdout.split_whitespace().nth(1)?; + version.split('.').nth(1)?.parse().ok() +} + #[derive(Debug, Clone, Copy)] pub struct TargetRenderOptions { /// Whether to emit DWARF unwind tables (.eh_frame sections) @@ -54,6 +69,13 @@ impl TargetConfig { ) -> Result { let template = GENERIC_LINUX_TEMPLATE; + // target-pointer-width changed from a JSON string to a JSON integer in rustc 1.91 + // (rust-lang/rust#144443). Default to the integer form for unknown/new versions. + let pointer_width_json = match rustc_minor_version() { + Some(minor) if minor < 91 => format!("\"{}\"", arch_spec.pointer_width), + _ => arch_spec.pointer_width.to_string(), + }; + let ctx = ztpl::Context::new() .with_str("ARCH", arch_spec.arch) .with_str("CPU", arch_spec.cpu) @@ -61,7 +83,7 @@ impl TargetConfig { .with_str("LLVM_TARGET", &llvm_config.llvm_target) .with_str("ABI", &llvm_config.abi) .with_str("DATA_LAYOUT", &llvm_config.data_layout) - .with_str("POINTER_WIDTH", arch_spec.pointer_width) + .with_str("POINTER_WIDTH", &pointer_width_json) .with_str("ENDIAN", arch_spec.endian) .with_str("OS", &self.os) .with_str("ENV", &self.abi) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index c0a3c6e..d0148e4 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "1.90" +channel = "1.94" targets = [ "riscv64imac-unknown-none-elf", "riscv32imac-unknown-none-elf",