Skip to content

Commit e23bdd9

Browse files
committed
Auto merge of #161049 - weihanglo:bootstrap-trim-paths-exp, r=<try>
[experiment] bootstrap: leverage cargo trim-paths
2 parents 1e5ee35 + b0b31e6 commit e23bdd9

3 files changed

Lines changed: 557 additions & 661 deletions

File tree

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

Lines changed: 9 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,9 +1107,13 @@ impl Builder<'_> {
11071107
//
11081108
// Keep this scheme in sync with `rustc_metadata::rmeta::decoder`'s
11091109
// `try_to_translate_virtual_to_real`.
1110-
//
1111-
// `RUSTC_DEBUGINFO_MAP` is used to pass through to the underlying rustc
1112-
// `--remap-path-prefix`.
1110+
let trim_paths = |cargo: &mut BootstrapCommand, ws_remap: &str| {
1111+
cargo.arg("-Ztrim-paths");
1112+
cargo.env("CARGO_PROFILE_RELEASE_TRIM_PATHS", "object");
1113+
cargo.env("CARGO_PROFILE_DEV_TRIM_PATHS", "object");
1114+
cargo.env("__CARGO_RUSTC_BOOTSTRAP_WS_REMAP", ws_remap);
1115+
};
1116+
11131117
match mode {
11141118
Mode::Rustc | Mode::Codegen => {
11151119
if let Some(ref map_to) =
@@ -1125,24 +1129,7 @@ impl Builder<'_> {
11251129
// Tell the compiler which prefix was used for remapping the compiler it-self
11261130
cargo.env("CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR", map_to);
11271131

1128-
// When building compiler sources, we want to apply the compiler remap scheme.
1129-
let map = [
1130-
// Cargo use relative paths for workspace members, so let's remap those.
1131-
format!("compiler/={map_to}/compiler"),
1132-
// rustc creates absolute paths (in part bc of the `rust-src` unremap
1133-
// and for working directory) so let's remap the build directory as well.
1134-
format!("{}={map_to}", self.build.src.display()),
1135-
// remap OUT_DIR so they don't leak into artifacts.
1136-
format!("{}={map_to}/out", self.build.out.display()),
1137-
// on windows, rustc may use forward slashes internally
1138-
#[cfg(windows)]
1139-
format!(
1140-
"{}={map_to}\\out",
1141-
self.build.out.display().to_string().replace('/', "\\")
1142-
),
1143-
]
1144-
.join("\t");
1145-
cargo.env("RUSTC_DEBUGINFO_MAP", map);
1132+
trim_paths(&mut cargo, map_to);
11461133
}
11471134
}
11481135
Mode::Std
@@ -1153,44 +1140,9 @@ impl Builder<'_> {
11531140
if let Some(ref map_to) =
11541141
self.build.debuginfo_map_to(GitRepo::Rustc, RemapScheme::NonCompiler)
11551142
{
1156-
// When building the standard library sources, we want to apply the std remap scheme.
1157-
let map = [
1158-
// Cargo use relative paths for workspace members, so let's remap those.
1159-
format!("library/={map_to}/library"),
1160-
// rustc creates absolute paths (in part bc of the `rust-src` unremap
1161-
// and for working directory) so let's remap the build directory as well.
1162-
format!("{}={map_to}", self.build.src.display()),
1163-
// remap OUT_DIR so they don't leak into artifacts.
1164-
format!("{}={map_to}/out", self.build.out.display()),
1165-
// on windows, rustc may use forward slashes internally
1166-
#[cfg(windows)]
1167-
format!(
1168-
"{}={map_to}\\out",
1169-
self.build.out.display().to_string().replace('/', "\\")
1170-
),
1171-
]
1172-
.join("\t");
1173-
cargo.env("RUSTC_DEBUGINFO_MAP", map);
1174-
}
1175-
}
1176-
}
1177-
1178-
if self.config.rust_remap_debuginfo {
1179-
let mut env_var = OsString::new();
1180-
if let Some(vendor) = self.build.vendored_crates_path() {
1181-
env_var.push(vendor);
1182-
env_var.push("=/rust/deps");
1183-
} else {
1184-
let registry_src = t!(home::cargo_home()).join("registry").join("src");
1185-
for entry in t!(std::fs::read_dir(registry_src)) {
1186-
if !env_var.is_empty() {
1187-
env_var.push("\t");
1188-
}
1189-
env_var.push(t!(entry).path());
1190-
env_var.push("=/rust/deps");
1143+
trim_paths(&mut cargo, map_to);
11911144
}
11921145
}
1193-
cargo.env("RUSTC_CARGO_REGISTRY_SRC_TO_REMAP", env_var);
11941146
}
11951147

11961148
// Enable usage of unstable features

0 commit comments

Comments
 (0)