@@ -44,6 +44,8 @@ pub struct TargetInfo {
44
44
crate_types : RefCell < HashMap < CrateType , Option < ( String , String ) > > > ,
45
45
/// `cfg` information extracted from `rustc --print=cfg`.
46
46
cfg : Vec < Cfg > ,
47
+ /// `target_spec` information extracted from `rustc --print=target-spec-json`
48
+ pub target_spec : TargetSpec ,
47
49
/// Supported values for `-Csplit-debuginfo=` flag, queried from rustc
48
50
support_split_debuginfo : Vec < String > ,
49
51
/// Path to the sysroot.
@@ -62,6 +64,16 @@ pub struct TargetInfo {
62
64
pub support_check_cfg : bool ,
63
65
}
64
66
67
+ #[ derive( Deserialize , Clone ) ]
68
+ pub struct Metadata {
69
+ pub std : Option < bool > ,
70
+ }
71
+
72
+ #[ derive( Deserialize , Clone ) ]
73
+ pub struct TargetSpec {
74
+ pub metadata : Metadata ,
75
+ }
76
+
65
77
/// Kind of each file generated by a Unit, part of `FileType`.
66
78
#[ derive( Clone , PartialEq , Eq , Debug ) ]
67
79
pub enum FileFlavor {
@@ -175,9 +187,11 @@ impl TargetInfo {
175
187
let mut process = rustc. workspace_process ( ) ;
176
188
apply_env_config ( gctx, & mut process) ?;
177
189
process
190
+ . env ( "RUSTC_BOOTSTRAP" , & "1" . to_string ( ) )
178
191
. arg ( "-" )
179
192
. arg ( "--crate-name" )
180
193
. arg ( "___" )
194
+ . arg ( "-Zunstable-options" )
181
195
. arg ( "--print=file-names" )
182
196
. args ( & rustflags)
183
197
. env_remove ( "RUSTC_LOG" ) ;
@@ -215,6 +229,7 @@ impl TargetInfo {
215
229
process. arg ( "--print=sysroot" ) ;
216
230
process. arg ( "--print=split-debuginfo" ) ;
217
231
process. arg ( "--print=crate-name" ) ; // `___` as a delimiter.
232
+ process. arg ( "--print=target-spec-json" ) ;
218
233
process. arg ( "--print=cfg" ) ;
219
234
220
235
let ( output, error) = rustc
@@ -266,6 +281,36 @@ impl TargetInfo {
266
281
res
267
282
} ;
268
283
284
+ let target_spec_json = {
285
+ let mut res: String = String :: new ( ) ;
286
+ loop {
287
+ match lines. next ( ) {
288
+ Some ( line) if line == "}" => {
289
+ res. push_str ( "}" ) ;
290
+ break ;
291
+ }
292
+ Some ( line) => res. push_str ( line. into ( ) ) ,
293
+ None => {
294
+ return error_missing_print_output (
295
+ "target-spec-json" ,
296
+ & process,
297
+ & output,
298
+ & error,
299
+ )
300
+ }
301
+ }
302
+ }
303
+ res
304
+ } ;
305
+
306
+ let target_spec: TargetSpec = serde_json:: from_str ( & target_spec_json. as_str ( ) )
307
+ . with_context ( || {
308
+ format ! (
309
+ "failed to parse target spec from `rustc --print=target-spec-json`, got:\n {}" ,
310
+ output
311
+ )
312
+ } ) ?;
313
+
269
314
let cfg = lines
270
315
. map ( |line| Ok ( Cfg :: from_str ( line) ?) )
271
316
. filter ( TargetInfo :: not_user_specific_cfg)
@@ -322,6 +367,7 @@ impl TargetInfo {
322
367
Flags :: Rustdoc ,
323
368
) ?,
324
369
cfg,
370
+ target_spec,
325
371
support_split_debuginfo,
326
372
support_check_cfg,
327
373
} ) ;
@@ -1026,6 +1072,11 @@ impl<'gctx> RustcTargetData<'gctx> {
1026
1072
pub fn script_override ( & self , lib_name : & str , kind : CompileKind ) -> Option < & BuildOutput > {
1027
1073
self . target_config ( kind) . links_overrides . get ( lib_name)
1028
1074
}
1075
+
1076
+ /// Gets the target info hashmap from the target data.
1077
+ pub fn target_info ( & self ) -> & HashMap < CompileTarget , TargetInfo > {
1078
+ & self . target_info
1079
+ }
1029
1080
}
1030
1081
1031
1082
/// Structure used to deal with Rustdoc fingerprinting
0 commit comments