use std::{env, fs::File, io::Write, path::PathBuf}; fn main() { let out = PathBuf::from(env::var_os("OUT_DIR").unwrap()); File::create(out.join("memory.x")) .unwrap() .write_all(include_bytes!("memory.x")) .unwrap(); println!("cargo:rustc-link-search={}", out.display()); println!("cargo:rerun-if-changed=memory.x"); println!("cargo:rerun-if-changed=build.rs"); // defmt ships its own linker script (`defmt.x`) that defines the // `_defmt_*` interner sections. Only link it when the feature is on — // otherwise the symbols don't exist and `ld` will refuse the build. if env::var_os("CARGO_FEATURE_DEFMT").is_some() { println!("cargo:rustc-link-arg=-Tdefmt.x"); } }