Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions tests/testsuite/profile_trim_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ mod object_works {
}

fn object_works_helper(split_debuginfo: &str, run: impl Fn(&std::path::Path) -> Vec<u8>) {
let registry_src = paths::home().join(".cargo/registry/src");
let registry_src = paths::home().join(".cargo").join("registry").join("src");

@epage epage Jul 15, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

side note: I thought windows was also supposed to work with / but I've also observed this problem

View changes since the review

let registry_src_bytes = registry_src.as_os_str().as_encoded_bytes();
let rust_src = "/lib/rustc/src/rust".as_bytes();

Expand Down Expand Up @@ -644,23 +644,27 @@ fn object_works_helper(split_debuginfo: &str, run: impl Fn(&std::path::Path) ->
let pkg_root = p.root();
let pkg_root = pkg_root.as_os_str().as_encoded_bytes();

// Our baseline of which source roots are discoverable without object trimming.
p.cargo("build").run();

let bin_path = p.bin("foo");
assert!(bin_path.is_file());
let stdout = run(&bin_path);
// On windows-msvc every debuginfo is in pdb file, so can't find anything here.

// 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());

// `file!()` in `bar()` keeps untrimmed registry source in the executable
// even when debuginfo is separate.
assert!(memchr::memmem::find(&stdout, registry_src_bytes).is_some());

// The local package root occurs only in debuginfo in this fixture.
// MSVC puts that debuginfo in the PDB,
// while the other inspectors read embedded debuginfo.
if cfg!(target_env = "msvc") {
// 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_none());
assert!(memchr::memmem::find(&stdout, pkg_root).is_none());
} else {
// 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();
Expand Down Expand Up @@ -689,11 +693,17 @@ fn object_works_helper(split_debuginfo: &str, run: impl Fn(&std::path::Path) ->
let bin_path = p.bin("foo");
assert!(bin_path.is_file());
let stdout = run(&bin_path);

// Original sysroot source root should be trimmed.
assert!(memchr::memmem::find(&stdout, rust_src).is_none());

// Check line by line so macOS can exempt untrimmable `OSO` symbols.
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 {
// original registry source root was trimmed.
let registry_is_trimmed = memchr::memmem::find(line, registry_src_bytes).is_none();
// original project root was trimmed.
let local_is_trimmed = memchr::memmem::find(line, pkg_root).is_none();
if registry_is_trimmed && local_is_trimmed {
continue;
}

Expand Down