forked from imxrt-rs/imxrt-hal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
70 lines (61 loc) · 1.71 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use std::{collections::HashSet, env};
fn features_enabled() -> HashSet<String> {
env::vars()
.map(|(key, _)| key)
.flat_map(|feature| {
feature
.strip_prefix("CARGO_FEATURE_")
.map(str::to_lowercase)
})
.collect()
}
fn features_10xx() -> HashSet<String> {
[
"imxrt1010",
"imxrt1015",
"imxrt1020",
"imxrt1050",
"imxrt1060",
"imxrt1064",
]
.iter()
.map(ToString::to_string)
.collect()
}
fn features_11xx() -> HashSet<String> {
["imxrt1160", "imxrt1170"]
.iter()
.map(ToString::to_string)
.collect()
}
fn features_chip() -> HashSet<String> {
features_10xx().into_iter().chain(features_11xx()).collect()
}
fn main() {
let all_features = features_enabled();
let feat_chip: HashSet<_> = features_chip();
let enabled_chip: Vec<_> = all_features.intersection(&feat_chip).collect();
assert!(
enabled_chip.len() < 2,
"Too many chip features! Select one of {:?}",
enabled_chip
);
if let Some(chip) = enabled_chip.get(0) {
let feat_10xx = features_10xx();
let feat_11xx = features_11xx();
let family = if feat_10xx.contains(*chip) {
assert!(!feat_11xx.contains(*chip));
"imxrt10xx"
} else if feat_11xx.contains(*chip) {
assert!(!feat_10xx.contains(*chip));
"imxrt11xx"
} else {
"none"
};
println!("cargo:rustc-cfg=family=\"{family}\"");
println!("cargo:rustc-cfg=chip=\"{chip}\"");
} else {
println!("cargo:rustc-cfg=family=\"none\"");
println!("cargo:rustc-cfg=chip=\"none\"");
}
}