@@ -23,7 +23,10 @@ pub struct TargetSpec {
23
23
pub vendor : Option < String > ,
24
24
pub env : Option < String > ,
25
25
pub abi : Option < String > ,
26
+ pub target_pointer_width : String ,
26
27
pub pre_link_args : Option < PreLinkArgs > ,
28
+ #[ serde( skip) ]
29
+ pub cfgs : Cfgs ,
27
30
}
28
31
29
32
#[ derive( Debug , Deserialize ) ]
@@ -32,3 +35,49 @@ pub struct RustcTargetSpecs(
32
35
/// First field in the tuple is the rustc target
33
36
pub BTreeMap < String , TargetSpec > ,
34
37
) ;
38
+
39
+ /// Potentially useful values from:
40
+ /// https://doc.rust-lang.org/reference/conditional-compilation.html
41
+ ///
42
+ /// That are not directly / easily exposed in `TargetSpec`.
43
+ #[ derive( Debug , Default ) ]
44
+ pub struct Cfgs {
45
+ pub target_features : Vec < String > ,
46
+ pub target_families : Vec < String > ,
47
+ pub target_endian : String ,
48
+ pub target_atomics : Vec < String > ,
49
+ pub target_thread_local : bool ,
50
+ }
51
+
52
+ impl Cfgs {
53
+ pub fn parse ( cfgs : & [ String ] ) -> Self {
54
+ let mut target_features = vec ! [ ] ;
55
+ let mut target_families = vec ! [ ] ;
56
+ let mut target_endian = None ;
57
+ let mut target_atomics = vec ! [ ] ;
58
+ let mut target_thread_local = false ;
59
+ for cfg in cfgs {
60
+ let ( name, value) = cfg
61
+ . split_once ( '=' )
62
+ . map ( |( n, v) | ( n. trim ( ) , Some ( v. trim ( ) . trim_matches ( '"' ) ) ) )
63
+ . unwrap_or ( ( cfg. trim ( ) , None ) ) ;
64
+
65
+ match ( name, value) {
66
+ ( "target_feature" , Some ( value) ) => target_features. push ( value. to_string ( ) ) ,
67
+ ( "target_family" , Some ( value) ) => target_families. push ( value. to_string ( ) ) ,
68
+ ( "target_endian" , Some ( value) ) => target_endian = Some ( value. to_string ( ) ) ,
69
+ ( "target_has_atomic" , Some ( value) ) => target_atomics. push ( value. to_string ( ) ) ,
70
+ ( "target_thread_local" , None ) => target_thread_local = true ,
71
+ _ => { } // Ignore the rest
72
+ }
73
+ }
74
+
75
+ Self {
76
+ target_features,
77
+ target_families,
78
+ target_endian : target_endian. expect ( "must have target_endian cfg" ) ,
79
+ target_atomics,
80
+ target_thread_local,
81
+ }
82
+ }
83
+ }
0 commit comments