diff --git a/Cargo.toml b/Cargo.toml index 634869e..8ef812d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,10 @@ build = "core_generator/build.rs" keywords = ["avr", "arduino", "uno"] -[build-dependencies] -avr-mcu = "0.2" +[dependencies] +target-cpu-macro = "0.1" + +[build-dependencies] +avr-mcu = "0.3" +target-cpu-fetch = "0.1" diff --git a/core_generator/build.rs b/core_generator/build.rs index 7e19bcc..18c900e 100644 --- a/core_generator/build.rs +++ b/core_generator/build.rs @@ -23,7 +23,11 @@ fn cores_path() -> PathBuf { } fn core_module_name(mcu: &Mcu) -> String { - mcu.device.name.to_lowercase().to_owned() + normalize_device_name(&mcu.device.name) +} + +fn normalize_device_name(device_name: &str) -> String { + device_name.to_lowercase().to_owned() } fn main() { @@ -31,15 +35,18 @@ fn main() { fs::create_dir_all(&cores_path()).expect("could not create cores directory"); } - let current_mcu = if cfg!(arch = "avr") { + let current_mcu = if avr_mcu::current::is_compiling_for_avr() { avr_mcu::current::mcu() .expect("no target cpu specified") } else { avr_mcu::microcontroller(DEFAULT_MCU_FOR_NON_AVR_DOCS) }; + let current_mcu_name = current_mcu.device.name.clone(); generate_config_module().unwrap(); generate_cores(&[current_mcu]).unwrap(); + + println!("cargo:rustc-cfg=avr_mcu_{}", normalize_device_name(¤t_mcu_name)); } fn generate_cores(mcus: &[Mcu]) -> Result<(), io::Error> { @@ -82,7 +89,7 @@ fn generate_cores_mod_rs(mcus: &[Mcu]) -> Result<(), io::Error> { writeln!(w, "/// The {}.", mcu.device.name)?; writeln!(w, "pub mod {};", module_name)?; - writeln!(w, "#[cfg(all(target_arch = \"avr\", target_cpu = \"{}\"))]", module_name)?; + writeln!(w, "#[cfg(avr_mcu_{})]", module_name)?; writeln!(w, "pub use self::{} as current;", module_name)?; } writeln!(w) diff --git a/examples/spi.rs b/examples/spi.rs index ccecf27..1ff200d 100644 --- a/examples/spi.rs +++ b/examples/spi.rs @@ -1,8 +1,8 @@ #![no_std] #![no_main] -extern crate arduino; -use arduino::cores::current; +extern crate ruduino; +use ruduino::cores::current; // Some devices may have multiple SPI modules. // The ATmega328p only has one. diff --git a/src/lib.rs b/src/lib.rs index 228f2a0..b205ecf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,6 +5,7 @@ #![feature(associated_type_defaults)] #![feature(lang_items)] #![feature(unwind_attributes)] +#![feature(proc_macro_hygiene)] #![no_std]