Skip to content

Commit

Permalink
Merge pull request #84 from dtolnay/buildenv
Browse files Browse the repository at this point in the history
Use $CARGO_PKG_VERSION from buildscript exec-time instead of build-time
  • Loading branch information
dtolnay authored Oct 23, 2024
2 parents c6f0815 + 265ab3b commit 91ebe48
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
use std::env;
use std::ffi::OsString;
use std::process;

fn main() {
println!("cargo:rerun-if-changed=build.rs");

println!("cargo:rustc-check-cfg=cfg(exhaustive)");
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);
})
}

0 comments on commit 91ebe48

Please sign in to comment.