From 0f333527c4844d758e1619174c4903b7a7d80977 Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Fri, 29 Jan 2021 20:16:51 +1300 Subject: [PATCH] By default, the crate should only bother compiling the MCU being targeted --- Cargo.toml | 4 ++++ core_generator/src/main.rs | 23 ++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9714c40..1ad8353 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,8 +25,12 @@ keywords = ["avr", "arduino", "uno"] [features] default = ["avr-std-stub"] +all-mcus = [] [dependencies] avr-std-stub = { version = "1.0", optional = true } const_env--value = "0.1" target-cpu-macro = "0.1" + +[package.metadata.docs.rs] +all-features = true # we specifically want to enable 'all-mcus' for documentation diff --git a/core_generator/src/main.rs b/core_generator/src/main.rs index 7360949..59af759 100644 --- a/core_generator/src/main.rs +++ b/core_generator/src/main.rs @@ -217,10 +217,27 @@ fn generate_cores_mod_rs(mcus: &[&Mcu]) -> Result<(), io::Error> { for mcu in mcus { let module_name = core_module_name(mcu); - writeln!(w, "/// The {}.", mcu.device.name)?; - writeln!(w, "pub mod {};", module_name)?; + let is_fallback_mcu = module_name == DEFAULT_MCU_FOR_NON_AVR_DOCS; - writeln!(w, "#[cfg(avr_mcu_{})] pub use self::{} as current;", module_name, module_name)?; + let cfg_check_default_fallback = if is_fallback_mcu { + format!(", not(target_arch = \"avr\")") + } else { + String::new() + }; + let current_module_check = if is_fallback_mcu { + format!("any(avr_mcu_{}, not(target_arch = \"avr\"))", module_name) + } else { + format!("avr_mcu_{}", module_name) + }; + + writeln!(w, "/// The {}.", mcu.device.name)?; + if is_fallback_mcu { + writeln!(w, "///\n/// This device is chosen as the default when the crate is targeting non-AVR devices.")?; + } + + writeln!(w, "#[cfg(any(avr_mcu_{}, feature = \"all-mcus\"{}))] pub mod {};", module_name, cfg_check_default_fallback, module_name)?; + + writeln!(w, "#[cfg({})] pub use self::{} as current;", current_module_check, module_name)?; writeln!(w)?; } writeln!(w)