35
35
//! [`drain_the_queue`]: crate::core::compiler::job_queue
36
36
//! ["Cargo Target"]: https://doc.rust-lang.org/nightly/cargo/reference/cargo-targets.html
37
37
38
+ use cargo_platform:: Cfg ;
38
39
use std:: collections:: { HashMap , HashSet } ;
39
40
use std:: hash:: { Hash , Hasher } ;
40
41
use std:: sync:: Arc ;
@@ -436,6 +437,7 @@ pub fn create_bcx<'a, 'gctx>(
436
437
& units,
437
438
& scrape_units,
438
439
host_kind_requested. then_some ( explicit_host_kind) ,
440
+ & target_data,
439
441
) ;
440
442
441
443
let mut extra_compiler_args = HashMap :: new ( ) ;
@@ -575,6 +577,7 @@ fn rebuild_unit_graph_shared(
575
577
roots : & [ Unit ] ,
576
578
scrape_units : & [ Unit ] ,
577
579
to_host : Option < CompileKind > ,
580
+ target_data : & RustcTargetData < ' _ > ,
578
581
) -> ( Vec < Unit > , Vec < Unit > , UnitGraph ) {
579
582
let mut result = UnitGraph :: new ( ) ;
580
583
// Map of the old unit to the new unit, used to avoid recursing into units
@@ -591,6 +594,7 @@ fn rebuild_unit_graph_shared(
591
594
root,
592
595
false ,
593
596
to_host,
597
+ target_data,
594
598
)
595
599
} )
596
600
. collect ( ) ;
@@ -617,6 +621,7 @@ fn traverse_and_share(
617
621
unit : & Unit ,
618
622
unit_is_for_host : bool ,
619
623
to_host : Option < CompileKind > ,
624
+ target_data : & RustcTargetData < ' _ > ,
620
625
) -> Unit {
621
626
if let Some ( new_unit) = memo. get ( unit) {
622
627
// Already computed, no need to recompute.
@@ -634,6 +639,7 @@ fn traverse_and_share(
634
639
& dep. unit ,
635
640
dep. unit_for . is_for_host ( ) ,
636
641
to_host,
642
+ target_data,
637
643
) ;
638
644
new_dep_unit. hash ( & mut dep_hash) ;
639
645
UnitDep {
@@ -657,8 +663,13 @@ fn traverse_and_share(
657
663
_ => unit. kind ,
658
664
} ;
659
665
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 ( ) ) ) ;
660
669
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 {
662
673
// If strip was not manually set, and all dependencies of this unit together
663
674
// with this unit have debuginfo turned off, we enable debuginfo stripping.
664
675
// This will remove pre-existing debug symbols coming from the standard library.
0 commit comments