2021-05-25 02:17:24 +00:00
|
|
|
use std::env;
|
2021-05-01 01:07:17 +00:00
|
|
|
use std::path::PathBuf;
|
2021-05-25 02:17:24 +00:00
|
|
|
use std::process::Command;
|
2021-05-01 01:07:17 +00:00
|
|
|
|
|
|
|
fn main() {
|
2021-05-25 02:17:24 +00:00
|
|
|
let chip_name = env::vars_os()
|
2021-05-01 01:07:17 +00:00
|
|
|
.map(|(a, _)| a.to_string_lossy().to_string())
|
|
|
|
.find(|x| x.starts_with("CARGO_FEATURE_STM32"))
|
|
|
|
.expect("No stm32xx Cargo feature enabled")
|
|
|
|
.strip_prefix("CARGO_FEATURE_")
|
|
|
|
.unwrap()
|
2021-07-31 05:20:37 +00:00
|
|
|
.to_ascii_lowercase();
|
2021-05-01 01:07:17 +00:00
|
|
|
|
2021-05-25 02:17:24 +00:00
|
|
|
let out_dir = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
|
|
|
let out_file = out_dir.join("generated.rs").to_string_lossy().to_string();
|
2021-05-01 01:07:17 +00:00
|
|
|
|
2021-05-25 02:17:24 +00:00
|
|
|
let exit_code = Command::new("python3")
|
|
|
|
.args(&["gen.py", &chip_name, &out_file])
|
|
|
|
.status()
|
|
|
|
.expect("failed to execute gen.py");
|
|
|
|
|
|
|
|
if !exit_code.success() {
|
|
|
|
panic!("gen.py exited with {:?}", exit_code)
|
2021-05-01 01:07:17 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 03:12:10 +00:00
|
|
|
stm32_metapac::peripheral_versions!(
|
|
|
|
($peri:ident, $version:ident) => {
|
|
|
|
println!("cargo:rustc-cfg={}", stringify!($peri));
|
|
|
|
println!("cargo:rustc-cfg={}_{}", stringify!($peri), stringify!($version));
|
|
|
|
};
|
|
|
|
);
|
|
|
|
|
2021-07-31 05:20:37 +00:00
|
|
|
let mut chip_and_core = chip_name.split('_');
|
|
|
|
let chip = chip_and_core.next().expect("Unexpected stm32xx feature");
|
|
|
|
|
|
|
|
if let Some(core) = chip_and_core.next() {
|
|
|
|
println!("cargo:rustc-cfg={}_{}", &chip[..(chip.len() - 2)], core);
|
|
|
|
} else {
|
|
|
|
println!("cargo:rustc-cfg={}", &chip[..(chip.len() - 2)]);
|
|
|
|
}
|
|
|
|
|
2021-05-01 01:07:17 +00:00
|
|
|
println!("cargo:rerun-if-changed=build.rs");
|
2021-05-25 02:17:24 +00:00
|
|
|
println!("cargo:rerun-if-changed=gen.py");
|
2021-05-01 01:07:17 +00:00
|
|
|
}
|