37
37
//! cargo:rustc-check-cfg=cfg(arm_isa, values("a64", "a32", "t32"))
38
38
//! cargo:rustc-check-cfg=cfg(arm_architecture, values("v4t", "v5te", "v6-m", "v7-m", "v7e-m", "v8-m.base", "v8-m.main", "v7-r", "v8-r", "v7-a", "v8-a"))
39
39
//! cargo:rustc-check-cfg=cfg(arm_profile, values("a", "r", "m", "legacy"))
40
+ //! cargo:rustc-check-cfg=cfg(arm_abi, values("eabi", "eabihf"))
40
41
//! ```
41
42
42
43
#[ derive( Default ) ]
43
44
pub struct TargetInfo {
44
45
isa : Option < Isa > ,
45
46
arch : Option < Arch > ,
46
47
profile : Option < Profile > ,
48
+ abi : Option < Abi > ,
47
49
}
48
50
49
51
impl TargetInfo {
@@ -61,6 +63,11 @@ impl TargetInfo {
61
63
pub fn profile ( & self ) -> Option < Profile > {
62
64
self . profile
63
65
}
66
+
67
+ /// Get the ABI of the target
68
+ pub fn abi ( & self ) -> Option < Abi > {
69
+ self . abi
70
+ }
64
71
}
65
72
66
73
/// Process the ${TARGET} environment variable, and emit cargo configuration to
@@ -99,6 +106,16 @@ pub fn process_target(target: &str) -> TargetInfo {
99
106
r#"cargo:rustc-check-cfg=cfg(arm_profile, values({}))"# ,
100
107
Profile :: values( )
101
108
) ;
109
+
110
+ if let Some ( abi) = Abi :: get ( target) {
111
+ println ! ( r#"cargo:rustc-cfg=arm_abi="{}""# , abi) ;
112
+ target_info. abi = Some ( abi) ;
113
+ }
114
+ println ! (
115
+ r#"cargo:rustc-check-cfg=cfg(arm_abi, values({}))"# ,
116
+ Abi :: values( )
117
+ ) ;
118
+
102
119
target_info
103
120
}
104
121
@@ -314,3 +331,53 @@ impl core::fmt::Display for Profile {
314
331
)
315
332
}
316
333
}
334
+
335
+ /// The ABI
336
+ #[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
337
+ pub enum Abi {
338
+ /// Arm Embedded ABI
339
+ Eabi ,
340
+ /// Arm Embedded ABI with Hard Float
341
+ EabiHf ,
342
+ }
343
+
344
+ impl Abi {
345
+ /// Decode a target string
346
+ pub fn get ( target : & str ) -> Option < Abi > {
347
+ if Arch :: get ( target) . is_none ( ) {
348
+ // Don't give an ABI for non-Arm targets
349
+ //
350
+ // e.g. PowerPC also has an ABI called EABI, but it's not the same
351
+ return None ;
352
+ }
353
+ if target. ends_with ( "-eabi" ) {
354
+ Some ( Abi :: Eabi )
355
+ } else if target. ends_with ( "-eabihf" ) {
356
+ Some ( Abi :: EabiHf )
357
+ } else {
358
+ None
359
+ }
360
+ }
361
+
362
+ /// Get a comma-separated list of values, suitable for cfg-check
363
+ pub fn values ( ) -> String {
364
+ let string_versions: Vec < String > = [ Abi :: Eabi , Abi :: EabiHf ]
365
+ . iter ( )
366
+ . map ( |i| format ! ( r#""{i}""# ) )
367
+ . collect ( ) ;
368
+ string_versions. join ( ", " )
369
+ }
370
+ }
371
+
372
+ impl core:: fmt:: Display for Abi {
373
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
374
+ write ! (
375
+ f,
376
+ "{}" ,
377
+ match self {
378
+ Abi :: Eabi => "eabi" ,
379
+ Abi :: EabiHf => "eabihf" ,
380
+ }
381
+ )
382
+ }
383
+ }
0 commit comments