Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
9 changes: 0 additions & 9 deletions compiler/rustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
14 changes: 0 additions & 14 deletions src/bootstrap/src/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down
30 changes: 26 additions & 4 deletions src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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<String> {
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,
Expand Down Expand Up @@ -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(" ");
Expand All @@ -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()
Expand Down
7 changes: 3 additions & 4 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;

Expand Down Expand Up @@ -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")
Expand Down
87 changes: 15 additions & 72 deletions src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -1161,90 +1158,36 @@ 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) =
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);

// 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
| Mode::ToolBootstrap
| Mode::ToolRustcPrivate
| Mode::ToolStd
| Mode::ToolTarget => {
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"),

@Urgau Urgau Aug 15, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems like this remapping isn't done anymore.

$ rustc +62cf67c121864e5bfc57b32497dc24e22b7a91a0 diag.rs
error[E0277]: the trait bound `{integer}: AsRef<Path>` is not satisfied
 --> diag.rs:2:37
  |
2 |     let a = std::fs::read_to_string(12).unwrap();
  |             ----------------------- ^^ the trait `AsRef<Path>` is not implemented for `{integer}`
  |             |
  |             required by a bound introduced by this call
  |
note: required by a bound in `std::fs::read_to_string`
 --> library/std/src/fs.rs:383:0

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, we forgot library=<map_to>/library remap, which its relative form not covered by Cargo's <absolute-workspace-root>=<map_to>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, the same is probably also not done for compiler.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

// 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");
if let Some(ref map_to) = self.build.debuginfo_map_to(RemapScheme::NonCompiler) {
trim_paths(&mut cargo, map_to);
}
}
cargo.env("RUSTC_CARGO_REGISTRY_SRC_TO_REMAP", env_var);
}

// Enable usage of unstable features
Expand Down
67 changes: 19 additions & 48 deletions src/bootstrap/src/core/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -995,38 +990,29 @@ impl Build {
})
}

pub(crate) fn debuginfo_map_to(
&self,
which: GitRepo,
remap_scheme: RemapScheme,
) -> Option<String> {
pub(crate) fn debuginfo_map_to(&self, remap_scheme: RemapScheme) -> Option<String> {
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")),
}
}

Expand Down Expand Up @@ -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<String> {
pub(crate) fn cc_unhandled_cflags(&self, target: TargetSelection, c: CLang) -> Vec<String> {
let mut base = Vec::new();

// If we're compiling C++ on macOS then we add a flag indicating that
Expand All @@ -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
}

Expand Down
Loading
Loading