From cb163a21bc9d4376357286dc6b66f759f786e244 Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Fri, 3 Jul 2020 01:37:00 +1200 Subject: [PATCH 1/3] Get the examples compiling again --- Cargo.toml | 8 ++++++-- core_generator/build.rs | 21 ++++++++++++++++----- examples/spi.rs | 4 ++-- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 634869e..e60deed 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.0" diff --git a/core_generator/build.rs b/core_generator/build.rs index 7e19bcc..d64cb4d 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,7 +35,7 @@ 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 { @@ -76,14 +80,21 @@ fn generate_cores_mod_rs(mcus: &[Mcu]) -> Result<(), io::Error> { let path = cores_path().join("mod.rs"); let mut w = File::create(&path)?; + if avr_mcu::current::is_compiling_for_avr() { + let current_mcu_name = target_cpu_fetch::target_cpu().expect("could not get the target CPU for ruduino core generation"); + + writeln!(w)?; + if let Some(current_mcu_name) = current_mcu_name { + writeln!(w, "/// Expose the current MCU core ({}).", current_mcu_name)?; + writeln!(w, "pub use self::{} as current;", current_mcu_name)?; + } + } + writeln!(w)?; for mcu in mcus { let module_name = core_module_name(mcu); 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, "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. From 2a3bcbda025c969c9a16656d4a1583b31f486562 Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Fri, 3 Jul 2020 01:55:15 +1200 Subject: [PATCH 2/3] Fix device detection logic --- core_generator/build.rs | 16 ++++++---------- src/lib.rs | 1 + 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/core_generator/build.rs b/core_generator/build.rs index d64cb4d..18c900e 100644 --- a/core_generator/build.rs +++ b/core_generator/build.rs @@ -41,9 +41,12 @@ fn main() { } 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> { @@ -80,21 +83,14 @@ fn generate_cores_mod_rs(mcus: &[Mcu]) -> Result<(), io::Error> { let path = cores_path().join("mod.rs"); let mut w = File::create(&path)?; - if avr_mcu::current::is_compiling_for_avr() { - let current_mcu_name = target_cpu_fetch::target_cpu().expect("could not get the target CPU for ruduino core generation"); - - writeln!(w)?; - if let Some(current_mcu_name) = current_mcu_name { - writeln!(w, "/// Expose the current MCU core ({}).", current_mcu_name)?; - writeln!(w, "pub use self::{} as current;", current_mcu_name)?; - } - } - writeln!(w)?; for mcu in mcus { let module_name = core_module_name(mcu); writeln!(w, "/// The {}.", mcu.device.name)?; writeln!(w, "pub mod {};", module_name)?; + + writeln!(w, "#[cfg(avr_mcu_{})]", module_name)?; + writeln!(w, "pub use self::{} as current;", module_name)?; } writeln!(w) } 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] From bcef4ad612694fd8de3a12dec0d342fe45e15094 Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Sat, 25 Jul 2020 01:54:59 +1200 Subject: [PATCH 3/3] Relax patch version contraints on target-cpu-fetch dependency --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index e60deed..8ef812d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,5 +24,5 @@ target-cpu-macro = "0.1" [build-dependencies] avr-mcu = "0.3" -target-cpu-fetch = "0.1.0" +target-cpu-fetch = "0.1"