Skip to content

Commit

Permalink
refactor(arch): use cfg_if to select the arch module
Browse files Browse the repository at this point in the history
This constructs is a bit longer, but it makes it more obvious what needs
to be done when adding a new arch module.
It also provides a better error message if the architecture is not
supported.
  • Loading branch information
ROMemories authored and kaspar030 committed Apr 22, 2024
1 parent 846665b commit c3cfd08
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/riot-rs-embassy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@

pub mod define_peripherals;

#[cfg_attr(context = "nrf", path = "arch/nrf.rs")]
#[cfg_attr(context = "rp2040", path = "arch/rp2040.rs")]
#[cfg_attr(context = "esp", path = "arch/esp.rs")]
#[cfg_attr(
not(any(context = "nrf", context = "rp2040", context = "esp")),
path = "arch/dummy.rs"
)]
pub mod arch;
cfg_if::cfg_if! {
if #[cfg(context = "nrf")] {
#[path = "arch/nrf.rs"]
pub mod arch;
} else if #[cfg(context = "rp2040")] {
#[path = "arch/rp2040.rs"]
pub mod arch;
} else if #[cfg(context = "esp")] {
#[path = "arch/esp.rs"]
pub mod arch;
} else if #[cfg(context = "riot-rs")] {
compile_error!("this architecture is not supported");
} else {
#[path = "arch/dummy.rs"]
pub mod arch;
}
}

#[cfg(feature = "usb")]
pub mod usb;
Expand Down

0 comments on commit c3cfd08

Please sign in to comment.