Files
3dobs/build.rs
T

25 lines
755 B
Rust
Raw Normal View History

2023-10-24 00:35:02 +02:00
use std::{env, process::Command};
fn main() {
// Get the current directory of the project
let project_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let output = Command::new("git")
.arg("rev-parse")
.arg("--short")
.arg("HEAD")
.current_dir(&project_dir)
.output()
.expect("Failed to execute git command");
if output.status.success() {
let commit_hash = String::from_utf8(output.stdout).expect("Git output is not valid UTF-8");
// Export the commit hash as a build-time constant
println!("cargo:rustc-env=GIT_HASH={}", commit_hash);
} else {
// Handle the case where the git command failed
eprintln!("Failed to get Git commit hash");
}
}