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 ;
@@ -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.
0 commit comments