use std::{env, fs, path::PathBuf}; fn main() { // Copy memory.x somewhere the linker will find it. Relying on the linker's // working directory does not work in a workspace, where cargo runs rustc // from the workspace root rather than this package's directory. let out = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR")); fs::copy("memory.x", out.join("memory.x")).expect("copy memory.x into OUT_DIR"); println!("cargo:rustc-link-search={}", out.display()); // --nmagic disables page alignment of sections; without it the vector table // is pushed away from the start of flash and the boot ROM cannot find it. println!("cargo:rustc-link-arg-bins=--nmagic"); println!("cargo:rustc-link-arg-bins=-Tlink.x"); println!("cargo:rerun-if-changed=memory.x"); println!("cargo:rerun-if-changed=build.rs"); }