Skip to content

Commit c5c20c4

Browse files
committed
arm-targets: Add CLI tool and more docs
1 parent d2ff2b3 commit c5c20c4

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

arm-targets/src/lib.rs

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
1-
//! Useful helpers when building Arm code
1+
//! Useful cfg helpers for when you are building Arm code
22
//!
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+
542
#[derive(Default)]
643
pub struct TargetInfo {
744
isa: Option<Isa>,
@@ -10,14 +47,17 @@ pub struct TargetInfo {
1047
}
1148

1249
impl TargetInfo {
50+
/// Get the Arm Instruction Set Architecture of the target
1351
pub fn isa(&self) -> Option<Isa> {
1452
self.isa
1553
}
1654

55+
/// Get the Arm Architecture version of the target
1756
pub fn arch(&self) -> Option<Arch> {
1857
self.arch
1958
}
2059

60+
/// Get the Arm Architecture Profile of the target
2161
pub fn profile(&self) -> Option<Profile> {
2262
self.profile
2363
}

arm-targets/src/main.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//! CLI tool for arm-targets
2+
3+
/// Entry point to the program
4+
fn main() {
5+
if let Some(target) = std::env::args().skip(1).next() {
6+
println!("// These are the features for the target '{}'", target);
7+
arm_targets::process_target(&target);
8+
} else {
9+
println!("// These are the features this crate enables:");
10+
arm_targets::process_target("");
11+
}
12+
}

0 commit comments

Comments
 (0)