|
| 1 | +//! This build script copies the `memory.x` file from the crate root into |
| 2 | +//! a directory where the linker can always find it at build time. |
| 3 | +//! For many projects this is optional, as the linker always searches the |
| 4 | +//! project root directory -- wherever `Cargo.toml` is. However, if you |
| 5 | +//! are using a workspace or have a more complicated build setup, this |
| 6 | +//! build script becomes required. Additionally, by requesting that |
| 7 | +//! Cargo re-run the build script whenever `memory.x` is changed, |
| 8 | +//! updating `memory.x` ensures a rebuild of the application with the |
| 9 | +//! new memory settings. |
| 10 | +
|
| 11 | +// use std::env; |
| 12 | +// use std::fs::File; |
| 13 | +// use std::io::Write; |
| 14 | +// use std::path::PathBuf; |
| 15 | + |
| 16 | +fn main() { |
| 17 | + // This section is not needed as the `embassy-stm32` crate |
| 18 | + // provides `memory.x` and adds it to the linker's path. |
| 19 | + // |
| 20 | + // If using a crate that does not provide it, please |
| 21 | + // uncomment the this section and the related imported |
| 22 | + // items. |
| 23 | + |
| 24 | + // Put `memory.x` in our output directory and ensure it's |
| 25 | + // on the linker search path. |
| 26 | + // let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); |
| 27 | + // File::create(out.join("memory.x")) |
| 28 | + // .unwrap() |
| 29 | + // .write_all(include_bytes!("memory.x")) |
| 30 | + // .unwrap(); |
| 31 | + // println!("cargo:rustc-link-search={}", out.display()); |
| 32 | + |
| 33 | + // By default, Cargo will re-run a build script whenever |
| 34 | + // any file in the project changes. By specifying `memory.x` |
| 35 | + // here, we ensure the build script is only re-run when |
| 36 | + // `memory.x` is changed. |
| 37 | + // println!("cargo:rerun-if-changed=memory.x"); |
| 38 | + |
| 39 | + // Prevent the linker from page aligning segments |
| 40 | + println!("cargo:rustc-link-arg-bins=--nmagic"); |
| 41 | + |
| 42 | + // Required for `cortex-m` |
| 43 | + println!("cargo:rustc-link-arg-bins=-Tlink.x"); |
| 44 | + // Required for `defmt` |
| 45 | + println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); |
| 46 | +} |
0 commit comments