Skip to content

Commit 0f33352

Browse files
committed
By default, the crate should only bother compiling the MCU being targeted
1 parent fc65312 commit 0f33352

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ keywords = ["avr", "arduino", "uno"]
2525

2626
[features]
2727
default = ["avr-std-stub"]
28+
all-mcus = []
2829

2930
[dependencies]
3031
avr-std-stub = { version = "1.0", optional = true }
3132
const_env--value = "0.1"
3233
target-cpu-macro = "0.1"
34+
35+
[package.metadata.docs.rs]
36+
all-features = true # we specifically want to enable 'all-mcus' for documentation

core_generator/src/main.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,27 @@ fn generate_cores_mod_rs(mcus: &[&Mcu]) -> Result<(), io::Error> {
217217

218218
for mcu in mcus {
219219
let module_name = core_module_name(mcu);
220+
let is_fallback_mcu = module_name == DEFAULT_MCU_FOR_NON_AVR_DOCS;
221+
222+
let cfg_check_default_fallback = if is_fallback_mcu {
223+
format!(", not(target_arch = \"avr\")")
224+
} else {
225+
String::new()
226+
};
227+
let current_module_check = if is_fallback_mcu {
228+
format!("any(avr_mcu_{}, not(target_arch = \"avr\"))", module_name)
229+
} else {
230+
format!("avr_mcu_{}", module_name)
231+
};
232+
220233
writeln!(w, "/// The {}.", mcu.device.name)?;
221-
writeln!(w, "pub mod {};", module_name)?;
234+
if is_fallback_mcu {
235+
writeln!(w, "///\n/// This device is chosen as the default when the crate is targeting non-AVR devices.")?;
236+
}
237+
238+
writeln!(w, "#[cfg(any(avr_mcu_{}, feature = \"all-mcus\"{}))] pub mod {};", module_name, cfg_check_default_fallback, module_name)?;
222239

223-
writeln!(w, "#[cfg(avr_mcu_{})] pub use self::{} as current;", module_name, module_name)?;
240+
writeln!(w, "#[cfg({})] pub use self::{} as current;", current_module_check, module_name)?;
224241
writeln!(w)?;
225242
}
226243
writeln!(w)

0 commit comments

Comments
 (0)