use std::{env, process::Command};
const NODE_BUILD_PROFILE_ENV_VAR: &str = "NODE_BUILD_PROFILE";
const NODE_GIT_HASH_ENV_VAR: &str = "NODE_GIT_SHA";
const CARGO_BUILD_PROFILE_ENV_VAR: &str = "PROFILE";
fn main() {
match Command::new("git")
.arg("rev-parse")
.arg("--short")
.arg("HEAD")
.output()
{
Ok(output) => {
let git_hash_raw =
String::from_utf8(output.stdout).expect("Failed to obtain commit hash to string");
let git_hash = git_hash_raw.trim_end_matches('\n');
println!("cargo:rustc-env={NODE_GIT_HASH_ENV_VAR}={git_hash}");
}
Err(error) => {
println!("cargo:warning={error}");
println!("cargo:warning=casper-node build version will not include git short hash");
}
}
println!(
"cargo:rustc-env={NODE_BUILD_PROFILE_ENV_VAR}={}",
env::var(CARGO_BUILD_PROFILE_ENV_VAR).unwrap()
);
}