use std::path::PathBuf; use std::{env, fs}; fn main() -> Result<(), Box> { // add_linker_script // Read the file to a string and replace all occurrences of ${ARCH_WIDTH} with the arch width let content = fs::read_to_string("link.x")?; // content = content.replace("${ARCH_WIDTH}", &arch_width.to_string()); let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); // Put the linker script somewhere the linker can find it fs::write(out_dir.join("link.x"), content)?; println!("cargo:rustc-link-search={}", out_dir.display()); println!("cargo:rerun-if-changed=link.x"); Ok(()) }