2023-09-01 16:14:25 +00:00
|
|
|
//! Tests for `-Ztrim-paths`.
|
|
|
|
|
2023-10-25 01:34:16 +00:00
|
|
|
use cargo_test_support::basic_manifest;
|
|
|
|
use cargo_test_support::git;
|
|
|
|
use cargo_test_support::paths;
|
2023-09-01 16:14:25 +00:00
|
|
|
use cargo_test_support::project;
|
2023-10-25 01:34:16 +00:00
|
|
|
use cargo_test_support::registry::Package;
|
2023-09-01 16:14:25 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn gated_manifest() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[profile.dev]
|
|
|
|
trim-paths = "macro"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check")
|
|
|
|
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains(
|
|
|
|
"\
|
|
|
|
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
|
|
|
|
|
|
|
|
Caused by:
|
|
|
|
feature `trim-paths` is required",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn gated_config_toml() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
".cargo/config.toml",
|
|
|
|
r#"
|
|
|
|
[profile.dev]
|
|
|
|
trim-paths = "macro"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check")
|
|
|
|
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains(
|
|
|
|
"\
|
|
|
|
[ERROR] config profile `dev` is not valid (defined in `[CWD]/.cargo/config.toml`)
|
|
|
|
|
|
|
|
Caused by:
|
|
|
|
feature `trim-paths` is required",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
2023-10-25 01:34:16 +00:00
|
|
|
|
|
|
|
#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")]
|
|
|
|
fn release_profile_default_to_object() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("build --release --verbose -Ztrim-paths")
|
|
|
|
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
|
2023-09-06 13:59:01 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
|
|
|
[RUNNING] `rustc [..]\
|
|
|
|
-Zremap-path-scope=object \
|
fix(trim-paths): explicit remap to current dir `.`
In https://github.com/rust-lang/rust/blob/87e1447aa/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs#L856
when the remap result of `work_dir` is an empty string,
LLVM won't generate some symbols for root debuginfo node.
For example, `N_SO` and `N_OSO` on macOS,
or `DW_AT_comp_dir` on Linux when debuginfo is splitted.
Precisely, it is observed that when the `DIFile` of compile unit was
provied with an empty compilation `Directory` string,
LLVM would not emit those symbols for the root DI node.
This behavior is not desired,
resulting in corrupted debuginfo and degrading debugging experience.
This is might not be a bug of `--remap-path-prefix` in rustc,
since `-fdebug-prefix-map` in clang 16 could have the same result
(`DW_AT_comp_dir` is gone when `work_dir` is remapped to an empty string).
However, in gcc 12 `fdebug-prefix-map` will return an absolute work_dir
when an empty string occurs.
To not bother whether this needs to be fixed in rustc or not,
let's fix it by always appending an explicit `.`
when `--remap-path-prefix` remaps to relative workspace root
a.k.a. where rustc is invoking.
For more on gcc/clang remap options, see
https://reproducible-builds.org/docs/build-path/
2023-12-08 18:52:40 +00:00
|
|
|
--remap-path-prefix=[CWD]=. \
|
2023-11-28 18:47:44 +00:00
|
|
|
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
|
2023-09-06 13:59:01 +00:00
|
|
|
[FINISHED] release [..]",
|
|
|
|
)
|
2023-10-25 01:34:16 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")]
|
|
|
|
fn one_option() {
|
|
|
|
let build = |option| {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[profile.dev]
|
|
|
|
trim-paths = "{option}"
|
|
|
|
"#
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("build -v -Ztrim-paths")
|
|
|
|
};
|
|
|
|
|
|
|
|
for option in ["macro", "diagnostics", "object", "all"] {
|
|
|
|
build(option)
|
|
|
|
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
|
2023-09-06 13:59:01 +00:00
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
|
|
|
[RUNNING] `rustc [..]\
|
|
|
|
-Zremap-path-scope={option} \
|
fix(trim-paths): explicit remap to current dir `.`
In https://github.com/rust-lang/rust/blob/87e1447aa/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs#L856
when the remap result of `work_dir` is an empty string,
LLVM won't generate some symbols for root debuginfo node.
For example, `N_SO` and `N_OSO` on macOS,
or `DW_AT_comp_dir` on Linux when debuginfo is splitted.
Precisely, it is observed that when the `DIFile` of compile unit was
provied with an empty compilation `Directory` string,
LLVM would not emit those symbols for the root DI node.
This behavior is not desired,
resulting in corrupted debuginfo and degrading debugging experience.
This is might not be a bug of `--remap-path-prefix` in rustc,
since `-fdebug-prefix-map` in clang 16 could have the same result
(`DW_AT_comp_dir` is gone when `work_dir` is remapped to an empty string).
However, in gcc 12 `fdebug-prefix-map` will return an absolute work_dir
when an empty string occurs.
To not bother whether this needs to be fixed in rustc or not,
let's fix it by always appending an explicit `.`
when `--remap-path-prefix` remaps to relative workspace root
a.k.a. where rustc is invoking.
For more on gcc/clang remap options, see
https://reproducible-builds.org/docs/build-path/
2023-12-08 18:52:40 +00:00
|
|
|
--remap-path-prefix=[CWD]=. \
|
2023-11-28 18:47:44 +00:00
|
|
|
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
|
2023-09-06 13:59:01 +00:00
|
|
|
[FINISHED] dev [..]",
|
|
|
|
))
|
2023-10-25 01:34:16 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
build("none")
|
|
|
|
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
|
|
|
|
.with_stderr_does_not_contain("[..]-Zremap-path-scope=[..]")
|
|
|
|
.with_stderr_does_not_contain("[..]--remap-path-prefix=[..]")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")]
|
|
|
|
fn multiple_options() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[profile.dev]
|
|
|
|
trim-paths = ["diagnostics", "macro", "object"]
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("build --verbose -Ztrim-paths")
|
|
|
|
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
|
2023-09-06 13:59:01 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
|
|
|
[RUNNING] `rustc [..]\
|
|
|
|
-Zremap-path-scope=diagnostics,macro,object \
|
fix(trim-paths): explicit remap to current dir `.`
In https://github.com/rust-lang/rust/blob/87e1447aa/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs#L856
when the remap result of `work_dir` is an empty string,
LLVM won't generate some symbols for root debuginfo node.
For example, `N_SO` and `N_OSO` on macOS,
or `DW_AT_comp_dir` on Linux when debuginfo is splitted.
Precisely, it is observed that when the `DIFile` of compile unit was
provied with an empty compilation `Directory` string,
LLVM would not emit those symbols for the root DI node.
This behavior is not desired,
resulting in corrupted debuginfo and degrading debugging experience.
This is might not be a bug of `--remap-path-prefix` in rustc,
since `-fdebug-prefix-map` in clang 16 could have the same result
(`DW_AT_comp_dir` is gone when `work_dir` is remapped to an empty string).
However, in gcc 12 `fdebug-prefix-map` will return an absolute work_dir
when an empty string occurs.
To not bother whether this needs to be fixed in rustc or not,
let's fix it by always appending an explicit `.`
when `--remap-path-prefix` remaps to relative workspace root
a.k.a. where rustc is invoking.
For more on gcc/clang remap options, see
https://reproducible-builds.org/docs/build-path/
2023-12-08 18:52:40 +00:00
|
|
|
--remap-path-prefix=[CWD]=. \
|
2023-11-28 18:47:44 +00:00
|
|
|
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
|
2023-09-06 13:59:01 +00:00
|
|
|
[FINISHED] dev [..]",
|
|
|
|
)
|
2023-10-25 01:34:16 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2023-11-02 02:59:26 +00:00
|
|
|
#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")]
|
|
|
|
fn profile_merge_works() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[profile.dev]
|
|
|
|
trim-paths = ["macro"]
|
|
|
|
|
|
|
|
[profile.custom]
|
|
|
|
inherits = "dev"
|
|
|
|
trim-paths = ["diagnostics"]
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("build -v -Ztrim-paths --profile custom")
|
|
|
|
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
|
|
|
[RUNNING] `rustc [..]\
|
2023-11-02 02:53:27 +00:00
|
|
|
-Zremap-path-scope=diagnostics \
|
fix(trim-paths): explicit remap to current dir `.`
In https://github.com/rust-lang/rust/blob/87e1447aa/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs#L856
when the remap result of `work_dir` is an empty string,
LLVM won't generate some symbols for root debuginfo node.
For example, `N_SO` and `N_OSO` on macOS,
or `DW_AT_comp_dir` on Linux when debuginfo is splitted.
Precisely, it is observed that when the `DIFile` of compile unit was
provied with an empty compilation `Directory` string,
LLVM would not emit those symbols for the root DI node.
This behavior is not desired,
resulting in corrupted debuginfo and degrading debugging experience.
This is might not be a bug of `--remap-path-prefix` in rustc,
since `-fdebug-prefix-map` in clang 16 could have the same result
(`DW_AT_comp_dir` is gone when `work_dir` is remapped to an empty string).
However, in gcc 12 `fdebug-prefix-map` will return an absolute work_dir
when an empty string occurs.
To not bother whether this needs to be fixed in rustc or not,
let's fix it by always appending an explicit `.`
when `--remap-path-prefix` remaps to relative workspace root
a.k.a. where rustc is invoking.
For more on gcc/clang remap options, see
https://reproducible-builds.org/docs/build-path/
2023-12-08 18:52:40 +00:00
|
|
|
--remap-path-prefix=[CWD]=. \
|
2023-11-28 18:47:44 +00:00
|
|
|
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
|
2023-11-02 02:59:26 +00:00
|
|
|
[FINISHED] custom [..]",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2023-10-25 01:34:16 +00:00
|
|
|
#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")]
|
|
|
|
fn registry_dependency() {
|
|
|
|
Package::new("bar", "0.0.1")
|
|
|
|
.file("Cargo.toml", &basic_manifest("bar", "0.0.1"))
|
|
|
|
.file("src/lib.rs", r#"pub fn f() { println!("{}", file!()); }"#)
|
|
|
|
.publish();
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = "0.0.1"
|
|
|
|
|
|
|
|
[profile.dev]
|
|
|
|
trim-paths = "object"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() { bar::f(); }")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let registry_src = paths::home().join(".cargo/registry/src");
|
2023-12-26 18:22:25 +00:00
|
|
|
let registry_src = registry_src.display();
|
2023-10-25 01:34:16 +00:00
|
|
|
|
|
|
|
p.cargo("run --verbose -Ztrim-paths")
|
|
|
|
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
|
2023-12-26 18:22:25 +00:00
|
|
|
.with_stdout("-[..]/bar-0.0.1/src/lib.rs") // Omit the hash of Source URL
|
2023-09-06 13:59:01 +00:00
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
|
|
|
[UPDATING] [..]
|
|
|
|
[DOWNLOADING] crates ...
|
|
|
|
[DOWNLOADED] bar v0.0.1 ([..])
|
|
|
|
[COMPILING] bar v0.0.1
|
|
|
|
[RUNNING] `rustc [..]\
|
|
|
|
-Zremap-path-scope=object \
|
2023-12-26 18:22:25 +00:00
|
|
|
--remap-path-prefix={registry_src}= \
|
2023-11-28 18:47:44 +00:00
|
|
|
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
|
2023-09-06 13:59:01 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
|
|
|
[RUNNING] `rustc [..]\
|
|
|
|
-Zremap-path-scope=object \
|
fix(trim-paths): explicit remap to current dir `.`
In https://github.com/rust-lang/rust/blob/87e1447aa/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs#L856
when the remap result of `work_dir` is an empty string,
LLVM won't generate some symbols for root debuginfo node.
For example, `N_SO` and `N_OSO` on macOS,
or `DW_AT_comp_dir` on Linux when debuginfo is splitted.
Precisely, it is observed that when the `DIFile` of compile unit was
provied with an empty compilation `Directory` string,
LLVM would not emit those symbols for the root DI node.
This behavior is not desired,
resulting in corrupted debuginfo and degrading debugging experience.
This is might not be a bug of `--remap-path-prefix` in rustc,
since `-fdebug-prefix-map` in clang 16 could have the same result
(`DW_AT_comp_dir` is gone when `work_dir` is remapped to an empty string).
However, in gcc 12 `fdebug-prefix-map` will return an absolute work_dir
when an empty string occurs.
To not bother whether this needs to be fixed in rustc or not,
let's fix it by always appending an explicit `.`
when `--remap-path-prefix` remaps to relative workspace root
a.k.a. where rustc is invoking.
For more on gcc/clang remap options, see
https://reproducible-builds.org/docs/build-path/
2023-12-08 18:52:40 +00:00
|
|
|
--remap-path-prefix=[CWD]=. \
|
2023-11-28 18:47:44 +00:00
|
|
|
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
|
2023-09-06 13:59:01 +00:00
|
|
|
[FINISHED] dev [..]
|
|
|
|
[RUNNING] `target/debug/foo[EXE]`"
|
|
|
|
))
|
2023-10-25 01:34:16 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")]
|
|
|
|
fn git_dependency() {
|
|
|
|
let git_project = git::new("bar", |project| {
|
|
|
|
project
|
|
|
|
.file("Cargo.toml", &basic_manifest("bar", "0.0.1"))
|
|
|
|
.file("src/lib.rs", r#"pub fn f() { println!("{}", file!()); }"#)
|
|
|
|
});
|
|
|
|
let url = git_project.url();
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = {{ git = "{url}" }}
|
|
|
|
|
|
|
|
[profile.dev]
|
|
|
|
trim-paths = "object"
|
|
|
|
"#
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() { bar::f(); }")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let git_checkouts_src = paths::home().join(".cargo/git/checkouts");
|
2023-12-26 18:22:25 +00:00
|
|
|
let git_checkouts_src = git_checkouts_src.display();
|
2023-10-25 01:34:16 +00:00
|
|
|
|
|
|
|
p.cargo("run --verbose -Ztrim-paths")
|
|
|
|
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
|
2023-12-26 18:22:25 +00:00
|
|
|
.with_stdout("bar-[..]/[..]/src/lib.rs") // Omit the hash of Source URL and commit
|
2023-09-06 13:59:01 +00:00
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
|
|
|
[UPDATING] git repository `{url}`
|
|
|
|
[COMPILING] bar v0.0.1 ({url}[..])
|
|
|
|
[RUNNING] `rustc [..]\
|
|
|
|
-Zremap-path-scope=object \
|
2023-12-26 18:22:25 +00:00
|
|
|
--remap-path-prefix={git_checkouts_src}= \
|
2023-11-28 18:47:44 +00:00
|
|
|
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
|
2023-09-06 13:59:01 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
|
|
|
[RUNNING] `rustc [..]\
|
|
|
|
-Zremap-path-scope=object \
|
fix(trim-paths): explicit remap to current dir `.`
In https://github.com/rust-lang/rust/blob/87e1447aa/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs#L856
when the remap result of `work_dir` is an empty string,
LLVM won't generate some symbols for root debuginfo node.
For example, `N_SO` and `N_OSO` on macOS,
or `DW_AT_comp_dir` on Linux when debuginfo is splitted.
Precisely, it is observed that when the `DIFile` of compile unit was
provied with an empty compilation `Directory` string,
LLVM would not emit those symbols for the root DI node.
This behavior is not desired,
resulting in corrupted debuginfo and degrading debugging experience.
This is might not be a bug of `--remap-path-prefix` in rustc,
since `-fdebug-prefix-map` in clang 16 could have the same result
(`DW_AT_comp_dir` is gone when `work_dir` is remapped to an empty string).
However, in gcc 12 `fdebug-prefix-map` will return an absolute work_dir
when an empty string occurs.
To not bother whether this needs to be fixed in rustc or not,
let's fix it by always appending an explicit `.`
when `--remap-path-prefix` remaps to relative workspace root
a.k.a. where rustc is invoking.
For more on gcc/clang remap options, see
https://reproducible-builds.org/docs/build-path/
2023-12-08 18:52:40 +00:00
|
|
|
--remap-path-prefix=[CWD]=. \
|
2023-11-28 18:47:44 +00:00
|
|
|
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
|
2023-09-06 13:59:01 +00:00
|
|
|
[FINISHED] dev [..]
|
|
|
|
[RUNNING] `target/debug/foo[EXE]`"
|
|
|
|
))
|
2023-10-25 01:34:16 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")]
|
|
|
|
fn path_dependency() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { path = "cocktail-bar" }
|
|
|
|
|
|
|
|
[profile.dev]
|
|
|
|
trim-paths = "object"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() { bar::f(); }")
|
|
|
|
.file("cocktail-bar/Cargo.toml", &basic_manifest("bar", "0.0.1"))
|
|
|
|
.file(
|
|
|
|
"cocktail-bar/src/lib.rs",
|
|
|
|
r#"pub fn f() { println!("{}", file!()); }"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("run --verbose -Ztrim-paths")
|
|
|
|
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
|
|
|
|
.with_stdout("cocktail-bar/src/lib.rs")
|
2023-09-06 13:59:01 +00:00
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
|
|
|
[COMPILING] bar v0.0.1 ([..]/cocktail-bar)
|
|
|
|
[RUNNING] `rustc [..]\
|
|
|
|
-Zremap-path-scope=object \
|
fix(trim-paths): explicit remap to current dir `.`
In https://github.com/rust-lang/rust/blob/87e1447aa/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs#L856
when the remap result of `work_dir` is an empty string,
LLVM won't generate some symbols for root debuginfo node.
For example, `N_SO` and `N_OSO` on macOS,
or `DW_AT_comp_dir` on Linux when debuginfo is splitted.
Precisely, it is observed that when the `DIFile` of compile unit was
provied with an empty compilation `Directory` string,
LLVM would not emit those symbols for the root DI node.
This behavior is not desired,
resulting in corrupted debuginfo and degrading debugging experience.
This is might not be a bug of `--remap-path-prefix` in rustc,
since `-fdebug-prefix-map` in clang 16 could have the same result
(`DW_AT_comp_dir` is gone when `work_dir` is remapped to an empty string).
However, in gcc 12 `fdebug-prefix-map` will return an absolute work_dir
when an empty string occurs.
To not bother whether this needs to be fixed in rustc or not,
let's fix it by always appending an explicit `.`
when `--remap-path-prefix` remaps to relative workspace root
a.k.a. where rustc is invoking.
For more on gcc/clang remap options, see
https://reproducible-builds.org/docs/build-path/
2023-12-08 18:52:40 +00:00
|
|
|
--remap-path-prefix=[CWD]=. \
|
2023-11-28 18:47:44 +00:00
|
|
|
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
|
2023-09-06 13:59:01 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
|
|
|
[RUNNING] `rustc [..]\
|
|
|
|
-Zremap-path-scope=object \
|
fix(trim-paths): explicit remap to current dir `.`
In https://github.com/rust-lang/rust/blob/87e1447aa/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs#L856
when the remap result of `work_dir` is an empty string,
LLVM won't generate some symbols for root debuginfo node.
For example, `N_SO` and `N_OSO` on macOS,
or `DW_AT_comp_dir` on Linux when debuginfo is splitted.
Precisely, it is observed that when the `DIFile` of compile unit was
provied with an empty compilation `Directory` string,
LLVM would not emit those symbols for the root DI node.
This behavior is not desired,
resulting in corrupted debuginfo and degrading debugging experience.
This is might not be a bug of `--remap-path-prefix` in rustc,
since `-fdebug-prefix-map` in clang 16 could have the same result
(`DW_AT_comp_dir` is gone when `work_dir` is remapped to an empty string).
However, in gcc 12 `fdebug-prefix-map` will return an absolute work_dir
when an empty string occurs.
To not bother whether this needs to be fixed in rustc or not,
let's fix it by always appending an explicit `.`
when `--remap-path-prefix` remaps to relative workspace root
a.k.a. where rustc is invoking.
For more on gcc/clang remap options, see
https://reproducible-builds.org/docs/build-path/
2023-12-08 18:52:40 +00:00
|
|
|
--remap-path-prefix=[CWD]=. \
|
2023-11-28 18:47:44 +00:00
|
|
|
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
|
2023-09-06 13:59:01 +00:00
|
|
|
[FINISHED] dev [..]
|
|
|
|
[RUNNING] `target/debug/foo[EXE]`"
|
|
|
|
))
|
2023-10-25 01:34:16 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")]
|
|
|
|
fn path_dependency_outside_workspace() {
|
|
|
|
let bar = project()
|
|
|
|
.at("bar")
|
|
|
|
.file("Cargo.toml", &basic_manifest("bar", "0.0.1"))
|
|
|
|
.file("src/lib.rs", r#"pub fn f() { println!("{}", file!()); }"#)
|
|
|
|
.build();
|
|
|
|
let bar_path = bar.url().to_file_path().unwrap();
|
|
|
|
let bar_path = bar_path.display();
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { path = "../bar" }
|
|
|
|
|
|
|
|
[profile.dev]
|
|
|
|
trim-paths = "object"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() { bar::f(); }")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("run --verbose -Ztrim-paths")
|
|
|
|
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
|
2023-09-06 13:59:01 +00:00
|
|
|
.with_stdout("bar-0.0.1/src/lib.rs")
|
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
|
|
|
[COMPILING] bar v0.0.1 ([..]/bar)
|
|
|
|
[RUNNING] `rustc [..]\
|
|
|
|
-Zremap-path-scope=object \
|
2023-11-28 18:47:44 +00:00
|
|
|
--remap-path-prefix={bar_path}=bar-0.0.1 \
|
|
|
|
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
|
2023-09-06 13:59:01 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
|
|
|
[RUNNING] `rustc [..]\
|
|
|
|
-Zremap-path-scope=object \
|
fix(trim-paths): explicit remap to current dir `.`
In https://github.com/rust-lang/rust/blob/87e1447aa/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs#L856
when the remap result of `work_dir` is an empty string,
LLVM won't generate some symbols for root debuginfo node.
For example, `N_SO` and `N_OSO` on macOS,
or `DW_AT_comp_dir` on Linux when debuginfo is splitted.
Precisely, it is observed that when the `DIFile` of compile unit was
provied with an empty compilation `Directory` string,
LLVM would not emit those symbols for the root DI node.
This behavior is not desired,
resulting in corrupted debuginfo and degrading debugging experience.
This is might not be a bug of `--remap-path-prefix` in rustc,
since `-fdebug-prefix-map` in clang 16 could have the same result
(`DW_AT_comp_dir` is gone when `work_dir` is remapped to an empty string).
However, in gcc 12 `fdebug-prefix-map` will return an absolute work_dir
when an empty string occurs.
To not bother whether this needs to be fixed in rustc or not,
let's fix it by always appending an explicit `.`
when `--remap-path-prefix` remaps to relative workspace root
a.k.a. where rustc is invoking.
For more on gcc/clang remap options, see
https://reproducible-builds.org/docs/build-path/
2023-12-08 18:52:40 +00:00
|
|
|
--remap-path-prefix=[CWD]=. \
|
2023-11-28 18:47:44 +00:00
|
|
|
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
|
2023-09-06 13:59:01 +00:00
|
|
|
[FINISHED] dev [..]
|
|
|
|
[RUNNING] `target/debug/foo[EXE]`"
|
|
|
|
))
|
2023-10-25 01:34:16 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")]
|
|
|
|
fn diagnostics_works() {
|
|
|
|
Package::new("bar", "0.0.1")
|
|
|
|
.file("Cargo.toml", &basic_manifest("bar", "0.0.1"))
|
|
|
|
.file("src/lib.rs", r#"pub fn f() { let unused = 0; }"#)
|
|
|
|
.publish();
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = "0.0.1"
|
|
|
|
|
|
|
|
[profile.dev]
|
|
|
|
trim-paths = "diagnostics"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let registry_src = paths::home().join(".cargo/registry/src");
|
|
|
|
let registry_src = registry_src.display();
|
|
|
|
|
|
|
|
p.cargo("build -vv -Ztrim-paths")
|
|
|
|
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
|
2023-09-06 13:59:01 +00:00
|
|
|
.with_stderr_line_without(
|
|
|
|
&["[..]bar-0.0.1/src/lib.rs:1[..]"],
|
|
|
|
&[&format!("{registry_src}")],
|
|
|
|
)
|
2023-10-25 01:34:16 +00:00
|
|
|
.with_stderr_contains("[..]unused_variables[..]")
|
2023-09-06 13:59:01 +00:00
|
|
|
.with_stderr_contains(&format!(
|
|
|
|
"\
|
|
|
|
[RUNNING] [..]rustc [..]\
|
|
|
|
-Zremap-path-scope=diagnostics \
|
2023-12-26 18:22:25 +00:00
|
|
|
--remap-path-prefix={registry_src}= \
|
2023-11-28 18:47:44 +00:00
|
|
|
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]",
|
2023-09-06 13:59:01 +00:00
|
|
|
))
|
|
|
|
.with_stderr_contains(
|
|
|
|
"\
|
|
|
|
[RUNNING] [..]rustc [..]\
|
|
|
|
-Zremap-path-scope=diagnostics \
|
fix(trim-paths): explicit remap to current dir `.`
In https://github.com/rust-lang/rust/blob/87e1447aa/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs#L856
when the remap result of `work_dir` is an empty string,
LLVM won't generate some symbols for root debuginfo node.
For example, `N_SO` and `N_OSO` on macOS,
or `DW_AT_comp_dir` on Linux when debuginfo is splitted.
Precisely, it is observed that when the `DIFile` of compile unit was
provied with an empty compilation `Directory` string,
LLVM would not emit those symbols for the root DI node.
This behavior is not desired,
resulting in corrupted debuginfo and degrading debugging experience.
This is might not be a bug of `--remap-path-prefix` in rustc,
since `-fdebug-prefix-map` in clang 16 could have the same result
(`DW_AT_comp_dir` is gone when `work_dir` is remapped to an empty string).
However, in gcc 12 `fdebug-prefix-map` will return an absolute work_dir
when an empty string occurs.
To not bother whether this needs to be fixed in rustc or not,
let's fix it by always appending an explicit `.`
when `--remap-path-prefix` remaps to relative workspace root
a.k.a. where rustc is invoking.
For more on gcc/clang remap options, see
https://reproducible-builds.org/docs/build-path/
2023-12-08 18:52:40 +00:00
|
|
|
--remap-path-prefix=[CWD]=. \
|
2023-11-28 18:47:44 +00:00
|
|
|
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]",
|
2023-09-06 13:59:01 +00:00
|
|
|
)
|
2023-10-25 01:34:16 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2023-12-04 21:52:32 +00:00
|
|
|
#[cfg(target_os = "macos")]
|
2023-12-08 15:49:06 +00:00
|
|
|
mod object_works {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
fn inspect_debuginfo(path: &std::path::Path) -> Vec<u8> {
|
2023-12-04 21:52:32 +00:00
|
|
|
std::process::Command::new("nm")
|
|
|
|
.arg("-pa")
|
|
|
|
.arg(path)
|
|
|
|
.output()
|
|
|
|
.expect("nm works")
|
|
|
|
.stdout
|
2023-12-08 15:49:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(requires_nm, nightly, reason = "-Zremap-path-scope is unstable")]
|
|
|
|
fn with_split_debuginfo_off() {
|
|
|
|
object_works_helper("off", inspect_debuginfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(requires_nm, nightly, reason = "-Zremap-path-scope is unstable")]
|
|
|
|
fn with_split_debuginfo_packed() {
|
|
|
|
object_works_helper("packed", inspect_debuginfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(requires_nm, nightly, reason = "-Zremap-path-scope is unstable")]
|
|
|
|
fn with_split_debuginfo_unpacked() {
|
|
|
|
object_works_helper("unpacked", inspect_debuginfo);
|
|
|
|
}
|
2023-12-04 21:52:32 +00:00
|
|
|
}
|
|
|
|
|
2023-10-25 01:34:16 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
2023-12-08 15:49:06 +00:00
|
|
|
mod object_works {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
fn inspect_debuginfo(path: &std::path::Path) -> Vec<u8> {
|
2023-10-25 01:34:16 +00:00
|
|
|
std::process::Command::new("readelf")
|
2023-12-08 21:34:00 +00:00
|
|
|
.arg("--debug-dump=info")
|
|
|
|
.arg("--debug-dump=no-follow-links") // older version can't recognized but just a warning
|
2023-10-25 01:34:16 +00:00
|
|
|
.arg(path)
|
|
|
|
.output()
|
|
|
|
.expect("readelf works")
|
2023-12-04 21:52:32 +00:00
|
|
|
.stdout
|
2023-12-08 15:49:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(requires_readelf, nightly, reason = "-Zremap-path-scope is unstable")]
|
|
|
|
fn with_split_debuginfo_off() {
|
|
|
|
object_works_helper("off", inspect_debuginfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(requires_readelf, nightly, reason = "-Zremap-path-scope is unstable")]
|
|
|
|
fn with_split_debuginfo_packed() {
|
|
|
|
object_works_helper("packed", inspect_debuginfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(requires_readelf, nightly, reason = "-Zremap-path-scope is unstable")]
|
|
|
|
fn with_split_debuginfo_unpacked() {
|
|
|
|
object_works_helper("unpacked", inspect_debuginfo);
|
|
|
|
}
|
2023-12-04 21:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
2023-12-08 15:49:06 +00:00
|
|
|
fn object_works_helper(split_debuginfo: &str, run: impl Fn(&std::path::Path) -> Vec<u8>) {
|
2023-12-04 21:52:32 +00:00
|
|
|
use std::os::unix::ffi::OsStrExt;
|
2023-10-25 01:34:16 +00:00
|
|
|
|
|
|
|
let registry_src = paths::home().join(".cargo/registry/src");
|
|
|
|
let registry_src_bytes = registry_src.as_os_str().as_bytes();
|
2023-12-26 18:22:25 +00:00
|
|
|
let registry_src = registry_src.display();
|
|
|
|
let rust_src = "/lib/rustc/src/rust".as_bytes();
|
2023-10-25 01:34:16 +00:00
|
|
|
|
|
|
|
Package::new("bar", "0.0.1")
|
|
|
|
.file("Cargo.toml", &basic_manifest("bar", "0.0.1"))
|
|
|
|
.file("src/lib.rs", r#"pub fn f() { println!("{}", file!()); }"#)
|
|
|
|
.publish();
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
2023-12-08 15:49:06 +00:00
|
|
|
&format!(
|
|
|
|
r#"
|
2023-10-25 01:34:16 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = "0.0.1"
|
2023-12-08 15:49:06 +00:00
|
|
|
|
|
|
|
[profile.dev]
|
|
|
|
split-debuginfo = "{split_debuginfo}"
|
|
|
|
"#
|
|
|
|
),
|
2023-10-25 01:34:16 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() { bar::f(); }")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let pkg_root = p.root();
|
|
|
|
let pkg_root = pkg_root.as_os_str().as_bytes();
|
|
|
|
|
|
|
|
p.cargo("build").run();
|
|
|
|
|
|
|
|
let bin_path = p.bin("foo");
|
|
|
|
assert!(bin_path.is_file());
|
2023-12-04 21:52:32 +00:00
|
|
|
let stdout = run(&bin_path);
|
2023-10-25 01:34:16 +00:00
|
|
|
// TODO: re-enable this check when rustc bootstrap disables remapping
|
|
|
|
// <https://github.com/rust-lang/cargo/pull/12625#discussion_r1371714791>
|
|
|
|
// assert!(memchr::memmem::find(&stdout, rust_src).is_some());
|
|
|
|
assert!(memchr::memmem::find(&stdout, registry_src_bytes).is_some());
|
|
|
|
assert!(memchr::memmem::find(&stdout, pkg_root).is_some());
|
|
|
|
|
|
|
|
p.cargo("clean").run();
|
|
|
|
|
|
|
|
p.cargo("build --verbose -Ztrim-paths")
|
2023-12-08 15:46:11 +00:00
|
|
|
.arg("--config")
|
|
|
|
.arg(r#"profile.dev.trim-paths="object""#)
|
2023-10-25 01:34:16 +00:00
|
|
|
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
|
2023-09-06 13:59:01 +00:00
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
|
|
|
[COMPILING] bar v0.0.1
|
2023-12-08 15:49:06 +00:00
|
|
|
[RUNNING] `rustc [..]-C split-debuginfo={split_debuginfo} [..]\
|
2023-09-06 13:59:01 +00:00
|
|
|
-Zremap-path-scope=object \
|
2023-12-26 18:22:25 +00:00
|
|
|
--remap-path-prefix={registry_src}= \
|
2023-11-28 18:47:44 +00:00
|
|
|
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
|
2023-09-06 13:59:01 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2023-12-08 15:49:06 +00:00
|
|
|
[RUNNING] `rustc [..]-C split-debuginfo={split_debuginfo} [..]\
|
2023-09-06 13:59:01 +00:00
|
|
|
-Zremap-path-scope=object \
|
fix(trim-paths): explicit remap to current dir `.`
In https://github.com/rust-lang/rust/blob/87e1447aa/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs#L856
when the remap result of `work_dir` is an empty string,
LLVM won't generate some symbols for root debuginfo node.
For example, `N_SO` and `N_OSO` on macOS,
or `DW_AT_comp_dir` on Linux when debuginfo is splitted.
Precisely, it is observed that when the `DIFile` of compile unit was
provied with an empty compilation `Directory` string,
LLVM would not emit those symbols for the root DI node.
This behavior is not desired,
resulting in corrupted debuginfo and degrading debugging experience.
This is might not be a bug of `--remap-path-prefix` in rustc,
since `-fdebug-prefix-map` in clang 16 could have the same result
(`DW_AT_comp_dir` is gone when `work_dir` is remapped to an empty string).
However, in gcc 12 `fdebug-prefix-map` will return an absolute work_dir
when an empty string occurs.
To not bother whether this needs to be fixed in rustc or not,
let's fix it by always appending an explicit `.`
when `--remap-path-prefix` remaps to relative workspace root
a.k.a. where rustc is invoking.
For more on gcc/clang remap options, see
https://reproducible-builds.org/docs/build-path/
2023-12-08 18:52:40 +00:00
|
|
|
--remap-path-prefix=[CWD]=. \
|
2023-11-28 18:47:44 +00:00
|
|
|
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]
|
2023-09-06 13:59:01 +00:00
|
|
|
[FINISHED] dev [..]",
|
|
|
|
))
|
2023-10-25 01:34:16 +00:00
|
|
|
.run();
|
|
|
|
|
|
|
|
let bin_path = p.bin("foo");
|
|
|
|
assert!(bin_path.is_file());
|
2023-12-04 21:52:32 +00:00
|
|
|
let stdout = run(&bin_path);
|
2023-09-06 13:59:01 +00:00
|
|
|
assert!(memchr::memmem::find(&stdout, rust_src).is_none());
|
2023-12-08 15:49:06 +00:00
|
|
|
for line in stdout.split(|c| c == &b'\n') {
|
|
|
|
let registry = memchr::memmem::find(line, registry_src_bytes).is_none();
|
|
|
|
let local = memchr::memmem::find(line, pkg_root).is_none();
|
|
|
|
if registry && local {
|
|
|
|
continue;
|
|
|
|
}
|
2023-12-04 21:52:32 +00:00
|
|
|
|
2023-12-08 15:49:06 +00:00
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
{
|
|
|
|
// `OSO` symbols can't be trimmed at this moment.
|
|
|
|
// See <https://github.com/rust-lang/rust/issues/116948#issuecomment-1793617018>
|
2023-12-04 21:52:32 +00:00
|
|
|
if memchr::memmem::find(line, b" OSO ").is_some() {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// on macOS `SO` symbols are embedded in final binaries and should be trimmed.
|
|
|
|
// See rust-lang/rust#117652.
|
2023-12-08 15:49:06 +00:00
|
|
|
if memchr::memmem::find(line, b" SO ").is_some() {
|
|
|
|
continue;
|
|
|
|
}
|
2023-12-04 21:52:32 +00:00
|
|
|
}
|
2023-12-08 15:49:06 +00:00
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
{
|
|
|
|
// There is a bug in rustc `-Zremap-path-scope`.
|
|
|
|
// See rust-lang/rust/pull/118518
|
|
|
|
if memchr::memmem::find(line, b"DW_AT_comp_dir").is_some() {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if memchr::memmem::find(line, b"DW_AT_GNU_dwo_name").is_some() {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
panic!(
|
|
|
|
"unexpected untrimmed symbol: {}",
|
|
|
|
String::from_utf8(line.into()).unwrap()
|
|
|
|
);
|
2023-12-04 21:52:32 +00:00
|
|
|
}
|
2023-10-25 01:34:16 +00:00
|
|
|
}
|
2023-10-31 04:42:37 +00:00
|
|
|
|
|
|
|
// TODO: might want to move to test/testsuite/build_script.rs once stabilized.
|
|
|
|
#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")]
|
|
|
|
fn custom_build_env_var_trim_paths() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("build.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let test_cases = [
|
|
|
|
("[]", "none"),
|
|
|
|
("\"all\"", "all"),
|
|
|
|
("\"diagnostics\"", "diagnostics"),
|
|
|
|
("\"macro\"", "macro"),
|
|
|
|
("\"none\"", "none"),
|
|
|
|
("\"object\"", "object"),
|
|
|
|
("false", "none"),
|
|
|
|
("true", "all"),
|
|
|
|
(
|
|
|
|
r#"["diagnostics", "macro", "object"]"#,
|
|
|
|
"diagnostics,macro,object",
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
|
|
|
for (opts, expected) in test_cases {
|
|
|
|
p.change_file(
|
|
|
|
"Cargo.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[profile.dev]
|
|
|
|
trim-paths = {opts}
|
|
|
|
"#
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
p.change_file(
|
|
|
|
"build.rs",
|
|
|
|
&format!(
|
|
|
|
r#"
|
|
|
|
fn main() {{
|
|
|
|
assert_eq!(
|
|
|
|
std::env::var("CARGO_TRIM_PATHS").unwrap().as_str(),
|
|
|
|
"{expected}",
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
"#
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
p.cargo("build -Ztrim-paths")
|
|
|
|
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
}
|
2023-12-01 00:38:46 +00:00
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
#[cargo_test(requires_lldb, nightly, reason = "-Zremap-path-scope is unstable")]
|
|
|
|
fn lldb_works_after_trimmed() {
|
|
|
|
use cargo_test_support::compare::match_contains;
|
|
|
|
|
|
|
|
let run_lldb = |path| {
|
|
|
|
std::process::Command::new("lldb")
|
|
|
|
.args(["-o", "breakpoint set --file src/main.rs --line 4"])
|
|
|
|
.args(["-o", "run"])
|
|
|
|
.args(["-o", "continue"])
|
|
|
|
.args(["-o", "exit"])
|
|
|
|
.arg("--no-use-colors")
|
|
|
|
.arg(path)
|
|
|
|
.output()
|
|
|
|
.expect("lldb works")
|
|
|
|
};
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[profile.dev]
|
|
|
|
trim-paths = "object"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
|
|
|
fn main() {
|
|
|
|
let msg = "Hello, Ferris!";
|
|
|
|
println!("{msg}");
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("build --verbose -Ztrim-paths")
|
|
|
|
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
|
|
|
|
.with_stderr_contains(
|
|
|
|
"\
|
|
|
|
[RUNNING] `rustc [..]\
|
|
|
|
-Zremap-path-scope=object \
|
fix(trim-paths): explicit remap to current dir `.`
In https://github.com/rust-lang/rust/blob/87e1447aa/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs#L856
when the remap result of `work_dir` is an empty string,
LLVM won't generate some symbols for root debuginfo node.
For example, `N_SO` and `N_OSO` on macOS,
or `DW_AT_comp_dir` on Linux when debuginfo is splitted.
Precisely, it is observed that when the `DIFile` of compile unit was
provied with an empty compilation `Directory` string,
LLVM would not emit those symbols for the root DI node.
This behavior is not desired,
resulting in corrupted debuginfo and degrading debugging experience.
This is might not be a bug of `--remap-path-prefix` in rustc,
since `-fdebug-prefix-map` in clang 16 could have the same result
(`DW_AT_comp_dir` is gone when `work_dir` is remapped to an empty string).
However, in gcc 12 `fdebug-prefix-map` will return an absolute work_dir
when an empty string occurs.
To not bother whether this needs to be fixed in rustc or not,
let's fix it by always appending an explicit `.`
when `--remap-path-prefix` remaps to relative workspace root
a.k.a. where rustc is invoking.
For more on gcc/clang remap options, see
https://reproducible-builds.org/docs/build-path/
2023-12-08 18:52:40 +00:00
|
|
|
--remap-path-prefix=[CWD]=. \
|
2023-12-01 00:38:46 +00:00
|
|
|
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
let bin_path = p.bin("foo");
|
|
|
|
assert!(bin_path.is_file());
|
|
|
|
let stdout = String::from_utf8(run_lldb(bin_path).stdout).unwrap();
|
|
|
|
match_contains("[..]stopped[..]", &stdout, None).unwrap();
|
|
|
|
match_contains("[..]stop reason = breakpoint[..]", &stdout, None).unwrap();
|
|
|
|
match_contains(
|
|
|
|
"\
|
|
|
|
(lldb) continue
|
|
|
|
Hello, Ferris!",
|
|
|
|
&stdout,
|
|
|
|
None,
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
}
|