From 9e0746492d1e252eae29108c5dd9456ddc5b6e97 Mon Sep 17 00:00:00 2001 From: bors Date: Thu, 26 Jan 2023 18:14:08 +0000 Subject: [PATCH] Auto merge of #11347 - kamirr:fix-split-debuginfo-windows, r=weihanglo 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`. Consider an empty project with the following change to `Cargo.toml`: ```toml [profile.dev] split-debuginfo="unpacked" ``` `cargo +1.64.0 build` will work, but `cargo +1.65.0 build` will fail with the following error message: ``` PS C:\REDACTED> cargo build Compiling tmp v0.1.0 (C:\REDACTED) error: `-Csplit-debuginfo=unpacked` is unstable on this platform error: could not compile `tmp` due to previous error ``` With this patch and 1.65.0 rustc, cargo will ignore all `split-debuginfo` settings, but with https://github.com/rust-lang/rust/pull/104104 rustc (approved, awaiting merge), it will properly detect supported values for `split-debuginfo` and only ignore those that are unsupported. --- src/cargo/core/compiler/build_context/target_info.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index 754adcf3c..298900f1b 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -168,6 +168,18 @@ impl TargetInfo { loop { let extra_fingerprint = kind.fingerprint_hash(); + // Query rustc for supported -Csplit-debuginfo values + let support_split_debuginfo = rustc + .cached_output( + rustc.workspace_process().arg("--print=split-debuginfo"), + extra_fingerprint, + ) + .unwrap_or_default() + .0 + .lines() + .map(String::from) + .collect(); + // Query rustc for several kinds of info from each line of output: // 0) file-names (to determine output file prefix/suffix for given crate type) // 1) sysroot