use std::env; use std::fs::File; use std::io::Write; use std::path::PathBuf; fn main() { let app_core = env::var_os("CARGO_FEATURE_APP_CORE").is_some(); let net_core = env::var_os("CARGO_FEATURE_NET_CORE").is_some(); // Put the linker script somewhere the linker can find it let contents = match (app_core, net_core) { (true, true) => panic!("only one of the `app-core` and `net-core` features can be enabled"), (true, false) => &include_bytes!("memory-app.x")[..], (false, true) => &include_bytes!("memory-net.x")[..], (false, false) => panic!("either the `app-core` or `net-core` feature must be enabled"), }; let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); File::create(out.join("memory.x")) .unwrap() .write_all(contents) .unwrap(); println!("cargo:rustc-link-search={}", out.display()); println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=memory-app.x"); println!("cargo:rerun-if-changed=memory-net.x"); }