From d6b46bfd373663cff064b45ec0fad7e8ed566f6b Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Tue, 28 Nov 2023 14:57:34 -0500 Subject: [PATCH 1/2] test(trim-paths): demonstrate not work properly with `-Zbuild-std` --- tests/build-std/main.rs | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/build-std/main.rs b/tests/build-std/main.rs index 9eb69bb56e1..94a472725b7 100644 --- a/tests/build-std/main.rs +++ b/tests/build-std/main.rs @@ -229,3 +229,46 @@ fn custom_test_framework() { .build_std_arg("core") .run(); } + +// Fixing rust-lang/rust#117839. +// on macOS it never gets remapped. +// Might be a separate issue, so only run on Linux. +#[cargo_test(build_std_real)] +#[cfg(target_os = "linux")] +fn remap_path_scope() { + let p = project() + .file( + "src/main.rs", + " + fn main() { + panic!(\"remap to /rustc/\"); + } + ", + ) + .file( + ".cargo/config.toml", + " + [profile.release] + debug = \"line-tables-only\" + ", + ) + .build(); + + p.cargo("run --release -Ztrim-paths") + .masquerade_as_nightly_cargo(&["-Ztrim-paths"]) + .env("RUST_BACKTRACE", "1") + .build_std() + .target_host() + .with_status(101) + .with_stderr_contains( + "\ +[FINISHED] release [optimized + debuginfo] [..] +[RUNNING] [..] +[..]thread '[..]' panicked at [..]src/main.rs:3:[..]", + ) + .with_stderr_contains("remap to /rustc/") + .with_stderr_contains("[..]at std-0.0.0/src/[..]") + .with_stderr_contains("[..]at src/main.rs:3[..]") + .with_stderr_contains("[..]at core-0.0.0/src/[..]") + .run(); +} From 8709835a01aef9f5b7b4f49b3566288da93f68cf Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Tue, 28 Nov 2023 13:47:44 -0500 Subject: [PATCH 2/2] fix: reorder `--remap-path-prefix` flags for `-Zbuild-std` Order of `--remap-path-prefix` flags is important for `-Zbuild-std`. We want to show `/rustc//library/std` instead of `std-0.0.0`. --- src/cargo/core/compiler/mod.rs | 6 ++- tests/build-std/main.rs | 4 +- tests/testsuite/profile_trim_paths.rs | 64 +++++++++++++-------------- 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 0801783dc7b..e80be76ae95 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -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(); @@ -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//library/std` instead of `std-0.0.0`. cmd.arg(package_remap); + cmd.arg(sysroot_remap); Ok(()) } diff --git a/tests/build-std/main.rs b/tests/build-std/main.rs index 94a472725b7..c905deb4950 100644 --- a/tests/build-std/main.rs +++ b/tests/build-std/main.rs @@ -267,8 +267,8 @@ fn remap_path_scope() { [..]thread '[..]' panicked at [..]src/main.rs:3:[..]", ) .with_stderr_contains("remap to /rustc/") - .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(); } diff --git a/tests/testsuite/profile_trim_paths.rs b/tests/testsuite/profile_trim_paths.rs index 1d24c159be7..a682de93980 100644 --- a/tests/testsuite/profile_trim_paths.rs +++ b/tests/testsuite/profile_trim_paths.rs @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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]`" )) @@ -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]`" )) @@ -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]`" )) @@ -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]`" )) @@ -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(); } @@ -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();