add build.rs to export GIT_HASH for us

This commit is contained in:
2023-10-24 00:35:28 +02:00
parent 9988028bf0
commit 7f4d5f8bcc
2 changed files with 25 additions and 1 deletions
+24
View File
@@ -0,0 +1,24 @@
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");
}
}
+1 -1
View File
@@ -417,7 +417,7 @@ pub fn draw_ui(
.position_pivot([0.5, 0.5]) .position_pivot([0.5, 0.5])
.build(|| { .build(|| {
ui.text("3dobs - 3D Object Browser"); ui.text("3dobs - 3D Object Browser");
ui.text(format!("Version: {}-{}", env!("CARGO_PKG_VERSION"), option_env!("GIT_HASH").unwrap_or("unknown"))); ui.text(format!("Version: {}-{}", env!("CARGO_PKG_VERSION"), env!("GIT_HASH")));
ui.text(format!("{}", env!("CARGO_PKG_DESCRIPTION"))); ui.text(format!("{}", env!("CARGO_PKG_DESCRIPTION")));
ui.spacing(); ui.spacing();
ui.spacing(); ui.spacing();