Skip to content

Commit

Permalink
Use $CARGO_PKG_VERSION from buildscript exec-time instead of build-time
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 23, 2024
1 parent c6f0815 commit 265ab3b
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 265ab3b

Please sign in to comment.