From d24370dd03207e94f23f8d42068b7c2c04000113 Mon Sep 17 00:00:00 2001 From: cscherr Date: Wed, 14 May 2025 17:26:38 +0200 Subject: [PATCH] fix!: don't require defmt always --- .cargo/config.toml | 2 -- Cargo.toml | 29 ++++++++++++++++++++++++++--- build.rs | 8 ++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) create mode 100755 build.rs diff --git a/.cargo/config.toml b/.cargo/config.toml index a210e52..2aafa28 100755 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -4,8 +4,6 @@ target = "thumbv6m-none-eabi" [target.thumbv6m-none-eabi] runner = 'probe-rs run --chip STM32L053R8' -rustflags = ["-C", "link-arg=-Tlink.x", "-C", "link-arg=-Tdefmt.x"] - [alias] cflash = "flash --chip STM32L053R8" diff --git a/Cargo.toml b/Cargo.toml index 38a3552..2e46d0c 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,29 @@ cortex-m-rt = "0.7.5" panic-halt = "1.0.0" hd44780-driver = "0.4.0" heapless = "0.8.0" -defmt = "1.0.1" -defmt-rtt = "1.0.0" -panic-probe = { version = "0.3", features = ["print-defmt"] } +defmt = {version="1.0.1", optional= true} +defmt-rtt = {version="1.0.0", optional=true} +panic-probe = { version = "0.3", features = ["print-defmt"], optional=true } + +[features] +logging = ["dep:defmt", "dep:defmt-rtt", "dep:panic-probe"] + +[[example]] +name = "logging" +path = "examples/logging.rs" +required-features = ["logging"] + +[[example]] +name = "rtc-log" +path = "examples/rtc-log.rs" +required-features = ["logging"] + +[[example]] +name = "temperature" +path = "examples/temperature.rs" +required-features = ["logging"] + +[[example]] +name = "aes_ecb" +path = "examples/aes_ecb.rs" +required-features = ["logging"] diff --git a/build.rs b/build.rs new file mode 100755 index 0000000..6aec154 --- /dev/null +++ b/build.rs @@ -0,0 +1,8 @@ +fn main() { + println!("cargo::rerun-if-changed=Cargo.toml"); + println!("cargo::rustc-link-arg=-Tlink.x"); + #[cfg(feature = "logging")] + { + println!("cargo::rustc-link-arg=-Tdefmt.x"); + } +}