Skip to content

Commit 11c47d0

Browse files
authored
fix(test): skip dwp uplift test without packed debuginfo (#17127)
### What does this PR try to resolve? Fix: rust-lang/rust#158213. `uplift_dwp_of_bin_on_linux` assumes all Linux hosts can produce `.dwp` files by requesting `-Csplit-debuginfo=packed`. That is not true for every Linux target. For example, `riscv64gc-unknown-linux-gnu` currently reports only `off` from `rustc --print=split-debuginfo`. When Cargo sees that `packed` is unsupported, it correctly avoids passing `-Csplit-debuginfo=packed`, so rustc does not emit `.dwp` files. The test then fails because it still unconditionally expects those files. This PR adds a `requires_host_split_debuginfo = "packed"` option to the `cargo_test` macro and uses it for the `.dwp` uplift test, so unsupported hosts show the test as ignored instead of silently returning. ### How to test and review this PR? The main behavior to review is that the test still runs on Linux hosts that support `packed`, while being marked ignored on Linux hosts like RISC-V where Cargo cannot request packed split debuginfo. Tested with: ```console build/x86_64-unknown-linux-gnu/rustfmt/bin/rustfmt --check src/tools/cargo/crates/cargo-test-macro/src/lib.rs src/tools/cargo/tests/testsuite/build.rs RUST_BACKTRACE=1 ./x test --stage 2 src/tools/cargo --test-args "build::uplift_dwp_of_bin_on_linux --exact --nocapture" ```
2 parents a595d0d + 378d210 commit 11c47d0

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

crates/cargo-test-macro/src/lib.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ use std::sync::LazyLock;
3838
/// For example, `requires = "rustfmt"` means the test will only run if the executable `rustfmt` is installed.
3939
/// These tests are *always* run on CI.
4040
/// This is mainly used to avoid requiring contributors from having every dependency installed.
41+
/// * `requires_host_split_debuginfo = "<value>"` --- This indicates a `-Csplit-debuginfo` value
42+
/// that is required to be supported by the host `rustc`.
4143
/// * `build_std_real` --- This is a "real" `-Zbuild-std` test (in the `build_std` integration test).
4244
/// This only runs on nightly, and only if the environment variable `CARGO_RUN_BUILD_STD_TESTS` is set (these tests on run on Linux).
4345
/// * `build_std_mock` --- This is a "mock" `-Zbuild-std` test (which uses a mock standard library).
@@ -147,6 +149,23 @@ pub fn cargo_test(attr: TokenStream, item: TokenStream) -> TokenStream {
147149
};
148150
set_ignore!(!has_command(command), "{command} not installed");
149151
}
152+
s if s.starts_with("requires_host_split_debuginfo=") => {
153+
let split_debuginfo = &s[30..];
154+
let Ok(literal) = split_debuginfo.parse::<Literal>() else {
155+
panic!("expect a string literal, found: {split_debuginfo}");
156+
};
157+
let literal = literal.to_string();
158+
let Some(split_debuginfo) = literal
159+
.strip_prefix('"')
160+
.and_then(|lit| lit.strip_suffix('"'))
161+
else {
162+
panic!("expect a quoted string literal, found: {literal}");
163+
};
164+
set_ignore!(
165+
!host_supports_split_debuginfo(split_debuginfo),
166+
"host rustc does not support -Csplit-debuginfo={split_debuginfo}"
167+
);
168+
}
150169
s if s.starts_with(">=1.") => {
151170
requires_reason = true;
152171
let min_minor = s[4..].parse().unwrap();
@@ -321,6 +340,33 @@ fn version() -> (u32, bool) {
321340
LazyLock::force(&VERSION).clone()
322341
}
323342

343+
fn host_supports_split_debuginfo(split_debuginfo: &str) -> bool {
344+
static SPLIT_DEBUGINFO: LazyLock<Vec<String>> = LazyLock::new(|| {
345+
let output = Command::new("rustc")
346+
.arg("--print=split-debuginfo")
347+
.output()
348+
.expect("rustc should run");
349+
350+
let exit_code = output.status.code();
351+
if exit_code != Some(0) {
352+
let stdout = std::str::from_utf8(&output.stdout).unwrap_or("<invalid utf8>");
353+
let stderr = std::str::from_utf8(&output.stderr).unwrap_or("<invalid utf8>");
354+
panic!(
355+
"'rustc --print=split-debuginfo' exited with non-zero exit code: {exit_code:?}\n\
356+
stdout: {stdout}\n\
357+
stderr: {stderr}",
358+
);
359+
}
360+
361+
let stdout = std::str::from_utf8(&output.stdout).expect("utf8");
362+
stdout.lines().map(str::to_owned).collect()
363+
});
364+
365+
SPLIT_DEBUGINFO
366+
.iter()
367+
.any(|supported| supported == split_debuginfo)
368+
}
369+
324370
fn check_command(command_path: &Path, args: &[&str]) -> bool {
325371
let mut command = Command::new(command_path);
326372
let command_name = command.get_program().to_str().unwrap().to_owned();

tests/testsuite/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5241,7 +5241,7 @@ fn uplift_pdb_of_bin_on_windows() {
52415241
assert!(!p.target_debug_dir().join("d.pdb").exists());
52425242
}
52435243

5244-
#[cargo_test]
5244+
#[cargo_test(requires_host_split_debuginfo = "packed")]
52455245
#[cfg(target_os = "linux")]
52465246
fn uplift_dwp_of_bin_on_linux() {
52475247
let p = project()

0 commit comments

Comments
 (0)