Skip to content

Commit 07f1208

Browse files
committed
Auto merge of #13065 - weihanglo:remap-path-prefix-order, r=ehuss
fix: reorder `--remap-path-prefix` flags for `-Zbuild-std` ### What does this PR try to resolve? Order of `--remap-path-prefix` flags is important for `-Zbuild-std`. We want to show `/rustc/<hash>/library/std` instead of `std-0.0.0`. Fixes rust-lang/rust#117839 ### How should we test and review this PR? Follow the steps in rust-lang/rust#117839, or run ``` CARGO_RUN_BUILD_STD_TESTS=true cargo +nightly t --test build-std ``` to verify.
2 parents d5d9c35 + 8709835 commit 07f1208

File tree

3 files changed

+79
-34
lines changed

3 files changed

+79
-34
lines changed

src/cargo/core/compiler/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1214,8 +1214,6 @@ fn trim_paths_args(
12141214
}
12151215
remap
12161216
};
1217-
cmd.arg(sysroot_remap);
1218-
12191217
let package_remap = {
12201218
let pkg_root = unit.pkg.root();
12211219
let ws_root = cx.bcx.ws.root();
@@ -1242,7 +1240,11 @@ fn trim_paths_args(
12421240
}
12431241
remap
12441242
};
1243+
1244+
// Order of `--remap-path-prefix` flags is important for `-Zbuild-std`.
1245+
// We want to show `/rustc/<hash>/library/std` instead of `std-0.0.0`.
12451246
cmd.arg(package_remap);
1247+
cmd.arg(sysroot_remap);
12461248

12471249
Ok(())
12481250
}

tests/build-std/main.rs

