Skip to content

Commit de87e7c

Browse files
committed
Do not strip debuginfo by default for MSVC
1 parent 7ff7e34 commit de87e7c

File tree

1 file changed

+11
-1
lines changed
  • src/cargo/ops/cargo_compile

1 file changed

+11
-1
lines changed

src/cargo/ops/cargo_compile/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ pub fn create_bcx<'a, 'gctx>(
436436
&units,
437437
&scrape_units,
438438
host_kind_requested.then_some(explicit_host_kind),
439+
&target_data,
439440
);
440441

441442
let mut extra_compiler_args = HashMap::new();
@@ -575,6 +576,7 @@ fn rebuild_unit_graph_shared(
575576
roots: &[Unit],
576577
scrape_units: &[Unit],
577578
to_host: Option<CompileKind>,
579+
target_data: &RustcTargetData<'_>,
578580
) -> (Vec<Unit>, Vec<Unit>, UnitGraph) {
579581
let mut result = UnitGraph::new();
580582
// Map of the old unit to the new unit, used to avoid recursing into units
@@ -591,6 +593,7 @@ fn rebuild_unit_graph_shared(
591593
root,
592594
false,
593595
to_host,
596+
target_data,
594597
)
595598
})
596599
.collect();
@@ -617,6 +620,7 @@ fn traverse_and_share(
617620
unit: &Unit,
618621
unit_is_for_host: bool,
619622
to_host: Option<CompileKind>,
623+
target_data: &RustcTargetData<'_>,
620624
) -> Unit {
621625
if let Some(new_unit) = memo.get(unit) {
622626
// Already computed, no need to recompute.
@@ -634,6 +638,7 @@ fn traverse_and_share(
634638
&dep.unit,
635639
dep.unit_for.is_for_host(),
636640
to_host,
641+
target_data,
637642
);
638643
new_dep_unit.hash(&mut dep_hash);
639644
UnitDep {
@@ -657,8 +662,13 @@ fn traverse_and_share(
657662
_ => unit.kind,
658663
};
659664

665+
let is_target_windows_msvc = target_data
666+
.short_name(&unit.kind)
667+
.ends_with("-pc-windows-msvc");
660668
let mut profile = unit.profile.clone();
661-
if profile.strip.is_deferred() {
669+
// For MSVC, rustc currently treats -Cstrip=debuginfo same as -Cstrip=symbols, which causes
670+
// this optimization to also remove symbols and thus break backtraces.
671+
if profile.strip.is_deferred() && !is_target_windows_msvc {
662672
// If strip was not manually set, and all dependencies of this unit together
663673
// with this unit have debuginfo turned off, we enable debuginfo stripping.
664674
// This will remove pre-existing debug symbols coming from the standard library.

0 commit comments

Comments
 (0)