This is what I found to reduce code size the most for the 8bit AVR MCU:
[profile.release]
opt-level = "z"
lto = true
overflow-checks = false
codegen-units = 1
debug = false
Also invoking cargo with:
cargo build --release -Z build-std=core -Z build-std-features=panic_immediate_abortYou must then implement panic handling yourself:
pub mod std {
#[lang = "eh_personality"]
#[no_mangle]
pub unsafe extern "C" fn rust_eh_personality() -> () {}
// panic can be replaced by abort with the panic_immediate_abort feature.
// -Z build-std-features=panic_immediate_abort
// This saves space by getting rid of the unwinding.
#[panic_handler]
pub unsafe fn panic_impl(_info: &::core::panic::PanicInfo) -> ! {
loop {}
}
#[no_mangle]
pub unsafe extern "C" fn abort() {
// blink led
loop {}
}
}
If I still have some room in the flash, I will make some led blink with a noticable pattern on abort.You can also experiment with the inlining threshold:
export RUSTFLAGS+=-C inline-threshold=0