-
Notifications
You must be signed in to change notification settings - Fork 33
/
build.rs
73 lines (64 loc) · 1.75 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
71
72
73
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", "imxrt1180"]
.iter()
.map(ToString::to_string)
.collect()
}
fn features_chip() -> HashSet<String> {
features_10xx().into_iter().chain(features_11xx()).collect()
}
fn emit_cfg_checks<F>(cfg: &str, values: impl IntoIterator<Item = F>)
where
F: std::fmt::Display,
{
let quoted: Vec<String> = values
.into_iter()
.map(|value| format!("\"{}\"", value))
.collect();
let joined = quoted.join(", ");
// Single ":" permitted for backwards compatibility.
println!("cargo:rustc-check-cfg=cfg({cfg}, values({joined}))");
}
fn main() {
let all_features = features_enabled();
let feat_chip: HashSet<_> = features_chip();
emit_cfg_checks(
"chip",
feat_chip.iter().chain(std::iter::once(&"none".into())),
);
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.first() {
println!("cargo:rustc-cfg=chip=\"{chip}\"");
} else {
println!("cargo:rustc-cfg=chip=\"none\"");
}
}