aboutsummaryrefslogtreecommitdiff
path: root/examples/nrf52840-edf/build.rs
diff options
context:
space:
mode:
authorJames Munns <[email protected]>2025-04-16 17:58:45 +0200
committerDario Nieuwenhuis <[email protected]>2025-09-11 14:45:06 +0200
commit0cb1ffe0258380a3dd25c1037fdfb6ceca3149d9 (patch)
tree9757a4f14c47412d8eed7a2d67ee7732f06c6cfe /examples/nrf52840-edf/build.rs
parent0e28ba1091257111f71b76a664d7038dbfcf9b5e (diff)
Add EDF example
Diffstat (limited to 'examples/nrf52840-edf/build.rs')
-rw-r--r--examples/nrf52840-edf/build.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/nrf52840-edf/build.rs b/examples/nrf52840-edf/build.rs
new file mode 100644
index 000000000..30691aa97
--- /dev/null
+++ b/examples/nrf52840-edf/build.rs
@@ -0,0 +1,35 @@
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
11use std::env;
12use std::fs::File;
13use std::io::Write;
14use std::path::PathBuf;
15
16fn main() {
17 // Put `memory.x` in our output directory and ensure it's
18 // on the linker search path.
19 let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
20 File::create(out.join("memory.x"))
21 .unwrap()
22 .write_all(include_bytes!("memory.x"))
23 .unwrap();
24 println!("cargo:rustc-link-search={}", out.display());
25
26 // By default, Cargo will re-run a build script whenever
27 // any file in the project changes. By specifying `memory.x`
28 // here, we ensure the build script is only re-run when
29 // `memory.x` is changed.
30 println!("cargo:rerun-if-changed=memory.x");
31
32 println!("cargo:rustc-link-arg-bins=--nmagic");
33 println!("cargo:rustc-link-arg-bins=-Tlink.x");
34 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
35}