diff --git a/build.rs b/build.rs index 9518c8d..4fc36f7 100644 --- a/build.rs +++ b/build.rs @@ -1,3 +1,7 @@ +use std::env; +use std::ffi::OsString; +use std::process; + fn main() { println!("cargo:rerun-if-changed=build.rs"); @@ -5,5 +9,13 @@ fn main() { println!("cargo:rustc-check-cfg=cfg(prettyplease_debug)"); println!("cargo:rustc-check-cfg=cfg(prettyplease_debug_indent)"); - println!(concat!("cargo:VERSION=", env!("CARGO_PKG_VERSION"))); + let pkg_version = cargo_env_var("CARGO_PKG_VERSION"); + println!("cargo:VERSION={}", pkg_version.to_str().unwrap()); +} + +fn cargo_env_var(key: &str) -> OsString { + env::var_os(key).unwrap_or_else(|| { + eprintln!("Environment variable ${key} is not set during execution of build script"); + process::exit(1); + }) }