Use std::env::var rather than env! in the build script

This will let the crate build on crates.io.
This commit is contained in:
Dylan McKay 2018-11-06 00:03:06 +13:00
parent 7f3f874eec
commit e2443720fb
1 changed files with 7 additions and 4 deletions

View File

@ -4,7 +4,7 @@ mod gen;
use avr_mcu::*; use avr_mcu::*;
use std::fs::{self, File}; use std::fs::{self, File};
use std::io; use std::{env, io};
use std::io::prelude::*; use std::io::prelude::*;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -12,7 +12,7 @@ use std::path::{Path, PathBuf};
/// archicectures that are not AVR. /// archicectures that are not AVR.
const DEFAULT_MCU_FOR_NON_AVR_DOCS: &'static str = "atmega328"; 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 { fn src_path() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("src") 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 path = src_path().join("config.rs");
let mut f = File::create(&path)?; let mut f = File::create(&path)?;
let clock = if cfg!(arch = "avr") { let clock: u64 = if cfg!(arch = "avr") {
env!("AVR_CPU_FREQUENCY_HZ") 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 { } else {
DEFAULT_FREQUENCY_HZ_FOR_NON_AVR_DOCS DEFAULT_FREQUENCY_HZ_FOR_NON_AVR_DOCS
}; };