aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f0/build.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-11-07 23:52:11 +0100
committerDario Nieuwenhuis <[email protected]>2021-11-07 23:52:11 +0100
commit2221e1fa935fef1fbc8a39a478824f0b163e6399 (patch)
treee411210300b63cf3bec2e32e2fb0f2d270129d84 /examples/stm32f0/build.rs
parent90095adedf370ddcda6d364dbb5e7f3a0a9b5895 (diff)
Replace rustflags with build.rs extra-link-args.
Rustflags apply to ALL the crates in the graph, while we only need them for the toplevel crate which is the only one getting linked. Rustflags are not equal for all crates, this caused cargo to re-build the same dependency crate multiple times uselessly. After this change, deps are reused more, making builds faster. Note that this only applies when sharing the target/ dir for multiple crates in the repo which is not the default.
Diffstat (limited to 'examples/stm32f0/build.rs')
-rw-r--r--examples/stm32f0/build.rs32
1 files changed, 3 insertions, 29 deletions
diff --git a/examples/stm32f0/build.rs b/examples/stm32f0/build.rs
index d534cc3df..8cd32d7ed 100644
--- a/examples/stm32f0/build.rs
+++ b/examples/stm32f0/build.rs
@@ -1,31 +1,5 @@
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() { 1fn main() {
17 // Put `memory.x` in our output directory and ensure it's 2 println!("cargo:rustc-link-arg-bins=--nmagic");
18 // on the linker search path. 3 println!("cargo:rustc-link-arg-bins=-Tlink.x");
19 let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); 4 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
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} 5}