Skip to content

Commit 2f74b54

Browse files
authored
refactor: use Path::push to construct remap-path-prefix (#14908)
### What does this PR try to resolve? It creates paths with correct separators for different systems. ### How should we test and review this PR? Try out `-Ztrim-paths` on Windows. Run `cargo build --verbose` and see if slashes in `--remap-path-prefix` use the system's path separators. ```toml cargo-features = ["trim-paths"] [package] name = "foo" [profile.release]trim-paths = true ``` ### Additional information
2 parents bcc217d + 4661f9b commit 2f74b54

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/cargo/core/compiler/mod.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1310,10 +1310,16 @@ fn trim_paths_args(
13101310
/// This remap logic aligns with rustc:
13111311
/// <https://github.com/rust-lang/rust/blob/c2ef3516/src/bootstrap/src/lib.rs#L1113-L1116>
13121312
fn sysroot_remap(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> OsString {
1313-
let sysroot = &build_runner.bcx.target_data.info(unit.kind).sysroot;
13141313
let mut remap = OsString::from("--remap-path-prefix=");
1315-
remap.push(sysroot);
1316-
remap.push("/lib/rustlib/src/rust"); // See also `detect_sysroot_src_path()`.
1314+
remap.push({
1315+
// See also `detect_sysroot_src_path()`.
1316+
let mut sysroot = build_runner.bcx.target_data.info(unit.kind).sysroot.clone();
1317+
sysroot.push("lib");
1318+
sysroot.push("rustlib");
1319+
sysroot.push("src");
1320+
sysroot.push("rust");
1321+
sysroot
1322+
});
13171323
remap.push("=");
13181324
remap.push("/rustc/");
13191325
if let Some(commit_hash) = build_runner.bcx.rustc().commit_hash.as_ref() {

0 commit comments

Comments
 (0)