Skip to content

Commit

Permalink
Use env::var_os intead of env! in build script
Browse files Browse the repository at this point in the history
The env! method pulls the variable at *compile time* as opposed to runtime. This
can cause breakage in scenarios with cross compilation, for example. Currently
there's also a pending change to Cargo on the beta release of Rust which breaks
the usage of env! (rust-lang/cargo#3368).

We may roll that change back, but I figured it'd be good to head off future
breakage anyway!
  • Loading branch information
alexcrichton committed Dec 28, 2016
1 parent 7953798 commit 10f7cc6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ extern crate csv;
extern crate phf_codegen;
extern crate rustc_serialize;

use std::env;
use std::fs::File;
use std::io::{BufWriter, Write};
use std::path::Path;
Expand Down Expand Up @@ -60,7 +61,7 @@ impl TempRecord {
}

fn main() {
let path = Path::new(env!("OUT_DIR")).join("codegen.rs");
let path = Path::new(&env::var_os("OUT_DIR").unwrap()).join("codegen.rs");
let mut file = BufWriter::new(File::create(&path).unwrap());

write!(&mut file, "static ZIP_CODES: phf::Map<&'static str, Record> = ").unwrap();
Expand Down

0 comments on commit 10f7cc6

Please sign in to comment.