diff --git a/Cargo.toml b/Cargo.toml index 233f358..5968d98 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,13 +3,36 @@ edition = "2024" name = "esp32-c_its-companion" rust-version = "1.88" version = "0.1.0" +default-run = "esp32-c_its-companion" [[bin]] name = "esp32-c_its-companion" path = "./src/main.rs" +[[bin]] +name = "test" +path = "./src/test.rs" +required-features = ["std"] + [features] -default = ["spat"] +default = ["esp", "spat"] + +# build for ESP (needed to build test for `host-tuple`) +esp = [ + "dep:esp-hal", + "dep:esp-rtos", + "dep:esp-bootloader-esp-idf", + "dep:embassy-executor", + "dep:embassy-time", + "dep:embedded-io", + "dep:embedded-io-async", + "dep:esp-alloc", + "dep:esp-backtrace", + "dep:esp-println", + "dep:esp-radio", + "dep:embassy_gps", +] +std = ["c-its-parser/std"] # echo CAM data on serial cam = ["c-its-parser/cam"] @@ -20,9 +43,9 @@ spat = ["c-its-parser/spatem", "c-its-parser/mapem"] [dependencies] -esp-hal = { version = "~1.1.0", features = ["esp32c5", "log-04", "unstable"] } +esp-hal = { version = "~1.1.0", optional = true, features = ["esp32c5", "log-04", "unstable"] } -esp-rtos = { version = "0.3.0", features = [ +esp-rtos = { version = "0.3.0", optional = true, features = [ "embassy", "esp-alloc", "esp-radio", @@ -30,22 +53,22 @@ esp-rtos = { version = "0.3.0", features = [ "log-04", ] } -esp-bootloader-esp-idf = { version = "0.5.0", features = ["esp32c5", "log-04"] } +esp-bootloader-esp-idf = { version = "0.5.0", optional = true, features = ["esp32c5", "log-04"] } log = "0.4.27" critical-section = "1.2.0" -embassy-executor = { version = "0.10.0", features = ["log"] } -embassy-time = { version = "0.5.0", features = ["log"] } -embedded-io = "0.7.1" -embedded-io-async = "0.7.0" -esp-alloc = "0.10.0" -esp-backtrace = { version = "0.19.0", features = [ +embassy-executor = { version = "0.10.0", optional = true, features = ["log"] } +embassy-time = { version = "0.5.0", optional = true, features = ["log"] } +embedded-io = { version = "0.7.1", optional = true } +embedded-io-async = { version = "0.7.0", optional = true } +esp-alloc = { version = "0.10.0", optional = true } +esp-backtrace = { version = "0.19.0", optional = true, features = [ "esp32c5", "panic-handler", "println", ] } -esp-println = { version = "0.17.0", features = ["esp32c5", "log-04"] } -esp-radio = { version = "0.18.0", features = [ +esp-println = { version = "0.17.0", optional = true, features = ["esp32c5", "log-04"] } +esp-radio = { version = "0.18.0", optional = true, features = [ "esp-alloc", "esp32c5", "log-04", @@ -54,7 +77,7 @@ esp-radio = { version = "0.18.0", features = [ "sniffer", ] } -embassy_gps = { version = "0.1.0", default-features = false, features = ["esp", "log-04"], git = "https://github.com/jbeyerstedt/embassy_gps.git", branch = "feat/rework-gpsfix" } +embassy_gps = { version = "0.1.0", optional = true, default-features = false, features = ["esp", "log-04"], git = "https://github.com/jbeyerstedt/embassy_gps.git", branch = "feat/rework-gpsfix" } c-its-parser = { version = "2.2.2", default-features = false, features = [ "time", "geo", diff --git a/Readme.md b/Readme.md index 02d912f..c2d3983 100644 --- a/Readme.md +++ b/Readme.md @@ -29,3 +29,10 @@ Connect your ESP32-C5 and run: ``` cargo run --release ``` + +### Run Unit Tests on Host +The unit tests in this project are meant to be run on the host: + +``` +cargo test --target host-tuple --bin test --no-default-features -F std,spat +``` diff --git a/build.rs b/build.rs index 9272c07..7ad15d3 100644 --- a/build.rs +++ b/build.rs @@ -1,7 +1,13 @@ +use std::env; + fn main() { - linker_be_nice(); - // make sure linkall.x is the last linker script (otherwise might cause problems with flip-link) - println!("cargo:rustc-link-arg=-Tlinkall.x"); + let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); + + if target_arch == "riscv32" { + linker_be_nice(); + // make sure linkall.x is the last linker script (otherwise might cause problems with flip-link) + println!("cargo:rustc-link-arg=-Tlinkall.x"); + } } fn linker_be_nice() { diff --git a/src/applogic/tlc.rs b/src/applogic/tlc.rs index ed03922..4b631c9 100644 --- a/src/applogic/tlc.rs +++ b/src/applogic/tlc.rs @@ -3,6 +3,7 @@ use c_its_parser::standards::mapem_2_2_1::mapem_pdu_descriptions; use c_its_parser::standards::spatem_2_2_1::spatem_pdu_descriptions; use chrono::Datelike; +#[cfg(target_arch = "riscv32")] use esp_println::println; pub fn handle_mapem(etsi: &mapem_pdu_descriptions::MAPEM) { diff --git a/src/test.rs b/src/test.rs new file mode 100644 index 0000000..0fb9fac --- /dev/null +++ b/src/test.rs @@ -0,0 +1,10 @@ +#![cfg(not(target_arch = "riscv32"))] + +extern crate alloc; + +mod applogic; +mod cache; + +fn main() { + // dummy only +}