Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/zeroos-arch-riscv/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/zeroos-build/src/files/generic-linux.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}",
Expand Down
24 changes: 23 additions & 1 deletion crates/zeroos-build/src/spec/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32> {
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)
Expand Down Expand Up @@ -54,14 +69,21 @@ impl TargetConfig {
) -> Result<String, String> {
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(),
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Version threshold for pointer-width format may be wrong

Low Severity

The code comment claims the target-pointer-width JSON type change happened in rustc 1.91, but the PR description states "rustc 1.94 tightened JSON schema validation and rejects the string form." The threshold minor < 91 may need to be minor < 94. If the change actually landed in 1.94, rustc versions 1.91–1.93 would receive the integer form when they still expect a string, producing invalid target JSON for anyone using those compiler versions.

Fix in Cursor Fix in Web


let ctx = ztpl::Context::new()
.with_str("ARCH", arch_spec.arch)
.with_str("CPU", arch_spec.cpu)
.with_str("FEATURES", &llvm_config.features)
.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)
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
channel = "1.90"
channel = "1.94"
targets = [
"riscv64imac-unknown-none-elf",
"riscv32imac-unknown-none-elf",
Expand Down
Loading