forked from RIOT-OS/rust-riot-wrappers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
58 lines (52 loc) · 2.04 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
extern crate shlex;
use std::env;
fn main() {
println!("cargo:rerun-if-env-changed=RIOTBUILD_CONFIG_HEADER_C");
let riotbuildh = env::var("RIOTBUILD_CONFIG_HEADER_C")
.expect("riotbuild.h is expected to be indicated in the RIOTBUILD_CONFIG_HEADER_C environment variable, or another source of enabled modules provided.");
println!("cargo:rerun-if-changed={riotbuildh}");
let mut defines = std::collections::HashMap::new();
use std::io::BufRead;
for line in std::io::BufReader::new(
std::fs::File::open(riotbuildh)
.expect("Failed to read riotbuild.h (RIOTBUILD_CONFIG_HEADER_C)"),
)
.lines()
{
let line = line.expect("Error reading line from riotbuild.h (RIOTBUILD_CONFIG_HEADER_C)");
if let Some(name) = line.strip_prefix("#undef ") {
defines.remove(name.trim());
}
if let Some((name, val)) = line
.strip_prefix("#define ")
.and_then(|nv| nv.split_once(" "))
{
defines.insert(name.trim().to_owned(), val.trim().to_owned());
}
}
const BOOLEAN_FLAGS: &[&str] = &[
// This decides whether or not some fields are populated ... and unlike with other
// structs, the zeroed default is not a good solution here. (It'd kind of work, but
// it'd produce incorrect debug output).
"CONFIG_AUTO_INIT_ENABLE_DEBUG",
];
for (def, val) in defines {
if val != "1" {
// So far, only processing boolean flags
continue;
}
if let Some(module) = def.strip_prefix("MODULE_") {
// Some modules like cmsis-dsp_StatisticsFunctions have funny characters
println!(
"cargo:rustc-cfg=riot_module_{}",
module.to_lowercase().replace("-", "_")
);
}
if def == "DEVELHELP" {
println!("cargo:rustc-cfg=riot_develhelp");
}
if BOOLEAN_FLAGS.contains(&def.as_str()) {
println!("cargo:rustc-cfg=marker_{}", def.to_lowercase());
}
}
}