diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..2422eba --- /dev/null +++ b/build.rs @@ -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"); + } +} diff --git a/src/ui/ui.rs b/src/ui/ui.rs index 35d395c..9ca84f1 100644 --- a/src/ui/ui.rs +++ b/src/ui/ui.rs @@ -417,7 +417,7 @@ pub fn draw_ui( .position_pivot([0.5, 0.5]) .build(|| { 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.spacing(); ui.spacing();