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 ;
@@ -442,6 +443,7 @@ pub fn create_bcx<'a, 'gctx>(
442
443
& units,
443
444
& scrape_units,
444
445
host_kind_requested. then_some ( explicit_host_kind) ,
446
+ & target_data,
445
447
) ;
446
448
}
447
449
@@ -573,6 +575,7 @@ fn rebuild_unit_graph_shared(
573
575
roots : & [ Unit ] ,
574
576
scrape_units : & [ Unit ] ,
575
577
to_host : Option < CompileKind > ,
578
+ target_data : & RustcTargetData < ' _ > ,
576
579
) -> ( Vec < Unit > , Vec < Unit > , UnitGraph ) {
577
580
let mut result = UnitGraph :: new ( ) ;
578
581
// Map of the old unit to the new unit, used to avoid recursing into units
@@ -589,6 +592,7 @@ fn rebuild_unit_graph_shared(
589
592
root,
590
593
false ,
591
594
to_host,
595
+ target_data,
592
596
)
593
597
} )
594
598
. collect ( ) ;
@@ -615,6 +619,7 @@ fn traverse_and_share(
615
619
unit : & Unit ,
616
620
unit_is_for_host : bool ,
617
621
to_host : Option < CompileKind > ,
622
+ target_data : & RustcTargetData < ' _ > ,
618
623
) -> Unit {
619
624
if let Some ( new_unit) = memo. get ( unit) {
620
625
// Already computed, no need to recompute.
@@ -632,6 +637,7 @@ fn traverse_and_share(
632
637
& dep. unit ,
633
638
dep. unit_for . is_for_host ( ) ,
634
639
to_host,
640
+ target_data,
635
641
) ;
636
642
new_dep_unit. hash ( & mut dep_hash) ;
637
643
UnitDep {
@@ -655,8 +661,13 @@ fn traverse_and_share(
655
661
_ => unit. kind ,
656
662
} ;
657
663
664
+ let cfg = target_data. cfg ( unit. kind ) ;
665
+ let is_target_windows_msvc = cfg. contains ( & Cfg :: Name ( "windows" . to_string ( ) ) )
666
+ && cfg. contains ( & Cfg :: KeyPair ( "target_env" . to_string ( ) , "msvc" . to_string ( ) ) ) ;
658
667
let mut profile = unit. profile . clone ( ) ;
659
- if profile. strip . is_deferred ( ) {
668
+ // For MSVC, rustc currently treats -Cstrip=debuginfo same as -Cstrip=symbols, which causes
669
+ // this optimization to also remove symbols and thus break backtraces.
670
+ if profile. strip . is_deferred ( ) && !is_target_windows_msvc {
660
671
// If strip was not manually set, and all dependencies of this unit together
661
672
// with this unit have debuginfo turned off, we enable debuginfo stripping.
662
673
// This will remove pre-existing debug symbols coming from the standard library.
0 commit comments