Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ jobs:
os: windows-latest
rust: stable-msvc
other: i686-pc-windows-msvc
- name: Windows x86_64 MSVC nightly

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

WARN: A new job is added

os: windows-latest
rust: nightly-msvc
other: i686-pc-windows-msvc
- name: Windows x86_64 gnu nightly # runs out of space while trying to link the test suite
os: windows-latest
rust: nightly-gnu
Expand All @@ -179,6 +183,10 @@ jobs:
- run: sudo apt update -y && sudo apt install lldb gcc-multilib libsecret-1-0 libsecret-1-dev -y
if: matrix.os == 'ubuntu-latest'
- run: rustup component add rustfmt || echo "rustfmt not available"
- name: Add Windows debuggers bin to PATH
shell: pwsh
run: Add-Content $env:GITHUB_PATH "C:\Program Files (x86)\Windows Kits\10\Debuggers\x64"
if: matrix.os == 'windows-latest'
- name: Configure extra test environment
run: echo CARGO_CONTAINER_TESTS=1 >> $GITHUB_ENV
if: matrix.os == 'ubuntu-latest'
Expand Down
32 changes: 31 additions & 1 deletion crates/cargo-test-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,37 @@ fn check_command(command_path: &Path, args: &[&str]) -> bool {
}

fn has_command(command: &str) -> bool {
check_command(Path::new(command), &["--version"])
use std::env::consts::EXE_EXTENSION;
// ALLOWED: For testing cargo itself only.
#[allow(clippy::disallowed_methods)]
let Some(paths) = std::env::var_os("PATH") else {
return false;
};
std::env::split_paths(&paths)
.flat_map(|path| {
let candidate = path.join(&command);
let with_exe = if EXE_EXTENSION.is_empty() {
None
} else {
Some(candidate.with_extension(EXE_EXTENSION))
};
std::iter::once(candidate).chain(with_exe)
})
.find(|p| is_executable(p))
.is_some()
}

#[cfg(unix)]
fn is_executable<P: AsRef<Path>>(path: P) -> bool {
use std::os::unix::prelude::*;
std::fs::metadata(path)
.map(|metadata| metadata.is_file() && metadata.permissions().mode() & 0o111 != 0)
.unwrap_or(false)
}

#[cfg(windows)]
fn is_executable<P: AsRef<Path>>(path: P) -> bool {
path.as_ref().is_file()
}

fn has_rustup_stable() -> bool {
Expand Down
112 changes: 101 additions & 11 deletions tests/testsuite/profile_trim_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,32 @@ mod object_works {
}
}

#[cfg(unix)]
fn object_works_helper(split_debuginfo: &str, run: impl Fn(&std::path::Path) -> Vec<u8>) {
use std::os::unix::ffi::OsStrExt;
#[cfg(target_env = "msvc")]
mod object_works {
use super::*;

fn inspect_debuginfo(path: &std::path::Path) -> Vec<u8> {
std::process::Command::new("strings")
.arg(path)
.output()
.expect("strings works")
.stdout
}

// windows-msvc supports split-debuginfo=packed only
#[cargo_test(
requires = "strings",
nightly,
reason = "-Zremap-path-scope is unstable"
)]
fn with_split_debuginfo_packed() {
object_works_helper("packed", inspect_debuginfo);
}
}

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_bytes = registry_src.as_os_str().as_bytes();
let registry_src_bytes = registry_src.as_os_str().as_encoded_bytes();
let rust_src = "/lib/rustc/src/rust".as_bytes();

Package::new("bar", "0.0.1")
Expand Down Expand Up @@ -538,19 +558,27 @@ fn object_works_helper(split_debuginfo: &str, run: impl Fn(&std::path::Path) ->
.build();

let pkg_root = p.root();
let pkg_root = pkg_root.as_os_str().as_bytes();
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(&bin_path);
// 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());

// On windows-msvc every debuginfo is in pdb file, so can't find anything here.
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();

p.cargo("build --verbose -Ztrim-paths")
Expand Down Expand Up @@ -763,6 +791,68 @@ Hello, Ferris!
);
}

#[cfg(target_env = "msvc")]
#[cargo_test(requires = "cdb", nightly, reason = "-Zremap-path-scope is unstable")]
fn cdb_works_after_trimmed() {
use cargo_test_support::compare::assert_e2e;

let run_debugger = |path| {
std::process::Command::new("cdb")
.args(["-c", "bp `main.rs:4`;g;g;q"])
.arg(path)
.output()
.expect("debugger works")
};

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"

[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_data(str![[r#"
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[RUNNING] `rustc [..]-Zremap-path-scope=object --remap-path-prefix=[ROOT]/foo=. --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]`
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
.run();

let bin_path = p.bin("foo");
assert!(bin_path.is_file());
let stdout = String::from_utf8(run_debugger(bin_path).stdout).unwrap();
assert_e2e().eq(
&stdout,
str![[r#"
...
Breakpoint 0 hit
Hello, Ferris!
...

"#]],
);
}

#[cargo_test(nightly, reason = "rustdoc --remap-path-prefix is unstable")]
fn rustdoc_without_diagnostics_scope() {
Package::new("bar", "0.0.1")
Expand Down