Skip to content

Commit 329c9d9

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 splits split-debuginfo support detection for respective options (off, packed, unpacked).
1 parent df56877 commit 329c9d9

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed

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

+25-5
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ 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+
/// Whether or not rustc supports the `-Csplit-debuginfo=off` flag.
59+
pub supports_split_debuginfo_off: bool,
60+
/// Whether or not rustc supports the `-Csplit-debuginfo=packed` flag.
61+
pub supports_split_debuginfo_packed: bool,
62+
/// Whether or not rustc supports the `-Csplit-debuginfo=unpacked` flag.
63+
pub supports_split_debuginfo_unpacked: bool,
6064
}
6165

6266
/// Kind of each file generated by a Unit, part of `FileType`.
@@ -199,14 +203,28 @@ impl TargetInfo {
199203
process.arg("--crate-type").arg(crate_type.as_str());
200204
}
201205

202-
// An extra `rustc` call to determine `-Csplit-debuginfo=packed` support.
203-
let supports_split_debuginfo = rustc
206+
// 3 extra `rustc` calls to determine `-Csplit-debuginfo={off,packed,unpacked}` support.
207+
let supports_split_debuginfo_off = rustc
208+
.cached_output(
209+
process.clone().arg("-Csplit-debuginfo=off"),
210+
extra_fingerprint,
211+
)
212+
.is_ok();
213+
214+
let supports_split_debuginfo_packed = rustc
204215
.cached_output(
205216
process.clone().arg("-Csplit-debuginfo=packed"),
206217
extra_fingerprint,
207218
)
208219
.is_ok();
209220

221+
let supports_split_debuginfo_unpacked = rustc
222+
.cached_output(
223+
process.clone().arg("-Csplit-debuginfo=unpacked"),
224+
extra_fingerprint,
225+
)
226+
.is_ok();
227+
210228
process.arg("--print=sysroot");
211229
process.arg("--print=cfg");
212230

@@ -303,7 +321,9 @@ impl TargetInfo {
303321
Flags::Rustdoc,
304322
)?,
305323
cfg,
306-
supports_split_debuginfo,
324+
supports_split_debuginfo_off,
325+
supports_split_debuginfo_packed,
326+
supports_split_debuginfo_unpacked,
307327
});
308328
}
309329
}

src/cargo/core/compiler/mod.rs

+25-4
Original file line numberDiff line numberDiff line change
@@ -894,10 +894,31 @@ 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+
let is_supported_off = cx
903+
.bcx
904+
.target_data
905+
.info(unit.kind)
906+
.supports_split_debuginfo_off
907+
&& split == "off";
908+
let is_supported_packed = cx
909+
.bcx
910+
.target_data
911+
.info(unit.kind)
912+
.supports_split_debuginfo_packed
913+
&& split == "packed";
914+
let is_supported_unpacked = cx
915+
.bcx
916+
.target_data
917+
.info(unit.kind)
918+
.supports_split_debuginfo_unpacked
919+
&& split == "unpacked";
920+
921+
if is_supported_off || is_supported_packed || is_supported_unpacked {
901922
cmd.arg("-C").arg(format!("split-debuginfo={}", split));
902923
}
903924
}

0 commit comments

Comments
 (0)