diff --git a/compiler-builtins/build.rs b/compiler-builtins/build.rs index e86c784b5..093fa11a0 100644 --- a/compiler-builtins/build.rs +++ b/compiler-builtins/build.rs @@ -538,7 +538,22 @@ mod c { // Support deterministic builds by remapping the __FILE__ prefix if the // compiler supports it. This fixes the nondeterminism caused by the // use of that macro in lib/builtins/int_util.h in compiler-rt. - build.flag_if_supported(&format!("-ffile-prefix-map={}=.", root.display())); + + // `RUSTC_DEBUGINFO_MAP` is a bootstrap-specific env var (not a general + // Cargo/rustc mechanism) containing the `--remap-path-prefix` mappings + // bootstrap passes to rustc via its rustc shim. Bootstrap uses this + // instead of RUSTFLAGS because Cargo doesn't always forward RUSTFLAGS to + // build scripts and proc-macros (rust-lang/cargo#4423). + // + // Apply each mapping via -ffile-prefix-map, mirroring rustc_llvm's + // build.rs for the same env var. + if let Some(maps) = env::var_os("RUSTC_DEBUGINFO_MAP") + && let Some(maps_str) = maps.to_str() + { + for map in maps_str.split('\t') { + build.flag_if_supported(&format!("-ffile-prefix-map={map}")); + } + } // Include out-of-line atomics for aarch64, which are all generated by supplying different // sets of flags to the same source file.