1
- //! Useful helpers when building Arm code
1
+ //! Useful cfg helpers for when you are building Arm code
2
2
//!
3
- //! Hopefully Rust will stabilise these kinds of target features, and this won't
4
- //! be required.
3
+ //! Hopefully Rust will stabilise these kinds of target features in the
4
+ //! future, and this won't be required. But until this, arm-targets is here to
5
+ //! help you conditionally compile your code based on the specific Arm
6
+ //! platform you are compiling for.
7
+ //!
8
+ //! In your application, do something like this:
9
+ //!
10
+ //! ```console
11
+ //! $ cargo add --build arm-targets
12
+ //! $ cat > build.rs << EOF
13
+ //! fn main() {
14
+ //! arm_targets::process();
15
+ //! }
16
+ //! EOF
17
+ //! ```
18
+ //!
19
+ //! This will then let you write application code like:
20
+ //!
21
+ //! ```rust
22
+ //! #[cfg(arm_architecture = "armv7m")]
23
+ //! fn only_for_cortex_m3() { }
24
+ //!
25
+ //! #[cfg(arm_isa = "a32")]
26
+ //! fn can_use_arm_32bit_asm_here() { }
27
+ //! ```
28
+ //!
29
+ //! Without this crate, you are limited to `cfg(target_arch = "arm")`, which
30
+ //! isn't all that useful given how many 'Arm' targets there are.
31
+ //!
32
+ //! To see a full list of the features created by this crate, run the CLI tool:
33
+ //!
34
+ //! ```console
35
+ //! $ cargo install arm-targets
36
+ //! $ arm-targets
37
+ //! cargo:rustc-check-cfg=cfg(arm_isa, values("a64", "a32", "t32"))
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
+ //! cargo:rustc-check-cfg=cfg(arm_profile, values("a", "r", "m", "legacy"))
40
+ //! ```
41
+
5
42
#[ derive( Default ) ]
6
43
pub struct TargetInfo {
7
44
isa : Option < Isa > ,
@@ -10,14 +47,17 @@ pub struct TargetInfo {
10
47
}
11
48
12
49
impl TargetInfo {
50
+ /// Get the Arm Instruction Set Architecture of the target
13
51
pub fn isa ( & self ) -> Option < Isa > {
14
52
self . isa
15
53
}
16
54
55
+ /// Get the Arm Architecture version of the target
17
56
pub fn arch ( & self ) -> Option < Arch > {
18
57
self . arch
19
58
}
20
59
60
+ /// Get the Arm Architecture Profile of the target
21
61
pub fn profile ( & self ) -> Option < Profile > {
22
62
self . profile
23
63
}
0 commit comments