22//!
33//! Hopefully Rust will stabilise these kinds of target features, and this won't
44//! be required.
5+ #[ derive( Default ) ]
6+ pub struct TargetInfo {
7+ profile : Option < Profile > ,
8+ arch : Option < Arch > ,
9+ isa : Option < Isa > ,
10+ }
11+
12+ impl TargetInfo {
13+ pub fn profile ( & self ) -> Option < Profile > {
14+ self . profile
15+ }
516
17+ pub fn arch ( & self ) -> Option < Arch > {
18+ self . arch
19+ }
20+
21+ pub fn isa ( & self ) -> Option < Isa > {
22+ self . isa
23+ }
24+ }
625/// Process the ${TARGET} environment variable, and emit cargo configuration to
726/// standard out.
8- pub fn process ( ) {
27+ pub fn process ( ) -> TargetInfo {
928 let target = std:: env:: var ( "TARGET" ) . expect ( "build script TARGET variable" ) ;
10- process_target ( & target) ;
29+ process_target ( & target)
1130}
1231
1332/// Process a given target string, and emit cargo configuration to standard out.
14- pub fn process_target ( target : & str ) {
33+ pub fn process_target ( target : & str ) -> TargetInfo {
34+ let mut target_info = TargetInfo :: default ( ) ;
1535 if let Some ( isa) = Isa :: get ( target) {
1636 println ! ( r#"cargo:rustc-cfg=arm_isa="{}""# , isa) ;
37+ target_info. isa = Some ( isa) ;
1738 }
1839 println ! (
1940 r#"cargo:rustc-check-cfg=cfg(arm_isa, values({}))"# ,
@@ -22,6 +43,7 @@ pub fn process_target(target: &str) {
2243
2344 if let Some ( arch) = Arch :: get ( target) {
2445 println ! ( r#"cargo:rustc-cfg=arm_architecture="{}""# , arch) ;
46+ target_info. arch = Some ( arch) ;
2547 }
2648 println ! (
2749 r#"cargo:rustc-check-cfg=cfg(arm_architecture, values({}))"# ,
@@ -30,14 +52,17 @@ pub fn process_target(target: &str) {
3052
3153 if let Some ( profile) = Profile :: get ( target) {
3254 println ! ( r#"cargo:rustc-cfg=arm_profile="{}""# , profile) ;
55+ target_info. profile = Some ( profile) ;
3356 }
3457 println ! (
3558 r#"cargo:rustc-check-cfg=cfg(arm_profile, values({}))"# ,
3659 Profile :: values( )
3760 ) ;
61+ target_info
3862}
3963
4064/// The Arm Instruction Set
65+ #[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
4166pub enum Isa {
4267 /// A64 instructions are executed by Arm processors in Aarch64 mode
4368 A64 ,
@@ -91,6 +116,7 @@ impl core::fmt::Display for Isa {
91116/// The Arm Architecture
92117///
93118/// As defined by a particular revision of the Arm Architecture Reference Manual (ARM).
119+ #[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
94120pub enum Arch {
95121 /// Armv6-M (also known as ARMv6-M)
96122 Armv6M ,
@@ -129,6 +155,8 @@ impl Arch {
129155 Some ( Arch :: Armv7R )
130156 } else if target. starts_with ( "armv8r-" ) {
131157 Some ( Arch :: Armv8R )
158+ } else if target. starts_with ( "armv7a-" ) {
159+ Some ( Arch :: Armv7A )
132160 } else if target. starts_with ( "aarch64-" ) || target. starts_with ( "aarch64be-" ) {
133161 Some ( Arch :: Armv8A )
134162 } else {
@@ -188,6 +216,7 @@ impl core::fmt::Display for Arch {
188216}
189217
190218/// The Arm Architecture Profile.
219+ #[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
191220pub enum Profile {
192221 /// Microcontrollers
193222 M ,
0 commit comments