Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Oct 25, 2023
1 parent 539068b commit 93a7fbf
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions tests/testsuite/profile_trim_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,101 @@ warning: unused variable: `unused`
)
.run();
}

#[cfg(unix)]
#[cargo_test(requires_strings, nightly, reason = "-Zremap-path-scope is unstable")]
fn object_works() {
let run_strings = |path| {
std::process::Command::new("strings")
.arg(path)
.output()
.expect("strings works")
};

let registry_src = paths::home().join(".cargo/registry/src");
let pkg_remap = format!("{}/[..]/bar-0.0.1=bar-0.0.1", registry_src.display());
let rust_src = "/lib/rustc/src/rust".as_bytes();
let registry_src_bytes = registry_src.as_os_str().as_encoded_bytes();

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]
split-debuginfo = "off" # we verify the executable as a whole
"#,
)
.file("src/main.rs", "fn main() { bar::f(); }")
.build();

let pkg_root = p.root();
let pkg_root = pkg_root.as_os_str().as_encoded_bytes();

p.cargo("build").run();

let bin_path = p.bin("foo");
assert!(bin_path.is_file());
let stdout = run_strings(bin_path).stdout;
// 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.change_file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
[dependencies]
bar = "0.0.1"
[profile.dev]
trim-paths = "object"
split-debuginfo = "off" # we verify the executable as a whole
"#,
);

p.cargo("build --verbose -Ztrim-paths")
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
.with_stderr(&format!(
"\
[COMPILING] bar v0.0.1
[RUNNING] `rustc [..]\
-Zremap-path-scope=object \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
--remap-path-prefix={pkg_remap} [..]
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc [..]\
-Zremap-path-scope=object \
--remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \
--remap-path-prefix=[CWD]= [..]
[FINISHED] dev [..]",
))
.run();

let bin_path = p.bin("foo");
assert!(bin_path.is_file());
let stdout = run_strings(bin_path).stdout;
dbg!(p.root());
assert!(memchr::memmem::find(&stdout, rust_src).is_none());
assert!(memchr::memmem::find(&stdout, registry_src_bytes).is_none());
// TODO: on macOS codegen unit partitions `.rcgu.o` are still there.
#[cfg(not(target_os = "macos"))]
assert!(memchr::memmem::find(&stdout, pkg_root).is_none());
}

0 comments on commit 93a7fbf

Please sign in to comment.