From e2bc77741093819da8b8235801e5567d01d129bf Mon Sep 17 00:00:00 2001 From: cscherr Date: Wed, 9 Jul 2025 15:12:10 +0200 Subject: [PATCH] chore: build and test shenanigans --- .cargo/config.toml | 9 ++------- Cargo.toml | 4 ++++ build.rs | 9 ++++++--- crates/crc/src/crc_dev.rs | 16 +++++++++++++++- crates/crc/src/lib.rs | 2 ++ scripts/test_crc.sh | 5 +++++ 6 files changed, 34 insertions(+), 11 deletions(-) create mode 100755 scripts/test_crc.sh diff --git a/.cargo/config.toml b/.cargo/config.toml index b280dc1..dc51815 100755 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,15 +1,10 @@ -[build] -# target = "thumbv6m-none-eabi" - -[test] -target = "x86_64-unknown-linux-gnu" - [target.thumbv6m-none-eabi] runner = 'probe-rs run --chip STM32L053R8' [alias] -target = "thumbv6m-none-eabi" +arun = "run --target thumbv6m-none-eabi" +atest = "test --target x86_64-unknown-linux-gnu" cflash = "flash --chip STM32L053R8" [env] diff --git a/Cargo.toml b/Cargo.toml index ff3db82..abcd512 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,10 @@ defmt = { version = "1.0.1" } defmt-rtt = { version = "1.0.0" } panic-probe = { version = "0.3", features = ["print-defmt"] } +[features] +default = ["buildscript"] +buildscript = [] + [profile.release] debug = "full" # those are not on the board diff --git a/build.rs b/build.rs index 3987a39..972f524 100755 --- a/build.rs +++ b/build.rs @@ -1,5 +1,8 @@ fn main() { - println!("cargo::rerun-if-changed=Cargo.toml"); - println!("cargo::rustc-link-arg=-Tlink.x"); - println!("cargo::rustc-link-arg=-Tdefmt.x"); + #[cfg(feature = "buildscript")] + { + println!("cargo::rerun-if-changed=Cargo.toml"); + println!("cargo::rustc-link-arg=-Tlink.x"); + println!("cargo::rustc-link-arg=-Tdefmt.x"); + } } diff --git a/crates/crc/src/crc_dev.rs b/crates/crc/src/crc_dev.rs index 4d75d4b..56c2512 100755 --- a/crates/crc/src/crc_dev.rs +++ b/crates/crc/src/crc_dev.rs @@ -1,9 +1,23 @@ +use crate::Crc; + +struct CrcDev; +impl Crc for CrcDev { + type Input = [u8]; + type Checksum = [u8; Self::CHECKSUM_LEN]; + const CHECKSUM_LEN: usize = 4; + + fn process(data: &Self::Input) -> Self::Checksum { + todo!() + } +} + #[cfg(test)] mod tests { use super::*; #[test] fn it_works() { - assert_eq!(2 + 2, 4); + let data = [0, 1, 2, 3, 4, 5, 6]; + assert_eq!(CrcDev::process(&data), [1, 2, 3, 4]) } } diff --git a/crates/crc/src/lib.rs b/crates/crc/src/lib.rs index 91b6a76..34884aa 100755 --- a/crates/crc/src/lib.rs +++ b/crates/crc/src/lib.rs @@ -1,3 +1,5 @@ +#![no_std] + mod crc_32; pub use crc_32::*; diff --git a/scripts/test_crc.sh b/scripts/test_crc.sh new file mode 100755 index 0000000..76237f3 --- /dev/null +++ b/scripts/test_crc.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# I'm using a bash script because if i set the target in .cargo/config.toml +# i can't build for x86_64 anymore, which means I can't run the unit tests. +TARGET="x86_64-unknown-linux-gnu" +cargo test --target $TARGET -p crc --no-default-features