Skip to content

Commit 1c97c86

Browse files
authored
Merge pull request #48 from braun-embedded/disable-linker-script
Add Cargo feature to disable linker script
2 parents 469a51a + f32484f commit 1c97c86

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ cortex-m-rtfm = "0.4.3"
4949
[features]
5050
# Miscellaneaous features
5151
rt = ["stm32l0/rt"]
52+
disable-linker-script = []
5253
# MCUs
5354
stm32l0x1 = ["stm32l0/stm32l0x1"]
5455
stm32l0x2 = ["stm32l0/stm32l0x2"]

build.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,27 @@ fn main() {
2525
panic!("\n\nMust select exactly one package for linker script generation!\nChoices: 'stm32l0x1' or 'stm32l0x2' or 'stm32l0x3'\n\n");
2626
}
2727

28-
let linker = if cfg!(feature = "stm32l0x1") {
29-
include_bytes!("memory_l0x1.x").as_ref()
30-
} else if cfg!(feature = "stm32l0x2") {
31-
include_bytes!("memory_l0x2.x").as_ref()
32-
} else if cfg!(feature = "stm32l0x3") {
33-
include_bytes!("memory_l0x3.x").as_ref()
34-
} else {
35-
unreachable!();
36-
};
37-
38-
File::create(out.join("memory.x"))
39-
.unwrap()
40-
.write_all(linker)
41-
.unwrap();
42-
println!("cargo:rustc-link-search={}", out.display());
28+
if !cfg!(feature = "disable-linker-script") {
29+
let linker = if cfg!(feature = "stm32l0x1") {
30+
include_bytes!("memory_l0x1.x").as_ref()
31+
} else if cfg!(feature = "stm32l0x2") {
32+
include_bytes!("memory_l0x2.x").as_ref()
33+
} else if cfg!(feature = "stm32l0x3") {
34+
include_bytes!("memory_l0x3.x").as_ref()
35+
} else {
36+
unreachable!();
37+
};
38+
39+
File::create(out.join("memory.x"))
40+
.unwrap()
41+
.write_all(linker)
42+
.unwrap();
43+
println!("cargo:rustc-link-search={}", out.display());
44+
45+
println!("cargo:rerun-if-changed=memory_l0x1.x");
46+
println!("cargo:rerun-if-changed=memory_l0x2.x");
47+
println!("cargo:rerun-if-changed=memory_l0x3.x");
48+
}
4349

4450
println!("cargo:rerun-if-changed=build.rs");
45-
println!("cargo:rerun-if-changed=memory_l0x1.x");
46-
println!("cargo:rerun-if-changed=memory_l0x2.x");
47-
println!("cargo:rerun-if-changed=memory_l0x3.x");
4851
}

0 commit comments

Comments
 (0)