Skip to content

Commit 68fbe8c

Browse files
committed
Move linker script into SDK crate.
Breaking change to the SDK, so bump the version now.
1 parent 8bb76e8 commit 68fbe8c

File tree

15 files changed

+47
-92
lines changed

15 files changed

+47
-92
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description = "SDK for writing applications for Neotron OS"
33
edition = "2021"
44
license = "MIT OR Apache-2.0"
55
name = "neotron-sdk"
6-
version = "0.1.0"
6+
version = "0.2.0"
77
authors = ["Jonathan 'theJPster' Pallant <[email protected]>"]
88

99
[dependencies]

build.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//! Build script for the Neotron SDK
2+
//!
3+
//! Sets up Rust to link with a Cortex-M linker script if you are building for
4+
//! an Arm bare-metal target.
5+
6+
use std::io::prelude::*;
7+
8+
fn main() {
9+
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH variable");
10+
let os = std::env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS variable");
11+
match (arch.as_str(), os.as_str()) {
12+
("arm", "none") => {
13+
setup_cortexm_linker();
14+
}
15+
_ => {
16+
// no script required
17+
}
18+
}
19+
}
20+
21+
fn setup_cortexm_linker() {
22+
// Put `neotron-cortex-m.ld` in our output directory and ensure it's
23+
// on the linker search path.
24+
let out = &std::path::PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
25+
std::fs::File::create(out.join("neotron-cortex-m.ld"))
26+
.unwrap()
27+
.write_all(include_bytes!("./neotron-cortex-m.ld"))
28+
.unwrap();
29+
println!("cargo:rustc-link-search={}", out.display());
30+
31+
// By default, Cargo will re-run a build script whenever
32+
// any file in the project changes. By specifying `neotron-cortex-m.ld`
33+
// here, we ensure the build script is only re-run when
34+
// `neotron-cortex-m.ld` is changed.
35+
println!("cargo:rerun-if-changed=./neotron-cortex-m.ld");
36+
}

samples/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ members = [
88
]
99
resolver = "2"
1010

11+
[workspace.dependencies]
12+
neotron-sdk = { path = "..", version = "0.2" }
13+
1114
[profile.release]
1215
opt-level = "z"
1316
lto = "fat"

samples/asmhello/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ arm-none-eabi-gcc \
1919
-nostartfiles \
2020
-ffreestanding \
2121
-mcpu=$CPU \
22-
-Wl,-T../neotron-cortex-m.ld \
22+
-Wl,-T../../neotron-cortex-m.ld \
2323
-o asmhello.elf \
2424
asmhello.S \

samples/chello/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ arm-none-eabi-gcc \
2828
-Wdouble-promotion \
2929
-Wextra \
3030
-Wl,-gc-sections \
31-
-Wl,-T../neotron-cortex-m.ld \
31+
-Wl,-T../../neotron-cortex-m.ld \
3232
-Wshadow \
3333
--specs=nano.specs \
3434
--specs=nosys.specs \

samples/fault/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ authors = ["Jonathan 'theJPster' Pallant <[email protected]>"]
77
description = "Hello World for Neotron systems"
88

99
[dependencies]
10-
neotron-sdk = { path = "../.." }
10+
neotron-sdk = { workspace = true }
1111

1212
# See workspace for profile settings

samples/fault/build.rs

Lines changed: 0 additions & 21 deletions
This file was deleted.

samples/hello/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ authors = ["Jonathan 'theJPster' Pallant <[email protected]>"]
77
description = "Hello World for Neotron systems"
88

99
[dependencies]
10-
neotron-sdk = { path = "../.." }
10+
neotron-sdk = { workspace = true }
1111

1212
# See workspace for profile settings

samples/hello/build.rs

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)