From 985b12ffa6d526bbf3a884cfcc12907a0a4205bd Mon Sep 17 00:00:00 2001 From: Zou Guangxian Date: Mon, 26 Jan 2026 04:14:53 +0000 Subject: [PATCH] feat(build): add support for custom RUSTFLAGS in build_binary_with_rustflags function --- build-syscall-cycles.sh | 10 ++++++---- crates/zeroos-build/src/cmds/build.rs | 6 ++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/build-syscall-cycles.sh b/build-syscall-cycles.sh index 47d67fa..fa3da82 100755 --- a/build-syscall-cycles.sh +++ b/build-syscall-cycles.sh @@ -14,11 +14,13 @@ cd "${ROOT}" echo "Building syscall-cycles example in std mode ..." if [[ "${PROFILE}" = "release" ]]; then # Keep release profile tuning explicit (avoid per-crate [profile.release] warnings). + # Disable machine outliner to avoid OUTLINED_FUNCTION_* symbols interfering with cycle counts. CARGO_PROFILE_RELEASE_DEBUG=2 \ - CARGO_PROFILE_RELEASE_STRIP=none \ - CARGO_PROFILE_RELEASE_LTO=true \ - CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1 \ - cargo spike build -p syscall-cycles --target "${TARGET_TRIPLE}" --mode std -- --quiet --features=std --profile "${PROFILE}" + CARGO_PROFILE_RELEASE_STRIP=none \ + CARGO_PROFILE_RELEASE_LTO=true \ + CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1 \ + RUSTFLAGS="${RUSTFLAGS:-} -Cllvm-args=-enable-machine-outliner=never" \ + cargo spike build -p syscall-cycles --target "${TARGET_TRIPLE}" --mode std -- --quiet --features=std --profile "${PROFILE}" else cargo spike build -p syscall-cycles --target "${TARGET_TRIPLE}" --mode std -- --quiet --features=std --profile "${PROFILE}" fi diff --git a/crates/zeroos-build/src/cmds/build.rs b/crates/zeroos-build/src/cmds/build.rs index 01d5a44..9ed829f 100644 --- a/crates/zeroos-build/src/cmds/build.rs +++ b/crates/zeroos-build/src/cmds/build.rs @@ -193,6 +193,12 @@ pub fn build_binary_with_rustflags( .map(|s| s.split('\x1f').map(|s| s.to_string()).collect()) .unwrap_or_default(); + if let Ok(rustflags) = std::env::var("RUSTFLAGS") { + for flag in rustflags.split_whitespace() { + rustflags_parts.push(flag.to_string()); + } + } + // In unwind-table-based backtraces, we need DWARF CFI tables even with `panic=abort`. // This forces `.eh_frame` emission for Rust code when backtraces are enabled. if args.mode == StdMode::Std && backtrace_enabled {