@@ -4,6 +4,8 @@ use clap::{App, Arg};
4
4
5
5
use std:: path:: { Path , PathBuf } ;
6
6
7
+ const DEFAULT_MCU_FOR_NON_AVR : & ' static str = "atmega328" ;
8
+
7
9
#[ derive( Clone , Debug ) ]
8
10
struct Config {
9
11
output_directory : PathBuf ,
@@ -74,38 +76,35 @@ mod gen {
74
76
fn generate_entry_module ( output_path : & Path , module_names : & [ String ] ) -> Result < ( ) , io:: Error > {
75
77
let mut mod_rs = File :: create ( output_path. join ( "mod.rs" ) ) ?;
76
78
77
- writeln ! ( mod_rs, "// Device definitions" ) ?;
78
- for module_name in module_names {
79
- writeln ! ( mod_rs, "pub mod {};" , module_name) ?;
80
- }
81
- writeln ! ( mod_rs) ?;
79
+ const CURRENT_MOD_SUMMARY : & ' static str = "Contains definitions for the current AVR device being targeted." ;
82
80
83
- const CURRENT_MOD_SUMMARY : & ' static str = "Contains definitions for the current AVR device" ;
84
-
85
- writeln ! ( mod_rs, "/// {}" , CURRENT_MOD_SUMMARY ) ?;
86
- writeln ! ( mod_rs, "///" ) ?;
87
- writeln ! ( mod_rs, "/// **NOTE**: We are showing the ATmega328 here, even though the library" ) ?;
88
- writeln ! ( mod_rs, "/// is not targeting a real AVR device. If you compile this library for" ) ?;
89
- writeln ! ( mod_rs, "/// a specific AVR MCU, the module for that device will aliased here." ) ?;
90
- writeln ! ( mod_rs, "// If we are targeting a non-AVR device, just pick the ATmega328p so" ) ?;
91
- writeln ! ( mod_rs, "// that users can see what the API would look like" ) ?;
92
- writeln ! ( mod_rs, "//" ) ?;
93
- writeln ! ( mod_rs, "// Note that we reexport rather than alias so that we can add a note about" ) ?;
94
- writeln ! ( mod_rs, "// this behaviour to the documentation." ) ?;
95
- writeln ! ( mod_rs, "#[cfg(not(target_arch = \" avr\" ))]" ) ?;
96
- writeln ! ( mod_rs, "pub mod current {{ pub use super::atmega328::*; }}" ) ?;
81
+ writeln ! ( mod_rs, "// Device definitions" ) ?;
97
82
writeln ! ( mod_rs) ?;
98
- writeln ! ( mod_rs, "/// {}" , CURRENT_MOD_SUMMARY ) ?;
99
- writeln ! ( mod_rs, "// If we are targeting AVR, lookup the current device's module" ) ?;
100
- writeln ! ( mod_rs, "// and alias it to the `current` module." ) ?;
101
- writeln ! ( mod_rs, "#[cfg(target_arch = \" avr\" )]" ) ?;
102
- writeln ! ( mod_rs, "pub mod current {{" ) ?;
103
- writeln ! ( mod_rs, " // NOTE: 'target_cpu' is a cfg flag specific to the avr-rust fork" ) ?;
104
83
for module_name in module_names {
105
- writeln ! ( mod_rs, " #[cfg(target_cpu = \" {}\" )] pub use super::{} as current;" ,
106
- module_name, module_name) ?;
84
+ if module_name == crate :: DEFAULT_MCU_FOR_NON_AVR {
85
+ writeln ! ( mod_rs, "/// The module containing the values for the '{}' microcontroller" , module_name) ?;
86
+ writeln ! ( mod_rs, "///" ) ?;
87
+ writeln ! ( mod_rs, "/// This is the default MCU when targeting a non-AVR target." ) ?;
88
+
89
+ writeln ! ( mod_rs, "#[cfg(any(not(target_arch = \" avr\" ), avr_mcu_{}, feature = \" all-mcus\" ))] pub mod {};" , module_name, module_name) ?;
90
+
91
+ writeln ! ( mod_rs, "/// {} **The '{}' is the default when targeting non-AVR devices.**" , CURRENT_MOD_SUMMARY , module_name) ?;
92
+
93
+ writeln ! ( mod_rs, "#[cfg(not(target_arch = \" avr\" ))] pub mod current {{ pub use super::{}::*; }}" , module_name) ?;
94
+
95
+ writeln ! ( mod_rs, "/// {} **This is currently the '{}'**." , CURRENT_MOD_SUMMARY , module_name) ?;
96
+ writeln ! ( mod_rs, "#[cfg(all(target_arch = \" avr\" , avr_mcu_{}))] pub mod current {{ pub use super::{}::*; }}" ,
97
+ module_name, module_name) ?;
98
+ } else {
99
+ writeln ! ( mod_rs, "/// The module containing the values for the '{}' microcontroller" , module_name) ?;
100
+ writeln ! ( mod_rs, "#[cfg(any(avr_mcu_{}, feature = \" all-mcus\" ))] pub mod {};" , module_name, module_name) ?;
101
+ writeln ! ( mod_rs, "/// {} **This is currently the '{}'**." , CURRENT_MOD_SUMMARY , module_name) ?;
102
+ writeln ! ( mod_rs, "#[cfg(all(target_arch = \" avr\" , avr_mcu_{}))] pub mod current {{ pub use super::{}::*; }}" ,
103
+ module_name, module_name) ?;
104
+ }
105
+ writeln ! ( mod_rs) ?;
107
106
}
108
- writeln ! ( mod_rs, "}}" ) ?;
107
+ writeln ! ( mod_rs) ?;
109
108
110
109
Ok ( ( ) )
111
110
}
0 commit comments