Skip to content

Commit

Permalink
fix: reorder --remap-path-prefix flags for -Zbuild-std
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
weihanglo committed Nov 28, 2023
1 parent d6b46bf commit 8709835
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 36 deletions.
6 changes: 4 additions & 2 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1214,8 +1214,6 @@ fn trim_paths_args(
}
remap
};
cmd.arg(sysroot_remap);

let package_remap = {
let pkg_root = unit.pkg.root();
let ws_root = cx.bcx.ws.root();
Expand All @@ -1242,7 +1240,11 @@ fn trim_paths_args(
}
remap
};

// 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`.
cmd.arg(package_remap);
cmd.arg(sysroot_remap);

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions tests/build-std/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ fn remap_path_scope() {
[..]thread '[..]' panicked at [..]src/main.rs:3:[..]",
)
.with_stderr_contains("remap to /rustc/<hash>")
.with_stderr_contains("[..]at std-0.0.0/src/[..]")
.with_stderr_contains("[..]at /rustc/[..]/library/std/src/[..]")
.with_stderr_contains("[..]at src/main.rs:3[..]")
.with_stderr_contains("[..]at core-0.0.0/src/[..]")
.with_stderr_contains("[..]at /rustc/[..]/library/core/src/[..]")
.run();
}
64 changes: 32 additions & 32 deletions tests/testsuite/profile_trim_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ fn release_profile_default_to_object() {
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc [..]\
-Zremap-path-scope=object \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
--remap-path-prefix=[CWD]= [..]
--remap-path-prefix=[CWD]= \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
[FINISHED] release [..]",
)
.run();
Expand Down Expand Up @@ -121,8 +121,8 @@ fn one_option() {
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc [..]\
-Zremap-path-scope={option} \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
--remap-path-prefix=[CWD]= [..]
--remap-path-prefix=[CWD]= \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
[FINISHED] dev [..]",
))
.run();
Expand Down Expand Up @@ -158,8 +158,8 @@ fn multiple_options() {
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc [..]\
-Zremap-path-scope=diagnostics,macro,object \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
--remap-path-prefix=[CWD]= [..]
--remap-path-prefix=[CWD]= \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
[FINISHED] dev [..]",
)
.run();
Expand Down Expand Up @@ -193,8 +193,8 @@ fn profile_merge_works() {
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc [..]\
-Zremap-path-scope=diagnostics \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
--remap-path-prefix=[CWD]= [..]
--remap-path-prefix=[CWD]= \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
[FINISHED] custom [..]",
)
.run();
Expand Down Expand Up @@ -238,13 +238,13 @@ fn registry_dependency() {
[COMPILING] bar v0.0.1
[RUNNING] `rustc [..]\
-Zremap-path-scope=object \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
--remap-path-prefix={pkg_remap} [..]
--remap-path-prefix={pkg_remap} \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc [..]\
-Zremap-path-scope=object \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
--remap-path-prefix=[CWD]= [..]
--remap-path-prefix=[CWD]= \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
[FINISHED] dev [..]
[RUNNING] `target/debug/foo[EXE]`"
))
Expand Down Expand Up @@ -292,13 +292,13 @@ fn git_dependency() {
[COMPILING] bar v0.0.1 ({url}[..])
[RUNNING] `rustc [..]\
-Zremap-path-scope=object \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
--remap-path-prefix={pkg_remap} [..]
--remap-path-prefix={pkg_remap} \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc [..]\
-Zremap-path-scope=object \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
--remap-path-prefix=[CWD]= [..]
--remap-path-prefix=[CWD]= \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
[FINISHED] dev [..]
[RUNNING] `target/debug/foo[EXE]`"
))
Expand Down Expand Up @@ -338,13 +338,13 @@ fn path_dependency() {
[COMPILING] bar v0.0.1 ([..]/cocktail-bar)
[RUNNING] `rustc [..]\
-Zremap-path-scope=object \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
--remap-path-prefix=[CWD]= [..]
--remap-path-prefix=[CWD]= \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc [..]\
-Zremap-path-scope=object \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
--remap-path-prefix=[CWD]= [..]
--remap-path-prefix=[CWD]= \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
[FINISHED] dev [..]
[RUNNING] `target/debug/foo[EXE]`"
))
Expand Down Expand Up @@ -387,13 +387,13 @@ fn path_dependency_outside_workspace() {
[COMPILING] bar v0.0.1 ([..]/bar)
[RUNNING] `rustc [..]\
-Zremap-path-scope=object \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
--remap-path-prefix={bar_path}=bar-0.0.1 [..]
--remap-path-prefix={bar_path}=bar-0.0.1 \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc [..]\
-Zremap-path-scope=object \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
--remap-path-prefix=[CWD]= [..]
--remap-path-prefix=[CWD]= \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
[FINISHED] dev [..]
[RUNNING] `target/debug/foo[EXE]`"
))
Expand Down Expand Up @@ -439,15 +439,15 @@ fn diagnostics_works() {
"\
[RUNNING] [..]rustc [..]\
-Zremap-path-scope=diagnostics \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
--remap-path-prefix={pkg_remap} [..]",
--remap-path-prefix={pkg_remap} \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]",
))
.with_stderr_contains(
"\
[RUNNING] [..]rustc [..]\
-Zremap-path-scope=diagnostics \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
--remap-path-prefix=[CWD]= [..]",
--remap-path-prefix=[CWD]= \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]",
)
.run();
}
Expand Down Expand Up @@ -528,13 +528,13 @@ fn object_works() {
[COMPILING] bar v0.0.1
[RUNNING] `rustc [..]\
-Zremap-path-scope=object \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
--remap-path-prefix={pkg_remap} [..]
--remap-path-prefix={pkg_remap} \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc [..]\
-Zremap-path-scope=object \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
--remap-path-prefix=[CWD]= [..]
--remap-path-prefix=[CWD]= \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
[FINISHED] dev [..]",
))
.run();
Expand Down

0 comments on commit 8709835

Please sign in to comment.