Skip to content

Commit 0e7ebb4

Browse files
committed
Auto merge of #150110 - Urgau:remap-relative-library, r=jieyouxu
Prefer remapping the relative `library/` and `compiler/` directories This is done to avoid leaking the relative paths to the standard library after the overall of filenames in #149709. Noted that the paths were already leaking before, but to a lesser extent since most (but not all) the paths embedded in the distributed `rlib` were absolute. In general Cargo compiles workspace members with relative paths, so it's better anyway to remap the relative path. In addition to our tests I have manually confirmed that it also works as expected for the printed diagnostics paths. cf. https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/remapping.20of.20the.20standard.20library/near/564093571
2 parents 686f9ce + 74eecf9 commit 0e7ebb4

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,15 +1675,14 @@ impl<'a> CrateMetadataRef<'a> {
16751675
for virtual_dir in virtual_source_base_dir.iter().flatten() {
16761676
if let Some(real_dir) = &real_source_base_dir
16771677
&& let rustc_span::FileName::Real(old_name) = name
1678-
&& let (_working_dir, embeddable_name) =
1679-
old_name.embeddable_name(RemapPathScopeComponents::MACRO)
1680-
&& let Ok(rest) = embeddable_name.strip_prefix(virtual_dir)
1678+
&& let virtual_path = old_name.path(RemapPathScopeComponents::MACRO)
1679+
&& let Ok(rest) = virtual_path.strip_prefix(virtual_dir)
16811680
{
16821681
let new_path = real_dir.join(rest);
16831682

16841683
debug!(
16851684
"try_to_translate_virtual_to_real: `{}` -> `{}`",
1686-
embeddable_name.display(),
1685+
virtual_path.display(),
16871686
new_path.display(),
16881687
);
16891688

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,10 +1032,7 @@ impl Builder<'_> {
10321032
self.build.debuginfo_map_to(GitRepo::Rustc, RemapScheme::Compiler)
10331033
{
10341034
// When building compiler sources, we want to apply the compiler remap scheme.
1035-
cargo.env(
1036-
"RUSTC_DEBUGINFO_MAP",
1037-
format!("{}={}", self.build.src.display(), map_to),
1038-
);
1035+
cargo.env("RUSTC_DEBUGINFO_MAP", format!("compiler/={map_to}/compiler"));
10391036
cargo.env("CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR", map_to);
10401037
}
10411038
}
@@ -1047,10 +1044,7 @@ impl Builder<'_> {
10471044
if let Some(ref map_to) =
10481045
self.build.debuginfo_map_to(GitRepo::Rustc, RemapScheme::NonCompiler)
10491046
{
1050-
cargo.env(
1051-
"RUSTC_DEBUGINFO_MAP",
1052-
format!("{}={}", self.build.src.display(), map_to),
1053-
);
1047+
cargo.env("RUSTC_DEBUGINFO_MAP", format!("library/={map_to}/library"));
10541048
}
10551049
}
10561050
}

0 commit comments

Comments
 (0)