From e2443720fb5579f199119a052c2d7d457ba1e86a Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Tue, 6 Nov 2018 00:03:06 +1300 Subject: [PATCH] Use std::env::var rather than env! in the build script This will let the crate build on crates.io. --- core_generator/build.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core_generator/build.rs b/core_generator/build.rs index 8a1eadb..45980bb 100644 --- a/core_generator/build.rs +++ b/core_generator/build.rs @@ -4,7 +4,7 @@ mod gen; use avr_mcu::*; use std::fs::{self, File}; -use std::io; +use std::{env, io}; use std::io::prelude::*; use std::path::{Path, PathBuf}; @@ -12,7 +12,7 @@ use std::path::{Path, PathBuf}; /// archicectures that are not AVR. const DEFAULT_MCU_FOR_NON_AVR_DOCS: &'static str = "atmega328"; -const DEFAULT_FREQUENCY_HZ_FOR_NON_AVR_DOCS: &'static str = "16_000_000"; +const DEFAULT_FREQUENCY_HZ_FOR_NON_AVR_DOCS: u64 = 16_000_000; fn src_path() -> PathBuf { Path::new(env!("CARGO_MANIFEST_DIR")).join("src") @@ -53,8 +53,11 @@ fn generate_config_module() -> Result<(), io::Error> { let path = src_path().join("config.rs"); let mut f = File::create(&path)?; - let clock = if cfg!(arch = "avr") { - env!("AVR_CPU_FREQUENCY_HZ") + let clock: u64 = if cfg!(arch = "avr") { + env::var("AVR_CPU_FREQUENCY_HZ") + .expect("Please set the '$AVR_CPU_FREQUENCY_HZ' environment variable") + .parse() + .expect("The $AVR_CPU_FREQUENCY_HZ environment variable is not an integer") } else { DEFAULT_FREQUENCY_HZ_FOR_NON_AVR_DOCS };