Skip to content

Commit 856ed94

Browse files
committed
Fix split-debuginfo support detection
cargo assumed that if -Csplit-debuginfo=packed worked, all values would be correct. This however is not the case -- as of Rust 1.65.0, rustc supports packed, but not unpacked or off on Windows. Because of this, having split-debuginfo="unpacked" on Windows has caused builds to fail, as cargo assumed that the option is fine (split-debuginfo=packed worked), but rustc then failed when being passed -Csplit-debuginfo=unpacked. This patch invokes rustc with the --print=split-debuginfo to query supported values and ignores the Cargo.toml entry if not supported.
1 parent df56877 commit 856ed94

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ pub struct TargetInfo {
5555
pub rustflags: Vec<String>,
5656
/// Extra flags to pass to `rustdoc`, see [`extra_args`].
5757
pub rustdocflags: Vec<String>,
58-
/// Whether or not rustc supports the `-Csplit-debuginfo` flag.
59-
pub supports_split_debuginfo: bool,
58+
/// Supported values for `-Csplit-debuginfo=` flag, queried from rustc
59+
pub support_split_debuginfo: Vec<String>,
6060
}
6161

6262
/// Kind of each file generated by a Unit, part of `FileType`.
@@ -167,6 +167,18 @@ impl TargetInfo {
167167
loop {
168168
let extra_fingerprint = kind.fingerprint_hash();
169169

170+
// Query rustc for supported -Csplit-debuginfo values
171+
let support_split_debuginfo = rustc
172+
.cached_output(
173+
rustc.workspace_process().arg("--print=split-debuginfo"),
174+
extra_fingerprint,
175+
)
176+
.unwrap_or_default()
177+
.0
178+
.lines()
179+
.map(String::from)
180+
.collect();
181+
170182
// Query rustc for several kinds of info from each line of output:
171183
// 0) file-names (to determine output file prefix/suffix for given crate type)
172184
// 1) sysroot
@@ -199,14 +211,6 @@ impl TargetInfo {
199211
process.arg("--crate-type").arg(crate_type.as_str());
200212
}
201213

202-
// An extra `rustc` call to determine `-Csplit-debuginfo=packed` support.
203-
let supports_split_debuginfo = rustc
204-
.cached_output(
205-
process.clone().arg("-Csplit-debuginfo=packed"),
206-
extra_fingerprint,
207-
)
208-
.is_ok();
209-
210214
process.arg("--print=sysroot");
211215
process.arg("--print=cfg");
212216

@@ -303,7 +307,7 @@ impl TargetInfo {
303307
Flags::Rustdoc,
304308
)?,
305309
cfg,
306-
supports_split_debuginfo,
310+
support_split_debuginfo,
307311
});
308312
}
309313
}

src/cargo/core/compiler/mod.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -894,10 +894,20 @@ fn build_base_args(
894894
cmd.args(&lto_args(cx, unit));
895895

896896
// This is generally just an optimization on build time so if we don't pass
897-
// it then it's ok. As of the time of this writing it's a very new flag, so
898-
// we need to dynamically check if it's available.
899-
if cx.bcx.target_data.info(unit.kind).supports_split_debuginfo {
900-
if let Some(split) = split_debuginfo {
897+
// it then it's ok. The values for the flag (off, packed, unpacked) may be supported
898+
// or not depending on the platform, so availability is checked per-value.
899+
// For example, at the time of writing this code, on Windows the only stable valid
900+
// value for split-debuginfo is "packed", while on Linux "unpacked" is also stable.
901+
if let Some(split) = split_debuginfo {
902+
if cx
903+
.bcx
904+
.target_data
905+
.info(unit.kind)
906+
.support_split_debuginfo
907+
.iter()
908+
.find(|sup| sup.as_str() == split.as_str())
909+
.is_some()
910+
{
901911
cmd.arg("-C").arg(format!("split-debuginfo={}", split));
902912
}
903913
}

0 commit comments

Comments
 (0)