@@ -944,6 +944,9 @@ pub struct RustcTargetData<'gctx> {
944944 target_config : HashMap < CompileTarget , TargetConfig > ,
945945 /// Information about the target platform that we're building for.
946946 target_info : HashMap < CompileTarget , TargetInfo > ,
947+
948+ /// `--print=cfg`
949+ check_cfg : CheckCfg ,
947950}
948951
949952impl < ' gctx > RustcTargetData < ' gctx > {
@@ -990,6 +993,35 @@ impl<'gctx> RustcTargetData<'gctx> {
990993 }
991994 } ;
992995
996+ let check_cfg = {
997+ let mut process = rustc. workspace_process ( ) ;
998+
999+ apply_env_config ( gctx, & mut process) ?;
1000+ process
1001+ . arg ( "-" )
1002+ . arg ( "--print=check-cfg" )
1003+ . arg ( "--check-cfg=cfg()" )
1004+ . arg ( "-Zunstable-options" )
1005+ . env_remove ( "RUSTC_LOG" ) ;
1006+
1007+ // Removes `FD_CLOEXEC` set by `jobserver::Client` to pass jobserver
1008+ // as environment variables specify.
1009+ if let Some ( client) = gctx. jobserver_from_env ( ) {
1010+ process. inherit_jobserver ( client) ;
1011+ }
1012+
1013+ let ( output, _error) = rustc
1014+ . cached_output ( & process, 0 )
1015+ . with_context ( || "failed to run `rustc` to learn about check-cfg information" ) ?;
1016+
1017+ let lines = output. lines ( ) ;
1018+
1019+ lines. fold ( CheckCfg :: default ( ) , |mut check_cfg, line| {
1020+ check_cfg. process_line ( line) ;
1021+ check_cfg
1022+ } )
1023+ } ;
1024+
9931025 let mut res = RustcTargetData {
9941026 rustc,
9951027 gctx,
@@ -998,6 +1030,7 @@ impl<'gctx> RustcTargetData<'gctx> {
9981030 host_info,
9991031 target_config,
10001032 target_info,
1033+ check_cfg,
10011034 } ;
10021035
10031036 // Get all kinds we currently know about.
@@ -1074,6 +1107,11 @@ impl<'gctx> RustcTargetData<'gctx> {
10741107 self . info ( kind) . cfg ( )
10751108 }
10761109
1110+ /// Gets the list of check-cfg
1111+ pub fn check_cfg ( & self ) -> & CheckCfg {
1112+ & self . check_cfg
1113+ }
1114+
10771115 /// Information about the given target platform, learned by querying rustc.
10781116 ///
10791117 /// # Panics
0 commit comments