From 4661f9b924762dbfbe2b74fd2bc41f428838ebe2 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Sun, 8 Dec 2024 19:03:16 -0500 Subject: [PATCH] refactor: use Path::push to construct remap-path-prefix It creates paths with correct separators for different systems. --- src/cargo/core/compiler/mod.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 406280c6dbd..5dc34616d91 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -1310,10 +1310,16 @@ fn trim_paths_args( /// This remap logic aligns with rustc: /// fn sysroot_remap(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> OsString { - let sysroot = &build_runner.bcx.target_data.info(unit.kind).sysroot; let mut remap = OsString::from("--remap-path-prefix="); - remap.push(sysroot); - remap.push("/lib/rustlib/src/rust"); // See also `detect_sysroot_src_path()`. + remap.push({ + // See also `detect_sysroot_src_path()`. + let mut sysroot = build_runner.bcx.target_data.info(unit.kind).sysroot.clone(); + sysroot.push("lib"); + sysroot.push("rustlib"); + sysroot.push("src"); + sysroot.push("rust"); + sysroot + }); remap.push("="); remap.push("/rustc/"); if let Some(commit_hash) = build_runner.bcx.rustc().commit_hash.as_ref() {