From b399aec99e812581b32431493e0c117c3c7a4a53 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Fri, 7 Aug 2026 08:39:41 -0400 Subject: [PATCH 1/5] bootstrap: remap-debuginfo via cargo trim-paths Replace `RUSTC_DEBUGINFO_MAP` and `RUSTC_CARGO_REGISTRY_SRC_TO_REMAP` with cargo trim-paths and `__CARGO_RUSTC_BOOTSTRAP_WS_REMAP` override (See cargo#17309). The `RUSTC_DEBUGINFO_MAP` into `-ffile-prefix-map` in rustc_llvm will be covered cc@1.3.0+ natively (which inherits and forwards `CARGO_TRIM_PATHS_REMAP`) --- compiler/rustc_llvm/build.rs | 9 ---- src/bootstrap/src/bin/rustc.rs | 14 ------ src/bootstrap/src/core/builder/cargo.rs | 66 ++++--------------------- 3 files changed, 9 insertions(+), 80 deletions(-) diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs index c6a4013db3913..78f3929dbce47 100644 --- a/compiler/rustc_llvm/build.rs +++ b/compiler/rustc_llvm/build.rs @@ -290,15 +290,6 @@ fn main() { cfg.flag(&*flag); } - // Remap ci-llvm include paths in debug info for reproducible builds. - if let Some(maps) = tracked_env_var_os("RUSTC_DEBUGINFO_MAP") - && let Some(maps_str) = maps.to_str() - { - for map in maps_str.split('\t') { - cfg.flag_if_supported(&format!("-ffile-prefix-map={map}")); - } - } - for component in &components { let mut flag = String::from("LLVM_COMPONENT_"); flag.push_str(&component.to_uppercase()); diff --git a/src/bootstrap/src/bin/rustc.rs b/src/bootstrap/src/bin/rustc.rs index 3d40e0a86c111..5db1f9f78b1f4 100644 --- a/src/bootstrap/src/bin/rustc.rs +++ b/src/bootstrap/src/bin/rustc.rs @@ -163,20 +163,6 @@ fn main() { } } - // The remap flags for the compiler and standard library sources. - if let Ok(maps) = env::var("RUSTC_DEBUGINFO_MAP") { - for map in maps.split('\t') { - cmd.arg("--remap-path-prefix").arg(map); - } - } - // The remap flags for Cargo registry sources need to be passed after the remapping for the - // Rust source code directory, to handle cases when $CARGO_HOME is inside the source directory. - if let Ok(maps) = env::var("RUSTC_CARGO_REGISTRY_SRC_TO_REMAP") { - for map in maps.split('\t') { - cmd.arg("--remap-path-prefix").arg(map); - } - } - // Here we pass additional paths that essentially act as a sysroot. // These are used to load rustc crates (e.g. `extern crate rustc_ast;`) // for rustc_private tools, so that we do not have to copy them into the diff --git a/src/bootstrap/src/core/builder/cargo.rs b/src/bootstrap/src/core/builder/cargo.rs index b8e2a585e3397..3651b6c263072 100644 --- a/src/bootstrap/src/core/builder/cargo.rs +++ b/src/bootstrap/src/core/builder/cargo.rs @@ -1161,9 +1161,13 @@ impl Builder<'_> { // // Keep this scheme in sync with `rustc_metadata::rmeta::decoder`'s // `try_to_translate_virtual_to_real`. - // - // `RUSTC_DEBUGINFO_MAP` is used to pass through to the underlying rustc - // `--remap-path-prefix`. + let trim_paths = |cargo: &mut BootstrapCommand, ws_remap: &str| { + cargo.arg("-Ztrim-paths"); + cargo.arg("--config").arg("profile.release.trim-paths='all'"); + cargo.arg("--config").arg("profile.dev.trim-paths='all'"); + cargo.env("__CARGO_RUSTC_BOOTSTRAP_WS_REMAP", ws_remap); + }; + match mode { Mode::Rustc | Mode::Codegen => { if let Some(ref map_to) = @@ -1179,24 +1183,7 @@ impl Builder<'_> { // Tell the compiler which prefix was used for remapping the compiler it-self cargo.env("CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR", map_to); - // When building compiler sources, we want to apply the compiler remap scheme. - let map = [ - // Cargo use relative paths for workspace members, so let's remap those. - format!("compiler/={map_to}/compiler"), - // rustc creates absolute paths (in part bc of the `rust-src` unremap - // and for working directory) so let's remap the build directory as well. - format!("{}={map_to}", self.build.src.display()), - // remap OUT_DIR so they don't leak into artifacts. - format!("{}={map_to}/out", self.build.out.display()), - // on windows, rustc may use forward slashes internally - #[cfg(windows)] - format!( - "{}={map_to}\\out", - self.build.out.display().to_string().replace('/', "\\") - ), - ] - .join("\t"); - cargo.env("RUSTC_DEBUGINFO_MAP", map); + trim_paths(&mut cargo, map_to); } } Mode::Std @@ -1207,44 +1194,9 @@ impl Builder<'_> { if let Some(ref map_to) = self.build.debuginfo_map_to(GitRepo::Rustc, RemapScheme::NonCompiler) { - // When building the standard library sources, we want to apply the std remap scheme. - let map = [ - // Cargo use relative paths for workspace members, so let's remap those. - format!("library/={map_to}/library"), - // rustc creates absolute paths (in part bc of the `rust-src` unremap - // and for working directory) so let's remap the build directory as well. - format!("{}={map_to}", self.build.src.display()), - // remap OUT_DIR so they don't leak into artifacts. - format!("{}={map_to}/out", self.build.out.display()), - // on windows, rustc may use forward slashes internally - #[cfg(windows)] - format!( - "{}={map_to}\\out", - self.build.out.display().to_string().replace('/', "\\") - ), - ] - .join("\t"); - cargo.env("RUSTC_DEBUGINFO_MAP", map); - } - } - } - - if self.config.rust_remap_debuginfo { - let mut env_var = OsString::new(); - if let Some(vendor) = self.build.vendored_crates_path() { - env_var.push(vendor); - env_var.push("=/rust/deps"); - } else { - let registry_src = t!(home::cargo_home()).join("registry").join("src"); - for entry in t!(std::fs::read_dir(registry_src)) { - if !env_var.is_empty() { - env_var.push("\t"); - } - env_var.push(t!(entry).path()); - env_var.push("=/rust/deps"); + trim_paths(&mut cargo, map_to); } } - cargo.env("RUSTC_CARGO_REGISTRY_SRC_TO_REMAP", env_var); } // Enable usage of unstable features From 5cf3ce2dc6c52d680bacfb0949d067a6e1854bf3 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Wed, 12 Aug 2026 23:52:30 -0400 Subject: [PATCH 2/5] tests: check `$CARGO_HOME` leaks --- tests/run-make/remap-path-prefix-std/rmake.rs | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/tests/run-make/remap-path-prefix-std/rmake.rs b/tests/run-make/remap-path-prefix-std/rmake.rs index 6e3bb69705c94..ff3b3bdaa8e45 100644 --- a/tests/run-make/remap-path-prefix-std/rmake.rs +++ b/tests/run-make/remap-path-prefix-std/rmake.rs @@ -64,23 +64,30 @@ fn main() { let stdout = completed.stdout_utf8(); let source_root = source_root(); - let root = source_root.to_string_lossy(); - if let Some((i, _)) = - stdout.lines().enumerate().find(|(_, line)| line.contains(root.as_ref())) - { - let lines: Vec<_> = stdout.lines().collect(); + let cargo_home = std::env::var("CARGO_HOME").map(PathBuf::from); + let mut local_roots = vec![("source-root", source_root.to_string_lossy())]; + if let Ok(cargo_home) = &cargo_home { + local_roots.push(("cargo-home", cargo_home.to_string_lossy())); + } - let start = i.saturating_sub(2); - let end = (i + 3).min(lines.len()); + for (kind, root) in &local_roots { + if let Some((i, _)) = + stdout.lines().enumerate().find(|(_, line)| line.contains(root.as_ref())) + { + let lines: Vec<_> = stdout.lines().collect(); - eprintln!("leaked source-root path found in {link_name}:"); + let start = i.saturating_sub(2); + let end = (i + 3).min(lines.len()); - for line in &lines[start..end] { - eprintln!("{line}"); - } + eprintln!("leaked {kind} path found in {link_name}:"); - panic!("found leaked source-root path in {link_name}"); + for line in &lines[start..end] { + eprintln!("{line}"); + } + + panic!("found leaked {kind} path in {link_name}"); + } } // Check that remapped paths are present if the rlib has debug info. From c2769052a86d979ccae9e6f2a42c16ba58c1c8e4 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Thu, 13 Aug 2026 21:21:19 -0400 Subject: [PATCH 3/5] tests: check std rmeta for local path leaks The current dwarfdump checks cannot see `.rmeta` leaks: * The compiler keeps unremapped local paths in metadata unless the remap scope is `all` (see issue 159621) * std ships metadata as separate `.rmeta` via `-Zembed-metadata=no` so the leak does not even appear in the rlibs This commit enhances to also check rmeta files. --- tests/run-make/remap-path-prefix-std/rmake.rs | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/tests/run-make/remap-path-prefix-std/rmake.rs b/tests/run-make/remap-path-prefix-std/rmake.rs index ff3b3bdaa8e45..4f101efc486b3 100644 --- a/tests/run-make/remap-path-prefix-std/rmake.rs +++ b/tests/run-make/remap-path-prefix-std/rmake.rs @@ -43,6 +43,13 @@ fn main() { // There must be at least one rlib (libstd itself, plus many others) assert!(!all_rlibs.is_empty(), "no rlibs found in target libdir {target_libdir:?}"); + let source_root = source_root(); + let cargo_home = std::env::var("CARGO_HOME").map(PathBuf::from); + let mut local_roots = vec![("source-root", source_root.to_string_lossy())]; + if let Ok(cargo_home) = &cargo_home { + local_roots.push(("cargo-home", cargo_home.to_string_lossy())); + } + for rlib in &all_rlibs { // Use a stable symlink name based on the crate part (before the '-' suffix). // e.g. "libstd-92abaa9b58c011c1.rlib" → "libstd.rlib" @@ -63,13 +70,6 @@ fn main() { } let stdout = completed.stdout_utf8(); - let source_root = source_root(); - - let cargo_home = std::env::var("CARGO_HOME").map(PathBuf::from); - let mut local_roots = vec![("source-root", source_root.to_string_lossy())]; - if let Ok(cargo_home) = &cargo_home { - local_roots.push(("cargo-home", cargo_home.to_string_lossy())); - } for (kind, root) in &local_roots { if let Some((i, _)) = @@ -98,4 +98,21 @@ fn main() { ); } } + + // `-Zembed-metadata=no` creates separate rmeta that may leak absolute paths + let all_rmetas = + shallow_find_files(&target_libdir, |p| p.extension().is_some_and(|ext| ext == "rmeta")); + assert!(!all_rmetas.is_empty(), "no rmeta files found in target libdir {target_libdir:?}"); + + for rmeta in &all_rmetas { + let filename = rmeta.file_name().unwrap().to_string_lossy(); + let bytes = rfs::read(rmeta); + + for (kind, root) in &local_roots { + let root = root.as_bytes(); + if bytes.windows(root.len()).any(|window| window == root) { + panic!("found leaked {kind} path in {filename}"); + } + } + } } From cb3818e338b662ebe1a36750c05ba2bbbeab793e Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Thu, 13 Aug 2026 08:20:05 -0400 Subject: [PATCH 4/5] tests: switch remap prefix expectation to `/cargo/registry` Registry dependencies are now remapped by cargo trim-paths as `/cargo/registry/{source-hash}/{pkg}-{ver}/` --- tests/run-make/remap-path-prefix-std/rmake.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run-make/remap-path-prefix-std/rmake.rs b/tests/run-make/remap-path-prefix-std/rmake.rs index 4f101efc486b3..d61883de2f9f1 100644 --- a/tests/run-make/remap-path-prefix-std/rmake.rs +++ b/tests/run-make/remap-path-prefix-std/rmake.rs @@ -93,7 +93,7 @@ fn main() { // Check that remapped paths are present if the rlib has debug info. if stdout.contains("DW_TAG_compile_unit") { assert!( - stdout.contains("/rustc/") || stdout.contains("/rust/deps"), + stdout.contains("/rustc/") || stdout.contains("/cargo/registry/"), "Expected remapped paths in dwarfdump output for {link_name}", ); } From 7d23b0e754fe0fc89919124d2db2a367c1e50cfc Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Fri, 14 Aug 2026 14:43:42 -0400 Subject: [PATCH 5/5] bootstrap: move debug-prefix-map C flags to LLVM CMake build The `-fdebug-prefix-map` flags in `cc_unhandled_cflags` served three kinds of consumers. * The cc-rs-driven C/C++ builds inside cargo: They now inherit the same remap pairs from cargo trim-paths so passing the flag through `CFLAGS` there is redundant. * The CMake-driven LLVM build: This is the one we need the remaps. * The remaining callers (`compiler_file` probing, cc detection, test fixtures): They never produce distributed artifacts. --- src/bootstrap/src/core/build_steps/compile.rs | 4 +- src/bootstrap/src/core/build_steps/llvm.rs | 30 +++++++-- src/bootstrap/src/core/build_steps/test.rs | 7 +- src/bootstrap/src/core/builder/cargo.rs | 21 ++---- src/bootstrap/src/core/session.rs | 67 ++++++------------- src/bootstrap/src/utils/cc_detect.rs | 7 +- 6 files changed, 59 insertions(+), 77 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index b475c9c81494c..0a03d63ad1c28 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -33,7 +33,7 @@ use crate::core::config::toml::target::DefaultLinuxLinkerOverride; use crate::core::config::{ Allocator, CompilerBuiltins, DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection, }; -use crate::core::session::{CLang, DependencyType, FileType, GitRepo, Mode}; +use crate::core::session::{CLang, DependencyType, FileType, Mode}; use crate::utils::build_stamp; use crate::utils::build_stamp::BuildStamp; use crate::utils::exec::command; @@ -1900,7 +1900,7 @@ pub fn compiler_file( } let mut cmd = command(compiler); cmd.args(builder.cc_handled_cflags(target, c)); - cmd.args(builder.cc_unhandled_cflags(target, GitRepo::Rustc, c)); + cmd.args(builder.cc_unhandled_cflags(target, c)); cmd.arg(format!("-print-file-name={file}")); let out = cmd.run_capture_stdout(builder).stdout(); PathBuf::from(out.trim()) diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 5d188bcd25570..e31252b86fb36 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -21,14 +21,13 @@ use crate::core::builder::{ Builder, CommandLineStep, Kind, RunConfig, ShouldRun, Step, StepMetadata, }; use crate::core::config::{Config, LlvmCiMode, LlvmPgoGenerationMode, TargetSelection}; -use crate::core::session::{CLang, GitRepo}; +use crate::core::session::CLang; use crate::trace; use crate::utils::build_stamp::{BuildStamp, generate_smart_stamp_hash}; use crate::utils::exec::command; use crate::utils::helpers::{ self, exe, get_clang_cl_resource_dir, libdir, t, unhashed_basename, up_to_date, }; - /// Path where a file containing the link type (dynamic or static) is stored in the LLVM CI tarball. pub const LLVM_CI_LINK_TYPE_PATH: &str = "link-type.txt"; @@ -782,6 +781,27 @@ fn check_llvm_version(builder: &Builder<'_>, llvm_config: &Path) { panic!("\n\nbad LLVM version: {version}, need >=21\n\n") } +/// C/C++ debug info remap flags for LLVM build. +/// +/// The remap is observable when LLVM is compiled with debug info, +/// for example, with `llvm.release-debuginfo = true`. +fn debuginfo_map_cflags(builder: &Builder<'_>, target: TargetSelection) -> Vec { + if !builder.config.rust_remap_debuginfo { + return Vec::new(); + } + + let mut flags = Vec::new(); + let map = format!("{}=/rustc/llvm", builder.src.display()); + let cc = builder.cc_tool(target); + if cc.is_like_clang() || cc.is_like_gnu() { + flags.push(format!("-fdebug-prefix-map={map}")); + } else if cc.is_like_clang_cl() { + flags.push("-Xclang".into()); + flags.push(format!("-fdebug-prefix-map={map}")); + } + flags +} + fn configure_cmake( builder: &Builder<'_>, target: TargetSelection, @@ -946,7 +966,8 @@ fn configure_cmake( for flag in builder .cc_handled_cflags(target, CLang::C) .into_iter() - .chain(builder.cc_unhandled_cflags(target, GitRepo::Llvm, CLang::C)) + .chain(builder.cc_unhandled_cflags(target, CLang::C)) + .chain(debuginfo_map_cflags(builder, target)) .filter(|flag| !suppressed_compiler_flag_prefixes.iter().any(|p| flag.starts_with(p))) { cflags.push(" "); @@ -967,7 +988,8 @@ fn configure_cmake( for flag in builder .cc_handled_cflags(target, CLang::Cxx) .into_iter() - .chain(builder.cc_unhandled_cflags(target, GitRepo::Llvm, CLang::Cxx)) + .chain(builder.cc_unhandled_cflags(target, CLang::Cxx)) + .chain(debuginfo_map_cflags(builder, target)) .filter(|flag| { !suppressed_compiler_flag_prefixes .iter() diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index e308801b2548f..e56e952330e63 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -38,7 +38,7 @@ use crate::core::builder::{ use crate::core::compiler::Compiler; use crate::core::config::TargetSelection; use crate::core::config::flags::{Subcommand, get_completion, top_level_help}; -use crate::core::session::{CLang, GitRepo, Mode}; +use crate::core::session::{CLang, Mode}; use crate::core::{android, debuggers}; use crate::utils::build_stamp::{self, BuildStamp}; use crate::utils::exec::{BootstrapCommand, command}; @@ -48,7 +48,6 @@ use crate::utils::helpers::{ target_supports_cranelift_backend, up_to_date, }; use crate::utils::render_tests::{add_flags_and_try_run_tests, try_run_tests}; - mod compiletest; pub mod failed_tests; @@ -2829,9 +2828,9 @@ Please disable assertions with `rust.debug-assertions = false`. // requires that a C++ compiler was configured which isn't always the case. if !builder.config.dry_run() && mode == CompiletestMode::RunMake { let mut cflags = builder.cc_handled_cflags(target, CLang::C); - cflags.extend(builder.cc_unhandled_cflags(target, GitRepo::Rustc, CLang::C)); + cflags.extend(builder.cc_unhandled_cflags(target, CLang::C)); let mut cxxflags = builder.cc_handled_cflags(target, CLang::Cxx); - cxxflags.extend(builder.cc_unhandled_cflags(target, GitRepo::Rustc, CLang::Cxx)); + cxxflags.extend(builder.cc_unhandled_cflags(target, CLang::Cxx)); cmd.arg("--cc") .arg(builder.cc(target)) .arg("--cxx") diff --git a/src/bootstrap/src/core/builder/cargo.rs b/src/bootstrap/src/core/builder/cargo.rs index 3651b6c263072..246991bdd2286 100644 --- a/src/bootstrap/src/core/builder/cargo.rs +++ b/src/bootstrap/src/core/builder/cargo.rs @@ -14,11 +14,10 @@ use crate::core::config::toml::pgo::PgoConfig; use crate::core::config::{ CompressDebuginfo, Config, DryRun, RustcLto, SplitDebuginfo, TargetSelection, }; -use crate::core::session::{CLang, GitRepo, Mode, RemapScheme}; +use crate::core::session::{CLang, Mode, RemapScheme}; use crate::utils::build_stamp; use crate::utils::exec::{BootstrapCommand, command}; use crate::utils::helpers::{self, LldThreads, check_cfg_arg, envify, linker_flags, t}; - /// Extra `--check-cfg` to add when building the compiler or tools /// (Mode restriction, config name, config values (if any)) #[expect(clippy::type_complexity)] // It's fine for hard-coded list and type is explained above. @@ -471,8 +470,7 @@ impl Cargo { // Extend `CXXFLAGS_$TARGET` with our extra flags. let env = format!("CFLAGS_{triple_underscored}"); - let mut cflags = - builder.cc_unhandled_cflags(target, GitRepo::Rustc, CLang::C).join(" "); + let mut cflags = builder.cc_unhandled_cflags(target, CLang::C).join(" "); if let Some(lto_cflag) = lto_cflag { cflags.push(' '); cflags.push_str(lto_cflag); @@ -496,8 +494,7 @@ impl Cargo { // Extend `CXXFLAGS_$TARGET` with our extra flags. let env = format!("CXXFLAGS_{triple_underscored}"); - let mut cxxflags = - builder.cc_unhandled_cflags(target, GitRepo::Rustc, CLang::Cxx).join(" "); + let mut cxxflags = builder.cc_unhandled_cflags(target, CLang::Cxx).join(" "); if let Some(lto_cflag) = lto_cflag { cxxflags.push(' '); cxxflags.push_str(lto_cflag); @@ -1170,16 +1167,12 @@ impl Builder<'_> { match mode { Mode::Rustc | Mode::Codegen => { - if let Some(ref map_to) = - self.build.debuginfo_map_to(GitRepo::Rustc, RemapScheme::NonCompiler) - { + if let Some(ref map_to) = self.build.debuginfo_map_to(RemapScheme::NonCompiler) { // Tell the compiler which prefix was used for remapping the standard library cargo.env("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR", map_to); } - if let Some(ref map_to) = - self.build.debuginfo_map_to(GitRepo::Rustc, RemapScheme::Compiler) - { + if let Some(ref map_to) = self.build.debuginfo_map_to(RemapScheme::Compiler) { // Tell the compiler which prefix was used for remapping the compiler it-self cargo.env("CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR", map_to); @@ -1191,9 +1184,7 @@ impl Builder<'_> { | Mode::ToolRustcPrivate | Mode::ToolStd | Mode::ToolTarget => { - if let Some(ref map_to) = - self.build.debuginfo_map_to(GitRepo::Rustc, RemapScheme::NonCompiler) - { + if let Some(ref map_to) = self.build.debuginfo_map_to(RemapScheme::NonCompiler) { trim_paths(&mut cargo, map_to); } } diff --git a/src/bootstrap/src/core/session.rs b/src/bootstrap/src/core/session.rs index 3e6668258c641..1fe6051f40828 100644 --- a/src/bootstrap/src/core/session.rs +++ b/src/bootstrap/src/core/session.rs @@ -29,11 +29,6 @@ use crate::utils::helpers::{ }; use crate::{debug, trace}; -pub(crate) enum GitRepo { - Rustc, - Llvm, -} - /// Global configuration for the build system. /// /// This structure transitively contains all configuration for the build system. @@ -995,38 +990,29 @@ impl Build { }) } - pub(crate) fn debuginfo_map_to( - &self, - which: GitRepo, - remap_scheme: RemapScheme, - ) -> Option { + pub(crate) fn debuginfo_map_to(&self, remap_scheme: RemapScheme) -> Option { if !self.config.rust_remap_debuginfo { return None; } - match which { - GitRepo::Rustc => { - let sha = self.rust_sha().unwrap_or(&self.version); - - match remap_scheme { - RemapScheme::Compiler => { - // For compiler sources, remap via `/rustc-dev/{sha}` to allow - // distinguishing between compiler sources vs library sources, since - // `rustc-dev` dist component places them under - // `$sysroot/lib/rustlib/rustc-src/rust` as opposed to `rust-src`'s - // `$sysroot/lib/rustlib/src/rust`. - // - // Keep this scheme in sync with `rustc_metadata::rmeta::decoder`'s - // `try_to_translate_virtual_to_real`. - Some(format!("/rustc-dev/{sha}")) - } - RemapScheme::NonCompiler => { - // For non-compiler sources, use `/rustc/{sha}` remapping scheme. - Some(format!("/rustc/{sha}")) - } - } + let sha = self.rust_sha().unwrap_or(&self.version); + + match remap_scheme { + RemapScheme::Compiler => { + // For compiler sources, remap via `/rustc-dev/{sha}` to allow + // distinguishing between compiler sources vs library sources, since + // `rustc-dev` dist component places them under + // `$sysroot/lib/rustlib/rustc-src/rust` as opposed to `rust-src`'s + // `$sysroot/lib/rustlib/src/rust`. + // + // Keep this scheme in sync with `rustc_metadata::rmeta::decoder`'s + // `try_to_translate_virtual_to_real`. + Some(format!("/rustc-dev/{sha}")) + } + RemapScheme::NonCompiler => { + // For non-compiler sources, use `/rustc/{sha}` remapping scheme. + Some(format!("/rustc/{sha}")) } - GitRepo::Llvm => Some(String::from("/rustc/llvm")), } } @@ -1069,12 +1055,7 @@ impl Build { } /// Returns extra C flags that `cc-rs` doesn't handle. - pub(crate) fn cc_unhandled_cflags( - &self, - target: TargetSelection, - which: GitRepo, - c: CLang, - ) -> Vec { + pub(crate) fn cc_unhandled_cflags(&self, target: TargetSelection, c: CLang) -> Vec { let mut base = Vec::new(); // If we're compiling C++ on macOS then we add a flag indicating that @@ -1091,16 +1072,6 @@ impl Build { base.push("-fno-omit-frame-pointer".into()); } - if let Some(map_to) = self.debuginfo_map_to(which, RemapScheme::NonCompiler) { - let map = format!("{}={}", self.src.display(), map_to); - let cc = self.cc_tool(target); - if cc.is_like_clang() || cc.is_like_gnu() { - base.push(format!("-fdebug-prefix-map={map}")); - } else if cc.is_like_clang_cl() { - base.push("-Xclang".into()); - base.push(format!("-fdebug-prefix-map={map}")); - } - } base } diff --git a/src/bootstrap/src/utils/cc_detect.rs b/src/bootstrap/src/utils/cc_detect.rs index e753ee71683fd..fc39523824f93 100644 --- a/src/bootstrap/src/utils/cc_detect.rs +++ b/src/bootstrap/src/utils/cc_detect.rs @@ -27,9 +27,8 @@ use std::path::{Path, PathBuf}; use crate::core::config::flags::Subcommand; use crate::core::config::{CompressDebuginfo, TargetSelection}; -use crate::core::session::{Build, CLang, GitRepo}; +use crate::core::session::{Build, CLang}; use crate::utils::exec::{BootstrapCommand, command}; - /// Creates and configures a new [`cc::Build`] instance for the given target. fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build { let mut cfg = cc::Build::new(); @@ -125,7 +124,7 @@ pub fn fill_target_compiler(build: &mut Build, target: TargetSelection) { build.cc.insert(target, compiler.clone()); let mut cflags = build.cc_handled_cflags(target, CLang::C); - cflags.extend(build.cc_unhandled_cflags(target, GitRepo::Rustc, CLang::C)); + cflags.extend(build.cc_unhandled_cflags(target, CLang::C)); // If we use llvm-libunwind, we will need a C++ compiler as well for all targets // We'll need one anyways if the target triple is also a host triple @@ -152,7 +151,7 @@ pub fn fill_target_compiler(build: &mut Build, target: TargetSelection) { build.do_if_verbose(|| println!("CFLAGS_{} = {cflags:?}", target.triple)); if let Ok(cxx) = build.cxx(target) { let mut cxxflags = build.cc_handled_cflags(target, CLang::Cxx); - cxxflags.extend(build.cc_unhandled_cflags(target, GitRepo::Rustc, CLang::Cxx)); + cxxflags.extend(build.cc_unhandled_cflags(target, CLang::Cxx)); build.do_if_verbose(|| println!("CXX_{} = {cxx:?}", target.triple)); build.do_if_verbose(|| println!("CXXFLAGS_{} = {cxxflags:?}", target.triple)); }