embassy/embassy-stm32/build.rs

33 lines
1.0 KiB
Rust
Raw Normal View History

use std::env;
2021-05-01 03:07:17 +02:00
use std::path::PathBuf;
use std::process::Command;
2021-05-01 03:07:17 +02:00
fn main() {
let chip_name = env::vars_os()
2021-05-01 03:07:17 +02: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()
.to_ascii_uppercase();
2021-05-01 03:07:17 +02: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 03:07:17 +02: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 03:07:17 +02:00
}
for s in env::var("DEP_STM32_METAPAC_V0.1_CFGS").unwrap().split(",") {
println!("cargo:rustc-cfg={}", s);
}
println!("cargo:rerun-if-env-changed=DEP_STM32_METAPAC_V0.1_CFGS");
2021-05-01 03:07:17 +02:00
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=gen.py");
2021-05-01 03:07:17 +02:00
}