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 ;
3839use std:: collections:: { HashMap , HashSet } ;
3940use std:: hash:: { Hash , Hasher } ;
4041use std:: sync:: Arc ;
@@ -443,6 +444,7 @@ pub fn create_bcx<'a, 'cfg>(
443444 & units,
444445 & scrape_units,
445446 host_kind_requested. then_some ( explicit_host_kind) ,
447+ & target_data,
446448 ) ;
447449 }
448450
@@ -574,6 +576,7 @@ fn rebuild_unit_graph_shared(
574576 roots : & [ Unit ] ,
575577 scrape_units : & [ Unit ] ,
576578 to_host : Option < CompileKind > ,
579+ target_data : & RustcTargetData < ' _ > ,
577580) -> ( Vec < Unit > , Vec < Unit > , UnitGraph ) {
578581 let mut result = UnitGraph :: new ( ) ;
579582 // Map of the old unit to the new unit, used to avoid recursing into units
@@ -590,6 +593,7 @@ fn rebuild_unit_graph_shared(
590593 root,
591594 false ,
592595 to_host,
596+ target_data,
593597 )
594598 } )
595599 . collect ( ) ;
@@ -616,6 +620,7 @@ fn traverse_and_share(
616620 unit : & Unit ,
617621 unit_is_for_host : bool ,
618622 to_host : Option < CompileKind > ,
623+ target_data : & RustcTargetData < ' _ > ,
619624) -> Unit {
620625 if let Some ( new_unit) = memo. get ( unit) {
621626 // Already computed, no need to recompute.
@@ -633,6 +638,7 @@ fn traverse_and_share(
633638 & dep. unit ,
634639 dep. unit_for . is_for_host ( ) ,
635640 to_host,
641+ target_data,
636642 ) ;
637643 new_dep_unit. hash ( & mut dep_hash) ;
638644 UnitDep {
@@ -656,8 +662,13 @@ fn traverse_and_share(
656662 _ => unit. kind ,
657663 } ;
658664
665+ let cfg = target_data. cfg ( unit. kind ) ;
666+ let is_target_windows_msvc = cfg. contains ( & Cfg :: Name ( "windows" . to_string ( ) ) )
667+ && cfg. contains ( & Cfg :: KeyPair ( "target_env" . to_string ( ) , "msvc" . to_string ( ) ) ) ;
659668 let mut profile = unit. profile . clone ( ) ;
660- 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 {
661672 // If strip was not manually set, and all dependencies of this unit together
662673 // with this unit have debuginfo turned off, we enable debuginfo stripping.
663674 // This will remove pre-existing debug symbols coming from the standard library.
0 commit comments