@@ -944,6 +944,9 @@ pub struct RustcTargetData<'gctx> {
944
944
target_config : HashMap < CompileTarget , TargetConfig > ,
945
945
/// Information about the target platform that we're building for.
946
946
target_info : HashMap < CompileTarget , TargetInfo > ,
947
+
948
+ /// `--print=cfg`
949
+ check_cfg : CheckCfg ,
947
950
}
948
951
949
952
impl < ' gctx > RustcTargetData < ' gctx > {
@@ -990,6 +993,35 @@ impl<'gctx> RustcTargetData<'gctx> {
990
993
}
991
994
} ;
992
995
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
+
993
1025
let mut res = RustcTargetData {
994
1026
rustc,
995
1027
gctx,
@@ -998,6 +1030,7 @@ impl<'gctx> RustcTargetData<'gctx> {
998
1030
host_info,
999
1031
target_config,
1000
1032
target_info,
1033
+ check_cfg,
1001
1034
} ;
1002
1035
1003
1036
// Get all kinds we currently know about.
@@ -1074,6 +1107,11 @@ impl<'gctx> RustcTargetData<'gctx> {
1074
1107
self . info ( kind) . cfg ( )
1075
1108
}
1076
1109
1110
+ /// Gets the list of check-cfg
1111
+ pub fn check_cfg ( & self ) -> & CheckCfg {
1112
+ & self . check_cfg
1113
+ }
1114
+
1077
1115
/// Information about the given target platform, learned by querying rustc.
1078
1116
///
1079
1117
/// # Panics
0 commit comments