@@ -376,6 +376,7 @@ pub struct Config {
376376 pub only_modified : bool ,
377377
378378 pub target_cfgs : OnceLock < TargetCfgs > ,
379+ pub builtin_cfg_names : OnceLock < HashSet < String > > ,
379380
380381 pub nocapture : bool ,
381382
@@ -440,6 +441,11 @@ impl Config {
440441 self . target_cfg ( ) . panic == PanicStrategy :: Unwind
441442 }
442443
444+ /// Get the list of builtin, 'well known' cfg names
445+ pub fn builtin_cfg_names ( & self ) -> & HashSet < String > {
446+ self . builtin_cfg_names . get_or_init ( || builtin_cfg_names ( self ) )
447+ }
448+
443449 pub fn has_threads ( & self ) -> bool {
444450 // Wasm targets don't have threads unless `-threads` is in the target
445451 // name, such as `wasm32-wasip1-threads`.
@@ -651,6 +657,17 @@ pub enum Endian {
651657 Big ,
652658}
653659
660+ fn builtin_cfg_names ( config : & Config ) -> HashSet < String > {
661+ rustc_output (
662+ config,
663+ & [ "--print=check-cfg" , "-Zunstable-options" , "--check-cfg=cfg()" ] ,
664+ Default :: default ( ) ,
665+ )
666+ . lines ( )
667+ . map ( |l| if let Some ( ( name, _) ) = l. split_once ( '=' ) { name. to_string ( ) } else { l. to_string ( ) } )
668+ . collect ( )
669+ }
670+
654671fn rustc_output ( config : & Config , args : & [ & str ] , envs : HashMap < String , String > ) -> String {
655672 let mut command = Command :: new ( & config. rustc_path ) ;
656673 add_dylib_path ( & mut command, iter:: once ( & config. compile_lib_path ) ) ;
0 commit comments