By default, the crate should only bother compiling the MCU being targeted

This commit is contained in:
Dylan McKay 2021-01-29 20:16:51 +13:00
parent fc6531296a
commit 0f333527c4
2 changed files with 24 additions and 3 deletions

View File

@ -25,8 +25,12 @@ keywords = ["avr", "arduino", "uno"]
[features] [features]
default = ["avr-std-stub"] default = ["avr-std-stub"]
all-mcus = []
[dependencies] [dependencies]
avr-std-stub = { version = "1.0", optional = true } avr-std-stub = { version = "1.0", optional = true }
const_env--value = "0.1" const_env--value = "0.1"
target-cpu-macro = "0.1" target-cpu-macro = "0.1"
[package.metadata.docs.rs]
all-features = true # we specifically want to enable 'all-mcus' for documentation

View File

@ -217,10 +217,27 @@ fn generate_cores_mod_rs(mcus: &[&Mcu]) -> Result<(), io::Error> {
for mcu in mcus { for mcu in mcus {
let module_name = core_module_name(mcu); let module_name = core_module_name(mcu);
writeln!(w, "/// The {}.", mcu.device.name)?; let is_fallback_mcu = module_name == DEFAULT_MCU_FOR_NON_AVR_DOCS;
writeln!(w, "pub mod {};", module_name)?;
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)?;
} }
writeln!(w) writeln!(w)