Skip to content

Commit 265ab3b

Browse files
committed
Use $CARGO_PKG_VERSION from buildscript exec-time instead of build-time
1 parent c6f0815 commit 265ab3b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

build.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1+
use std::env;
2+
use std::ffi::OsString;
3+
use std::process;
4+
15
fn main() {
26
println!("cargo:rerun-if-changed=build.rs");
37

48
println!("cargo:rustc-check-cfg=cfg(exhaustive)");
59
println!("cargo:rustc-check-cfg=cfg(prettyplease_debug)");
610
println!("cargo:rustc-check-cfg=cfg(prettyplease_debug_indent)");
711

8-
println!(concat!("cargo:VERSION=", env!("CARGO_PKG_VERSION")));
12+
let pkg_version = cargo_env_var("CARGO_PKG_VERSION");
13+
println!("cargo:VERSION={}", pkg_version.to_str().unwrap());
14+
}
15+
16+
fn cargo_env_var(key: &str) -> OsString {
17+
env::var_os(key).unwrap_or_else(|| {
18+
eprintln!("Environment variable ${key} is not set during execution of build script");
19+
process::exit(1);
20+
})
921
}

0 commit comments

Comments
 (0)