Features are named compile-time flags in Cargo.toml. They enable conditional compilation without separate crate versions.
[features]
default = ["cortex-m"]
cortex-m = ["dep:cortex-m-rt", "dep:stm32f4xx-hal"]
riscv = ["dep:riscv-rt"]
qemu = [] # No deps, just enables QEMU stubs
std = ["dep:std"] # For host-side testingIn code:
#[cfg(feature = "cortex-m")]
use stm32f4xx_hal::can::Can;
#[cfg(feature = "riscv")]
use esp_hal::can::Can;
#[cfg(feature = "qemu")]
fn init_dma() { /* stub */ }
#[cfg(not(feature = "qemu"))]
fn init_dma() { /* real DMA init */ }Build for each target:
cargo build --features cortex-m --target thumbv7em-none-eabihf
cargo build --features riscv --target riscv32imac-unknown-none-elf
cargo test --features "std qemu" # Run logic tests on hostThe std + qemu feature combination is how SpaceCAN's protocol core is tested on the development machine — the same logic that runs on STM32F4 in production is tested under cargo test with mocked hardware interfaces.