-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbuild.rs
24 lines (24 loc) · 928 Bytes
/
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
use std::env;
use std::fs;
use std::path::PathBuf;
fn main() {
if env::var_os("CARGO_FEATURE_RT").is_some() {
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
println!("cargo:rustc-link-search={}", out.display());
let devices = ["stm32u031", "stm32u073", "stm32u083"];
let mut device_file = None;
for &d in &devices {
if env::var_os(&format!("CARGO_FEATURE_{}", d.to_uppercase())).is_some() {
device_file = Some(format!("src/{d}/device.x"));
break;
}
}
if let Some(device_file) = device_file {
fs::copy(&device_file, out.join("device.x")).unwrap();
println!("cargo:rerun-if-changed={device_file}");
} else {
panic!("No device features selected. Avaliable device features are: {devices:?}");
}
}
println!("cargo:rerun-if-changed=build.rs");
}