2021-05-25 02:17:24 +00:00
|
|
|
use std::env;
|
|
|
|
use std::path::PathBuf;
|
2021-06-07 03:10:11 +00:00
|
|
|
use stm32_metapac_gen::*;
|
2021-06-09 11:40:34 +00:00
|
|
|
|
2021-11-23 22:49:06 +00:00
|
|
|
fn parse_chip_core(chip_and_core: &str) -> (String, Option<String>) {
|
|
|
|
let mut s = chip_and_core.split('-');
|
|
|
|
let chip_name: String = s.next().unwrap().to_string();
|
|
|
|
if let Some(c) = s.next() {
|
2022-02-26 01:01:59 +00:00
|
|
|
if c.starts_with("cm") {
|
2021-11-23 22:49:06 +00:00
|
|
|
return (chip_name, Some(c.to_ascii_lowercase()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(chip_and_core.to_string(), None)
|
|
|
|
}
|
|
|
|
|
2021-05-25 02:17:24 +00:00
|
|
|
fn main() {
|
2021-06-07 03:10:11 +00:00
|
|
|
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
|
|
|
let data_dir = PathBuf::from("../stm32-data/data");
|
2021-05-25 02:17:24 +00:00
|
|
|
|
2021-11-23 22:49:06 +00:00
|
|
|
let chip_core_name = env::vars_os()
|
2021-05-25 02:17:24 +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()
|
2022-02-26 01:01:59 +00:00
|
|
|
.to_ascii_lowercase()
|
2021-11-23 22:49:06 +00:00
|
|
|
.replace('_', "-");
|
|
|
|
|
|
|
|
let (chip_name, _) = parse_chip_core(&chip_core_name);
|
2021-05-25 02:17:24 +00:00
|
|
|
|
2022-02-26 01:01:59 +00:00
|
|
|
let opts = Options {
|
2021-06-07 03:10:11 +00:00
|
|
|
out_dir: out_dir.clone(),
|
|
|
|
data_dir: data_dir.clone(),
|
2022-02-26 01:01:59 +00:00
|
|
|
chips: vec![chip_name.to_ascii_uppercase()],
|
|
|
|
};
|
|
|
|
Gen::new(opts).gen();
|
2021-06-09 11:40:34 +00:00
|
|
|
|
2021-06-07 03:10:11 +00:00
|
|
|
println!(
|
|
|
|
"cargo:rustc-link-search={}/src/chips/{}",
|
|
|
|
out_dir.display(),
|
2022-02-26 01:01:59 +00:00
|
|
|
chip_core_name,
|
2021-05-25 02:17:24 +00:00
|
|
|
);
|
2021-08-02 17:21:30 +00:00
|
|
|
|
2021-08-02 17:29:06 +00:00
|
|
|
#[cfg(feature = "memory-x")]
|
2021-08-02 17:21:30 +00:00
|
|
|
println!(
|
|
|
|
"cargo:rustc-link-search={}/src/chips/{}/memory_x/",
|
|
|
|
out_dir.display(),
|
2022-02-26 01:01:59 +00:00
|
|
|
chip_core_name
|
|
|
|
);
|
|
|
|
println!(
|
|
|
|
"cargo:rustc-env=STM32_METAPAC_PAC_PATH={}/src/chips/{}/pac.rs",
|
|
|
|
out_dir.display(),
|
|
|
|
chip_core_name
|
|
|
|
);
|
|
|
|
println!(
|
|
|
|
"cargo:rustc-env=STM32_METAPAC_METADATA_PATH={}/src/chips/{}/metadata.rs",
|
|
|
|
out_dir.display(),
|
|
|
|
chip_core_name
|
2021-08-02 17:21:30 +00:00
|
|
|
);
|
|
|
|
|
2021-05-25 02:17:24 +00:00
|
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
|
|
}
|