Skip to content

Commit 281629b

Browse files
committed
fix(trim-paths): remap all paths to build.build-dir
Remap all paths pointing to `build.build-dir`, i.e., `[BUILD_DIR]/debug/deps/foo-[HASH].dwo` would be remapped to `/cargo/build-dir/debug/deps/foo-[HASH].dwo` (note the `/cargo/build-dir` prefix). This covers scenarios like: * Build script generated code. For example, a build script may call `file!` macros, and the associated crate uses [`include!`] to include the expanded [`file!`] macro in-place via the `OUT_DIR` environment. * On Linux, `DW_AT_GNU_dwo_name` that contains paths to split debuginfo files (dwp and dwo).
1 parent 463e9ed commit 281629b

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,7 @@ fn trim_paths_args_rustdoc(
13931393
// Order of `--remap-path-prefix` flags is important for `-Zbuild-std`.
13941394
// We want to show `/rustc/<hash>/library/std` instead of `std-0.0.0`.
13951395
cmd.arg(package_remap(build_runner, unit));
1396+
cmd.arg(build_dir_remap(build_runner));
13961397
cmd.arg(sysroot_remap(build_runner, unit));
13971398

13981399
Ok(())
@@ -1420,6 +1421,7 @@ fn trim_paths_args(
14201421
// Order of `--remap-path-prefix` flags is important for `-Zbuild-std`.
14211422
// We want to show `/rustc/<hash>/library/std` instead of `std-0.0.0`.
14221423
cmd.arg(package_remap(build_runner, unit));
1424+
cmd.arg(build_dir_remap(build_runner));
14231425
cmd.arg(sysroot_remap(build_runner, unit));
14241426

14251427
Ok(())
@@ -1493,6 +1495,26 @@ fn package_remap(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> OsString {
14931495
remap
14941496
}
14951497

1498+
/// Remap all paths pointing to `build.build-dir`,
1499+
/// i.e., `[BUILD_DIR]/debug/deps/foo-[HASH].dwo` would be remapped to
1500+
/// `/cargo/build-dir/debug/deps/foo-[HASH].dwo`
1501+
/// (note the `/cargo/build-dir` prefix).
1502+
///
1503+
/// This covers scenarios like:
1504+
///
1505+
/// * Build script generated code. For example, a build script may call `file!`
1506+
/// macros, and the associated crate uses [`include!`] to include the expanded
1507+
/// [`file!`] macro in-place via the `OUT_DIR` environment.
1508+
/// * On Linux, `DW_AT_GNU_dwo_name` that contains paths to split debuginfo
1509+
/// files (dwp and dwo).
1510+
fn build_dir_remap(build_runner: &BuildRunner<'_, '_>) -> OsString {
1511+
let build_dir = build_runner.bcx.ws.build_dir();
1512+
let mut remap = OsString::from("--remap-path-prefix=");
1513+
remap.push(build_dir.as_path_unlocked());
1514+
remap.push("=/cargo/build-dir");
1515+
remap
1516+
}
1517+
14961518
/// Generates the `--check-cfg` arguments for the `unit`.
14971519
fn check_cfg_args(unit: &Unit) -> Vec<OsString> {
14981520
// The routine below generates the --check-cfg arguments. Our goals here are to

tests/testsuite/profile_trim_paths.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ fn registry_dependency_with_build_script_codegen() {
297297
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
298298
// Macros should be sanitized
299299
.with_stdout_data(str![[r#"
300-
[ROOT]/foo/target/debug/build/bar-[HASH]/out/bindings.rs
300+
/cargo/build-dir/debug/build/bar-[HASH]/out/bindings.rs
301301
302302
"#]]) // Omit the hash of Source URL
303303
.with_stderr_data(str![[r#"
@@ -308,7 +308,7 @@ fn registry_dependency_with_build_script_codegen() {
308308
[COMPILING] bar v0.0.1
309309
[RUNNING] `rustc --crate-name build_script_build [..]-Zremap-path-scope=object --remap-path-prefix=[ROOT]/home/.cargo/registry/src= --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]`
310310
[RUNNING] `[ROOT]/foo/target/debug/build/bar-[HASH]/build-script-build`
311-
[RUNNING] `rustc --crate-name bar [..]-Zremap-path-scope=object --remap-path-prefix=[ROOT]/home/.cargo/registry/src= --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]`
311+
[RUNNING] `rustc --crate-name bar [..]-Zremap-path-scope=object --remap-path-prefix=[ROOT]/home/.cargo/registry/src= --remap-path-prefix=[ROOT]/foo/target=/cargo/build-dir --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
312312
[COMPILING] foo v0.0.1 ([ROOT]/foo)
313313
[RUNNING] `rustc --crate-name foo [..]-Zremap-path-scope=object --remap-path-prefix=[ROOT]/foo=. --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]`
314314
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -694,15 +694,6 @@ fn object_works_helper(split_debuginfo: &str, run: impl Fn(&std::path::Path) ->
694694
}
695695
}
696696

697-
#[cfg(target_os = "linux")]
698-
{
699-
// To fix this, we should also remap build.build-dir.
700-
// See <https://github.com/rust-lang/cargo/pull/15610/commits/a55c7f88fb8d592d993740176da95fc5d1a362e0#r2119070640>
701-
if memchr::memmem::find(line, b"DW_AT_GNU_dwo_name").is_some() {
702-
continue;
703-
}
704-
}
705-
706697
panic!(
707698
"unexpected untrimmed symbol: {}",
708699
String::from_utf8(line.into()).unwrap()

0 commit comments

Comments
 (0)