Merge pull request #118 from rust-embedded/link-arg

Move link-arg setting from .cargo/config.toml to build.rs
This commit is contained in:
Adam Greig
2023-02-20 22:56:18 +00:00
committed by GitHub
2 changed files with 21 additions and 12 deletions

View File

@@ -10,27 +10,24 @@
# runner = "gdb -q -x openocd.gdb" # runner = "gdb -q -x openocd.gdb"
rustflags = [ rustflags = [
# This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x # Previously, the linker arguments --nmagic and -Tlink.x were set here.
# See https://github.com/rust-embedded/cortex-m-quickstart/pull/95 # They are now set by build.rs instead. The linker argument can still
"-C", "link-arg=--nmagic", # only be set here, if a custom linker is needed.
# LLD (shipped with the Rust toolchain) is used as the default linker # By default, the LLD linker is used, which is shipped with the Rust
"-C", "link-arg=-Tlink.x", # toolchain. If you run into problems with LLD, you can switch to the
# GNU linker by uncommenting this line:
# if you run into problems with LLD switch to the GNU linker by commenting out
# this line
# "-C", "linker=arm-none-eabi-ld", # "-C", "linker=arm-none-eabi-ld",
# if you need to link to pre-compiled C libraries provided by a C toolchain # If you need to link to pre-compiled C libraries provided by a C toolchain
# use GCC as the linker by commenting out both lines above and then # use GCC as the linker by uncommenting the three lines below:
# uncommenting the three lines below
# "-C", "linker=arm-none-eabi-gcc", # "-C", "linker=arm-none-eabi-gcc",
# "-C", "link-arg=-Wl,-Tlink.x", # "-C", "link-arg=-Wl,-Tlink.x",
# "-C", "link-arg=-nostartfiles", # "-C", "link-arg=-nostartfiles",
] ]
[build] [build]
# Pick ONE of these compilation targets # Pick ONE of these default compilation targets
# target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ # target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+
target = "thumbv7m-none-eabi" # Cortex-M3 target = "thumbv7m-none-eabi" # Cortex-M3
# target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU) # target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU)

View File

@@ -7,6 +7,8 @@
//! Cargo re-run the build script whenever `memory.x` is changed, //! Cargo re-run the build script whenever `memory.x` is changed,
//! updating `memory.x` ensures a rebuild of the application with the //! updating `memory.x` ensures a rebuild of the application with the
//! new memory settings. //! new memory settings.
//!
//! The build script also sets the linker flags to tell it which link script to use.
use std::env; use std::env;
use std::fs::File; use std::fs::File;
@@ -28,4 +30,14 @@ fn main() {
// here, we ensure the build script is only re-run when // here, we ensure the build script is only re-run when
// `memory.x` is changed. // `memory.x` is changed.
println!("cargo:rerun-if-changed=memory.x"); println!("cargo:rerun-if-changed=memory.x");
// Specify linker arguments.
// `--nmagic` is required if memory section addresses are not aligned to 0x10000,
// for example the FLASH and RAM sections in your `memory.x`.
// See https://github.com/rust-embedded/cortex-m-quickstart/pull/95
println!("cargo:rustc-link-arg=--nmagic");
// Set the linker script to the one provided by cortex-m-rt.
println!("cargo:rustc-link-arg=-Tlink.x");
} }