~ruther/avr-device

f77864dc9935b6cc402024373ec2e645d1d0cbcf — Rahix 5 years ago fb9d2d9
hack: Make sure you cannot build for more than one chip

Signed-off-by: Rahix <rahix@rahix.de>
2 files changed, 48 insertions(+), 3 deletions(-)

M build.rs
M src/lib.rs
M build.rs => build.rs +4 -2
@@ 3,7 3,8 @@ use std::process;
fn main() {
    // Just run `make` to generate the chip definitions
    if !process::Command::new("make").status().unwrap().success() {
        eprintln!("
        eprintln!(
            "
avr-device: Running `make` resulted in a failure.

    Please make sure, you have all dependencies


@@ 16,7 17,8 @@ avr-device: Running `make` resulted in a failure.

    For more info, look at README file:
        https://github.com/Rahix/avr-device/blob/master/README.md
");
"
        );
        panic!("make failed");
    }
}

M src/lib.rs => src/lib.rs +44 -1
@@ 1,3 1,17 @@
//! This crate contains register definitions for
#![cfg_attr(feature = "atmega1280", doc = "**atmega1280**.")]
#![cfg_attr(feature = "atmega8", doc = "**atmega8**.")]
#![cfg_attr(feature = "atmega328p", doc = "**atmega328p**.")]
#![cfg_attr(feature = "atmega32u4", doc = "**atmega32u4**.")]
#![cfg_attr(feature = "attiny85", doc = "**attiny85**.")]
//! Which chip the crate is built for depends on the feature flag used.
//!
//! The following chips are available (using feature flags of the same name):
//! * `atmega1280`
//! * `atmega8`
//! * `atmega328p`
//! * `atmega32u4`
//! * `attiny85`
#![no_std]
#![feature(asm)]



@@ 18,10 32,39 @@ cfg_if::cfg_if! {
    } else if #[cfg(feature = "attiny85")] {
        pub use crate::devices::attiny85::*;
    } else {
        compile_error!("You need to select exactly one chip as a feature!");
        compile_error!("You need to select a chip as a feature!");
    }
}

// TODO: Find a better way to do this
#[cfg(any(
    all(feature = "atmega1280", any(
        feature = "atmega8",
        feature = "atmega328p",
        feature = "atmega32u4",
        feature = "attiny85",
    )),
    all(feature = "atmega8", any(
        feature = "atmega1280",
        feature = "atmega328p",
        feature = "atmega32u4",
        feature = "attiny85",
    )),
    all(feature = "atmega328p", any(
        feature = "atmega1280",
        feature = "atmega8",
        feature = "atmega32u4",
        feature = "attiny85",
    )),
    all(feature = "atmega32u4", any(
        feature = "atmega1280",
        feature = "atmega8",
        feature = "atmega329p",
        feature = "attiny85",
    )),
))]
compile_error!("You cannot select multiple chips at once!");

#[cfg(any(
    feature = "atmega1280",
    feature = "atmega8",

Do not follow this link