Skip to content

Commit

Permalink
Disable LTO when running bloat, fix clippy
Browse files Browse the repository at this point in the history
Use the debug profile for development, with LTO off and a fake memory.x
so linking succeeds. This lets us cleanly run bloat, fmt and clippy.
  • Loading branch information
ah- committed Mar 10, 2018
1 parent b9c527f commit 6fd3934
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ lto = true

[profile.dev]
debug = true
lto = true
lto = false
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ debug: build
arm-none-eabi-gdb target/thumbv7m-none-eabi/release/anne-key

bloat:
$(XARGO) bloat --release --target thumbv7m-none-eabi $(BLOAT_ARGS)
$(XARGO) bloat --target thumbv7m-none-eabi $(BLOAT_ARGS) -n 50

fmt:
cargo fmt

clippy:
$(XARGO) clippy --target thumbv7m-none-eabi

clean:
$(XARGO) clean
Expand Down
8 changes: 7 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ use std::path::PathBuf;
fn main() {
// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
let memory_x: &[u8] = if &env::var("PROFILE").unwrap()[..] == "debug" {
include_bytes!("memory-debug.x")
} else {
include_bytes!("memory-release.x")
};
File::create(out.join("memory.x"))
.unwrap()
.write_all(include_bytes!("memory.x"))
.write_all(memory_x)
.unwrap();
println!("cargo:rustc-link-search={}", out.display());

println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=memory.x");
println!("cargo:rerun-if-changed=memory-debug.x");
}
9 changes: 9 additions & 0 deletions memory-debug.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* fake larger flash so debug builds succeed
can't actually use these on the stm32, but they
allow cargo bloat and clippy to run cleanly */

MEMORY
{
FLASH : ORIGIN = 0x08004000, LENGTH = 4M
RAM : ORIGIN = 0x20000000, LENGTH = 4M
}
File renamed without changes.
12 changes: 12 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,15 @@ fn exti9_5(_t: &mut Threshold, r: EXTI9_5::Resources) {
// maybe only clear set bits? or ones from 9-5?
unsafe { r.EXTI.pr.write(|w| w.bits(0xffff)) };
}

// Need this when building in debug mode without LTO, otherwise we get linker
// errors. This isn't ever actually used.
#[cfg(debug_assertions)]
#[no_mangle]
pub unsafe extern "C" fn rust_begin_unwind(
_args: ::core::fmt::Arguments,
_file: &'static str,
_line: u32,
) -> ! {
loop {}
}

0 comments on commit 6fd3934

Please sign in to comment.