@@ -183,6 +183,7 @@ struct Crate {
183183 deps : HashSet < String > ,
184184 path : PathBuf ,
185185 has_lib : bool ,
186+ features : Vec < String > ,
186187}
187188
188189impl Crate {
@@ -666,16 +667,24 @@ impl Build {
666667 }
667668
668669 /// Gets the space-separated set of activated features for the compiler.
669- fn rustc_features ( & self , kind : Kind , target : TargetSelection ) -> String {
670+ fn rustc_features ( & self , kind : Kind , target : TargetSelection , crates : & [ String ] ) -> String {
671+ let possible_features_by_crates: HashSet < _ > = crates
672+ . iter ( )
673+ . flat_map ( |krate| & self . crates [ krate] . features )
674+ . map ( std:: ops:: Deref :: deref)
675+ . collect ( ) ;
676+ let check = |feature : & str | -> bool {
677+ crates. is_empty ( ) || possible_features_by_crates. contains ( feature)
678+ } ;
670679 let mut features = vec ! [ ] ;
671- if self . config . jemalloc {
680+ if self . config . jemalloc && check ( "jemalloc" ) {
672681 features. push ( "jemalloc" ) ;
673682 }
674- if self . config . llvm_enabled ( target) || kind == Kind :: Check {
683+ if ( self . config . llvm_enabled ( target) || kind == Kind :: Check ) && check ( "llvm" ) {
675684 features. push ( "llvm" ) ;
676685 }
677686 // keep in sync with `bootstrap/compile.rs:rustc_cargo_env`
678- if self . config . rustc_parallel {
687+ if self . config . rustc_parallel && check ( "rustc_use_parallel_compiler" ) {
679688 features. push ( "rustc_use_parallel_compiler" ) ;
680689 }
681690
@@ -684,7 +693,7 @@ impl Build {
684693 // which is everything (including debug/trace/etc.)
685694 // if its unset, if debug_assertions is on, then debug_logging will also be on
686695 // as well as tracing *ignoring* this feature when debug_assertions is on
687- if !self . config . rust_debug_logging {
696+ if !self . config . rust_debug_logging && check ( "max_level_info" ) {
688697 features. push ( "max_level_info" ) ;
689698 }
690699
0 commit comments