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
23 changes: 15 additions & 8 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -543,13 +543,14 @@ version = "0.1.0"

[[package]]
name = "cc"
version = "1.2.16"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be714c154be609ec7f5dad223a33bf1482fff90472de28f7362806e6d4832b8c"
checksum = "5d262e149917187838d5b42777c8253bcb64500067342904e7d429499a6f277e"
dependencies = [
"find-msvc-tools",
"jobserver",
"libc",
"shlex",
"shlex 2.0.1",
]

[[package]]
Expand Down Expand Up @@ -1437,9 +1438,9 @@ dependencies = [

[[package]]
name = "find-msvc-tools"
version = "0.1.5"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844"
checksum = "26b73573e6edcd2af0cdf47bd6cb58f0b3839491263c314eaad1ccf24430e1de"

[[package]]
name = "flate2"
Expand Down Expand Up @@ -2222,7 +2223,7 @@ dependencies = [
"jsonpath-rust",
"regex",
"serde_json",
"shlex",
"shlex 1.3.0",
]

[[package]]
Expand Down Expand Up @@ -3995,7 +3996,7 @@ dependencies = [
"rustc_span",
"rustc_target",
"serde_json",
"shlex",
"shlex 1.3.0",
"tracing",
"windows 0.61.3",
]
Expand Down Expand Up @@ -4361,7 +4362,7 @@ version = "0.0.0"
dependencies = [
"cc",
"libc",
"shlex",
"shlex 1.3.0",
]

[[package]]
Expand Down Expand Up @@ -5374,6 +5375,12 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"

[[package]]
name = "shlex"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"

[[package]]
name = "simd-adler32"
version = "0.3.7"
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_llvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ libc = "0.2.73"
[build-dependencies]
# tidy-alphabetical-start
# `cc` updates often break things, so we pin it here.
cc = "=1.2.16"
cc = "=1.4.2"
shlex = "1.3.0"
# tidy-alphabetical-end

Expand Down
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
15 changes: 11 additions & 4 deletions library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ dependencies = [

[[package]]
name = "cc"
version = "1.2.0"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aeb932158bd710538c73702db6945cb68a8fb08c519e6e12706b94263b36db8"
checksum = "5d262e149917187838d5b42777c8253bcb64500067342904e7d429499a6f277e"
dependencies = [
"find-msvc-tools",
"shlex",
]

Expand Down Expand Up @@ -88,6 +89,12 @@ dependencies = [
"windows-sys",
]

[[package]]
name = "find-msvc-tools"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d45db016d36b838f563236e9193d0ee6ce38f3f68b6c94e914b4929c96bbb890"

[[package]]
name = "foldhash"
version = "0.2.0"
Expand Down Expand Up @@ -314,9 +321,9 @@ dependencies = [

[[package]]
name = "shlex"
version = "1.3.0"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"

[[package]]
name = "std"
Expand Down
2 changes: 1 addition & 1 deletion library/profiler_builtins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ doc = false

[build-dependencies]
# Pinned so `cargo update` bumps don't cause breakage
cc = "=1.2.0"
cc = "=1.4.2"
14 changes: 0 additions & 14 deletions src/bootstrap/src/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,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
5 changes: 2 additions & 3 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ use crate::utils::helpers::{
self, exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, symlink_dir, t, up_to_date,
};
use crate::{
CLang, CodegenBackendKind, Compiler, DependencyType, FileType, GitRepo, LLVM_TOOLS, Mode,
debug, trace,
CLang, CodegenBackendKind, Compiler, DependencyType, FileType, LLVM_TOOLS, Mode, debug, trace,
};

/// Build a standard library for the given `target` using the given `build_compiler`.
Expand Down Expand Up @@ -1898,7 +1897,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
29 changes: 26 additions & 3 deletions src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::utils::exec::command;
use crate::utils::helpers::{
self, exe, get_clang_cl_resource_dir, libdir, t, unhashed_basename, up_to_date,
};
use crate::{CLang, GitRepo, trace};
use crate::{CLang, trace};

/// Result of building or downloading LLVM artifacts.
#[derive(Clone)]
Expand Down Expand Up @@ -663,6 +663,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 @@ -827,7 +848,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 @@ -848,7 +870,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
6 changes: 3 additions & 3 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use crate::utils::helpers::{
up_to_date,
};
use crate::utils::render_tests::{add_flags_and_try_run_tests, try_run_tests};
use crate::{CLang, CodegenBackendKind, GitRepo, Mode, TestTarget, envify};
use crate::{CLang, CodegenBackendKind, Mode, TestTarget, envify};

mod compiletest;
pub mod failed_tests;
Expand Down Expand Up @@ -2781,9 +2781,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
88 changes: 15 additions & 73 deletions src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ use crate::core::config::{CompressDebuginfo, Config, DryRun, SplitDebuginfo, Tar
use crate::utils::build_stamp;
use crate::utils::exec::{BootstrapCommand, command};
use crate::utils::helpers::{self, LldThreads, check_cfg_arg, linker_flags, t};
use crate::{
CLang, Compiler, EXTRA_CHECK_CFGS, GitRepo, Mode, RemapScheme, prepare_behaviour_dump_dir,
};
use crate::{CLang, Compiler, EXTRA_CHECK_CFGS, Mode, RemapScheme, prepare_behaviour_dump_dir};

/// Represents flag values in `String` form with a `\x1f` delimiter to pass to the compiler later.
///
Expand Down Expand Up @@ -431,8 +429,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 Ok(var) = std::env::var(&env) {
cflags.push(' ');
cflags.push_str(&var);
Expand All @@ -452,8 +449,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 Ok(var) = std::env::var(&env) {
cxxflags.push(' ');
cxxflags.push_str(&var);
Expand Down Expand Up @@ -1107,90 +1103,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
Loading
Loading