Skip to content

Commit d273f0d

Browse files
committed
arm-targets: Add ABI
1 parent c5c20c4 commit d273f0d

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

arm-targets/src/lib.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@
3737
//! cargo:rustc-check-cfg=cfg(arm_isa, values("a64", "a32", "t32"))
3838
//! 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"))
3939
//! cargo:rustc-check-cfg=cfg(arm_profile, values("a", "r", "m", "legacy"))
40+
//! cargo:rustc-check-cfg=cfg(arm_abi, values("eabi", "eabihf"))
4041
//! ```
4142
4243
#[derive(Default)]
4344
pub struct TargetInfo {
4445
isa: Option<Isa>,
4546
arch: Option<Arch>,
4647
profile: Option<Profile>,
48+
abi: Option<Abi>,
4749
}
4850

4951
impl TargetInfo {
@@ -61,6 +63,11 @@ impl TargetInfo {
6163
pub fn profile(&self) -> Option<Profile> {
6264
self.profile
6365
}
66+
67+
/// Get the ABI of the target
68+
pub fn abi(&self) -> Option<Abi> {
69+
self.abi
70+
}
6471
}
6572

6673
/// Process the ${TARGET} environment variable, and emit cargo configuration to
@@ -99,6 +106,16 @@ pub fn process_target(target: &str) -> TargetInfo {
99106
r#"cargo:rustc-check-cfg=cfg(arm_profile, values({}))"#,
100107
Profile::values()
101108
);
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+
102119
target_info
103120
}
104121

@@ -314,3 +331,53 @@ impl core::fmt::Display for Profile {
314331
)
315332
}
316333
}
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

Comments
 (0)