Skip to content

Commit fa619a9

Browse files
committed
Auto merge of #13630 - Kobzol:msvc-disable-release-strip, r=weihanglo
Do not strip debuginfo by default for MSVC This PR disables the logic which enables debuginfo stripping by default in release mode (#13257) for MSVC, since it causes problems there (rust-lang/rust#122857). I'm not sure if this is the correct way to gate the logic on a specific target triple. The root of the issue is that `-Cstrip=debuginfo` currently behaves like `-Cstrip=symbols` on MSVC, which causes the original optimization to break backtraces on Windows. Ultimately, this should probably be fixed in `rustc`, but that might take some further design work, therefore a faster solution would be to just special case this in Cargo for now, and remove the special case later, once it gets fixed on the `rustc` side. Related issue: rust-lang/rust#122857
2 parents 1f6857d + 53a0dc4 commit fa619a9

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

src/cargo/ops/cargo_compile/mod.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
//! [`drain_the_queue`]: crate::core::compiler::job_queue
3636
//! ["Cargo Target"]: https://doc.rust-lang.org/nightly/cargo/reference/cargo-targets.html
3737
38+
use cargo_platform::Cfg;
3839
use std::collections::{HashMap, HashSet};
3940
use std::hash::{Hash, Hasher};
4041
use std::sync::Arc;
@@ -436,6 +437,7 @@ pub fn create_bcx<'a, 'gctx>(
436437
&units,
437438
&scrape_units,
438439
host_kind_requested.then_some(explicit_host_kind),
440+
&target_data,
439441
);
440442

441443
let mut extra_compiler_args = HashMap::new();
@@ -575,6 +577,7 @@ fn rebuild_unit_graph_shared(
575577
roots: &[Unit],
576578
scrape_units: &[Unit],
577579
to_host: Option<CompileKind>,
580+
target_data: &RustcTargetData<'_>,
578581
) -> (Vec<Unit>, Vec<Unit>, UnitGraph) {
579582
let mut result = UnitGraph::new();
580583
// Map of the old unit to the new unit, used to avoid recursing into units
@@ -591,6 +594,7 @@ fn rebuild_unit_graph_shared(
591594
root,
592595
false,
593596
to_host,
597+
target_data,
594598
)
595599
})
596600
.collect();
@@ -617,6 +621,7 @@ fn traverse_and_share(
617621
unit: &Unit,
618622
unit_is_for_host: bool,
619623
to_host: Option<CompileKind>,
624+
target_data: &RustcTargetData<'_>,
620625
) -> Unit {
621626
if let Some(new_unit) = memo.get(unit) {
622627
// Already computed, no need to recompute.
@@ -634,6 +639,7 @@ fn traverse_and_share(
634639
&dep.unit,
635640
dep.unit_for.is_for_host(),
636641
to_host,
642+
target_data,
637643
);
638644
new_dep_unit.hash(&mut dep_hash);
639645
UnitDep {
@@ -657,8 +663,13 @@ fn traverse_and_share(
657663
_ => unit.kind,
658664
};
659665

666+
let cfg = target_data.cfg(unit.kind);
667+
let is_target_windows_msvc = cfg.contains(&Cfg::Name("windows".to_string()))
668+
&& cfg.contains(&Cfg::KeyPair("target_env".to_string(), "msvc".to_string()));
660669
let mut profile = unit.profile.clone();
661-
if profile.strip.is_deferred() {
670+
// For MSVC, rustc currently treats -Cstrip=debuginfo same as -Cstrip=symbols, which causes
671+
// this optimization to also remove symbols and thus break backtraces.
672+
if profile.strip.is_deferred() && !is_target_windows_msvc {
662673
// If strip was not manually set, and all dependencies of this unit together
663674
// with this unit have debuginfo turned off, we enable debuginfo stripping.
664675
// This will remove pre-existing debug symbols coming from the standard library.

tests/testsuite/profiles.rs

+27
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,9 @@ fn strip_accepts_false_to_disable_strip() {
632632
.run();
633633
}
634634

635+
// Temporarily disabled on Windows due to https://github.com/rust-lang/rust/issues/122857
635636
#[cargo_test]
637+
#[cfg(not(windows))]
636638
fn strip_debuginfo_in_release() {
637639
let p = project()
638640
.file(
@@ -656,7 +658,32 @@ fn strip_debuginfo_in_release() {
656658
.run();
657659
}
658660

661+
// Using -Cstrip=debuginfo in release mode by default is temporarily disabled on Windows due to
662+
// https://github.com/rust-lang/rust/issues/122857
659663
#[cargo_test]
664+
#[cfg(all(target_os = "windows", target_env = "msvc"))]
665+
fn do_not_strip_debuginfo_in_release_on_windows() {
666+
let p = project()
667+
.file(
668+
"Cargo.toml",
669+
r#"
670+
[package]
671+
name = "foo"
672+
version = "0.1.0"
673+
edition = "2015"
674+
"#,
675+
)
676+
.file("src/main.rs", "fn main() {}")
677+
.build();
678+
679+
p.cargo("build --release -v")
680+
.with_stderr_does_not_contain("[..]strip=debuginfo[..]")
681+
.run();
682+
}
683+
684+
// Temporarily disabled on Windows due to https://github.com/rust-lang/rust/issues/122857
685+
#[cargo_test]
686+
#[cfg(not(windows))]
660687
fn strip_debuginfo_without_debug() {
661688
let p = project()
662689
.file(

tests/testsuite/run.rs

+2
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,9 @@ fn one_bin_multiple_examples() {
740740
.run();
741741
}
742742

743+
// Temporarily disabled on Windows due to https://github.com/rust-lang/rust/issues/122857
743744
#[cargo_test]
745+
#[cfg(not(windows))]
744746
fn example_with_release_flag() {
745747
let p = project()
746748
.file(

0 commit comments

Comments
 (0)