+43
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,46 @@ fn custom_test_framework() {
229229
.build_std_arg("core")
230230
.run();
231231
}
232+
233+
// Fixing rust-lang/rust#117839.
234+
// on macOS it never gets remapped.
235+
// Might be a separate issue, so only run on Linux.
236+
#[cargo_test(build_std_real)]
237+
#[cfg(target_os = "linux")]
238+
fn remap_path_scope() {
239+
let p = project()
240+
.file(
241+
"src/main.rs",
242+
"
243+
fn main() {
244+
panic!(\"remap to /rustc/<hash>\");
245+
}
246+
",
247+
)
248+
.file(
249+
".cargo/config.toml",
250+
"
251+
[profile.release]
252+
debug = \"line-tables-only\"
253+
",
254+
)
255+
.build();
256+
257+
p.cargo("run --release -Ztrim-paths")
258+
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
259+
.env("RUST_BACKTRACE", "1")
260+
.build_std()
261+
.target_host()
262+
.with_status(101)
263+
.with_stderr_contains(
264+
"\
265+
[FINISHED] release [optimized + debuginfo] [..]
266+
[RUNNING] [..]
267+
[..]thread '[..]' panicked at [..]src/main.rs:3:[..]",
268+
)
269+
.with_stderr_contains("remap to /rustc/<hash>")
270+
.with_stderr_contains("[..]at /rustc/[..]/library/std/src/[..]")
271+
.with_stderr_contains("[..]at src/main.rs:3[..]")
272+
.with_stderr_contains("[..]at /rustc/[..]/library/core/src/[..]")
273+
.run();
274+
}

tests/testsuite/profile_trim_paths.rs

+32-32
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ fn release_profile_default_to_object() {
8383
[COMPILING] foo v0.0.1 ([CWD])
8484
[RUNNING] `rustc [..]\
8585
-Zremap-path-scope=object \
86-
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
87-
--remap-path-prefix=[CWD]= [..]
86+
--remap-path-prefix=[CWD]= \
87+
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
8888
[FINISHED] release [..]",
8989
)
9090
.run();
@@ -121,8 +121,8 @@ fn one_option() {
121121
[COMPILING] foo v0.0.1 ([CWD])
122122
[RUNNING] `rustc [..]\
123123
-Zremap-path-scope={option} \
124-
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
125-
--remap-path-prefix=[CWD]= [..]
124+
--remap-path-prefix=[CWD]= \
125+
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
126126
[FINISHED] dev [..]",
127127
))
128128
.run();
@@ -158,8 +158,8 @@ fn multiple_options() {
158158
[COMPILING] foo v0.0.1 ([CWD])
159159
[RUNNING] `rustc [..]\
160160
-Zremap-path-scope=diagnostics,macro,object \
161-
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
162-
--remap-path-prefix=[CWD]= [..]
161+
--remap-path-prefix=[CWD]= \
162+
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
163163
[FINISHED] dev [..]",
164164
)
165165
.run();
@@ -193,8 +193,8 @@ fn profile_merge_works() {
193193
[COMPILING] foo v0.0.1 ([CWD])
194194
[RUNNING] `rustc [..]\
195195
-Zremap-path-scope=diagnostics \
196-
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
197-
--remap-path-prefix=[CWD]= [..]
196+
--remap-path-prefix=[CWD]= \
197+
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
198198
[FINISHED] custom [..]",
199199
)
200200
.run();
@@ -238,13 +238,13 @@ fn registry_dependency() {
238238
[COMPILING] bar v0.0.1
239239
[RUNNING] `rustc [..]\
240240
-Zremap-path-scope=object \
241-
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
242-
--remap-path-prefix={pkg_remap} [..]
241+
--remap-path-prefix={pkg_remap} \
242+
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
243243
[COMPILING] foo v0.0.1 ([CWD])
244244
[RUNNING] `rustc [..]\
245245
-Zremap-path-scope=object \
246-
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
247-
--remap-path-prefix=[CWD]= [..]
246+
--remap-path-prefix=[CWD]= \
247+
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
248248
[FINISHED] dev [..]
249249
[RUNNING] `target/debug/foo[EXE]`"
250250
))
@@ -292,13 +292,13 @@ fn git_dependency() {
292292
[COMPILING] bar v0.0.1 ({url}[..])
293293
[RUNNING] `rustc [..]\
294294
-Zremap-path-scope=object \
295-
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
296-
--remap-path-prefix={pkg_remap} [..]
295+
--remap-path-prefix={pkg_remap} \
296+
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
297297
[COMPILING] foo v0.0.1 ([CWD])
298298
[RUNNING] `rustc [..]\
299299
-Zremap-path-scope=object \
300-
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
301-
--remap-path-prefix=[CWD]= [..]
300+
--remap-path-prefix=[CWD]= \
301+
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
302302
[FINISHED] dev [..]
303303
[RUNNING] `target/debug/foo[EXE]`"
304304
))
@@ -338,13 +338,13 @@ fn path_dependency() {
338338
[COMPILING] bar v0.0.1 ([..]/cocktail-bar)
339339
[RUNNING] `rustc [..]\
340340
-Zremap-path-scope=object \
341-
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
342-
--remap-path-prefix=[CWD]= [..]
341+
--remap-path-prefix=[CWD]= \
342+
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
343343
[COMPILING] foo v0.0.1 ([CWD])
344344
[RUNNING] `rustc [..]\
345345
-Zremap-path-scope=object \
346-
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
347-
--remap-path-prefix=[CWD]= [..]
346+
--remap-path-prefix=[CWD]= \
347+
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
348348
[FINISHED] dev [..]
349349
[RUNNING] `target/debug/foo[EXE]`"
350350
))
@@ -387,13 +387,13 @@ fn path_dependency_outside_workspace() {
387387
[COMPILING] bar v0.0.1 ([..]/bar)
388388
[RUNNING] `rustc [..]\
389389
-Zremap-path-scope=object \
390-
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
391-
--remap-path-prefix={bar_path}=bar-0.0.1 [..]
390+
--remap-path-prefix={bar_path}=bar-0.0.1 \
391+
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
392392
[COMPILING] foo v0.0.1 ([CWD])
393393
[RUNNING] `rustc [..]\
394394
-Zremap-path-scope=object \
395-
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
396-
--remap-path-prefix=[CWD]= [..]
395+
--remap-path-prefix=[CWD]= \
396+
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
397397
[FINISHED] dev [..]
398398
[RUNNING] `target/debug/foo[EXE]`"
399399
))
@@ -439,15 +439,15 @@ fn diagnostics_works() {
439439
"\
440440
[RUNNING] [..]rustc [..]\
441441
-Zremap-path-scope=diagnostics \
442-
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
443-
--remap-path-prefix={pkg_remap} [..]",
442+
--remap-path-prefix={pkg_remap} \
443+
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]",
444444
))
445445
.with_stderr_contains(
446446
"\
447447
[RUNNING] [..]rustc [..]\
448448
-Zremap-path-scope=diagnostics \
449-
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
450-
--remap-path-prefix=[CWD]= [..]",
449+
--remap-path-prefix=[CWD]= \
450+
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]",
451451
)
452452
.run();
453453
}
@@ -528,13 +528,13 @@ fn object_works() {
528528
[COMPILING] bar v0.0.1
529529
[RUNNING] `rustc [..]\
530530
-Zremap-path-scope=object \
531-
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
532-
--remap-path-prefix={pkg_remap} [..]
531+
--remap-path-prefix={pkg_remap} \
532+
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
533533
[COMPILING] foo v0.0.1 ([CWD])
534534
[RUNNING] `rustc [..]\
535535
-Zremap-path-scope=object \
536-
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
537-
--remap-path-prefix=[CWD]= [..]
536+
--remap-path-prefix=[CWD]= \
537+
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
538538
[FINISHED] dev [..]",
539539
))
540540
.run();

0 commit comments

Comments
 (0)