diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-11-07 23:52:11 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-11-07 23:52:11 +0100 |
| commit | 2221e1fa935fef1fbc8a39a478824f0b163e6399 (patch) | |
| tree | e411210300b63cf3bec2e32e2fb0f2d270129d84 /examples/stm32f0 | |
| parent | 90095adedf370ddcda6d364dbb5e7f3a0a9b5895 (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')
| -rw-r--r-- | examples/stm32f0/.cargo/config.toml | 5 | ||||
| -rw-r--r-- | examples/stm32f0/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/stm32f0/build.rs | 32 | ||||
| -rw-r--r-- | examples/stm32f0/memory.x | 6 |
4 files changed, 4 insertions, 41 deletions
diff --git a/examples/stm32f0/.cargo/config.toml b/examples/stm32f0/.cargo/config.toml index 7506fa91b..4d34270cd 100644 --- a/examples/stm32f0/.cargo/config.toml +++ b/examples/stm32f0/.cargo/config.toml | |||
| @@ -1,10 +1,5 @@ | |||
| 1 | [target.thumbv6m-none-eabi] | 1 | [target.thumbv6m-none-eabi] |
| 2 | runner = 'probe-run --chip STM32F030F4Px' | 2 | runner = 'probe-run --chip STM32F030F4Px' |
| 3 | rustflags = [ | ||
| 4 | # LLD (shipped with the Rust toolchain) is used as the default linker | ||
| 5 | "-C", "link-arg=-Tlink.x", | ||
| 6 | "-C", "link-arg=-Tdefmt.x", | ||
| 7 | ] | ||
| 8 | 3 | ||
| 9 | [build] | 4 | [build] |
| 10 | target = "thumbv6m-none-eabi" | 5 | target = "thumbv6m-none-eabi" |
diff --git a/examples/stm32f0/Cargo.toml b/examples/stm32f0/Cargo.toml index 2db98488d..e586748ab 100644 --- a/examples/stm32f0/Cargo.toml +++ b/examples/stm32f0/Cargo.toml | |||
| @@ -15,7 +15,7 @@ defmt-rtt = "0.2.0" | |||
| 15 | panic-probe = "0.2.0" | 15 | panic-probe = "0.2.0" |
| 16 | rtt-target = { version = "0.3.1", features = ["cortex-m"] } | 16 | rtt-target = { version = "0.3.1", features = ["cortex-m"] } |
| 17 | embassy = { path = "../../embassy", features = ["defmt"] } | 17 | embassy = { path = "../../embassy", features = ["defmt"] } |
| 18 | embassy-stm32 = { path = "../../embassy-stm32", features = ["defmt", "stm32f030f4", "time-driver-tim3"] } | 18 | embassy-stm32 = { path = "../../embassy-stm32", features = ["defmt", "memory-x", "stm32f030f4", "time-driver-tim3"] } |
| 19 | 19 | ||
| 20 | [features] | 20 | [features] |
| 21 | default = [ | 21 | default = [ |
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 | |||
| 11 | use std::env; | ||
| 12 | use std::fs::File; | ||
| 13 | use std::io::Write; | ||
| 14 | use std::path::PathBuf; | ||
| 15 | |||
| 16 | fn main() { | 1 | fn 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 | } |
diff --git a/examples/stm32f0/memory.x b/examples/stm32f0/memory.x deleted file mode 100644 index 3bddaed41..000000000 --- a/examples/stm32f0/memory.x +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | FLASH : ORIGIN = 0x08000000, LENGTH = 16K | ||
| 4 | /* DTCM */ | ||
| 5 | RAM : ORIGIN = 0x20000000, LENGTH = 4K | ||
| 6 | } | ||
