diff --git a/build.rs b/build.rs index 770ae56..c380dd0 100755 --- a/build.rs +++ b/build.rs @@ -5,6 +5,8 @@ // pre-compiled bytes using [include_bytes!()] on the images in [images/]. #[cfg(windows)] fn main() -> std::io::Result<()> { + set_commit_env(); + static_vcruntime::metabuild(); let mut res = winres::WindowsResource::new(); // This sets the icon. @@ -27,4 +29,22 @@ fn main() -> std::io::Result<()> { } #[cfg(unix)] -fn main() {} +fn main() { + set_commit_env(); +} + +// Set the current git commit to the env var [COMMIT]. +fn set_commit_env() { + println!("cargo:rerun-if-changed=.git/refs/heads/"); + + let output = std::process::Command::new("git") + .args(["rev-parse", "HEAD"]) + .output() + .unwrap(); + + let commit = String::from_utf8(output.stdout).unwrap(); + + assert!(commit.len() >= 40); + + println!("cargo:rustc-env=COMMIT={commit}"); +} diff --git a/src/constants.rs b/src/constants.rs index 5f30fa7..a132a8b 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -18,7 +18,7 @@ pub const GUPAX_VERSION: &str = concat!("v", env!("CARGO_PKG_VERSION")); // e.g: v1.0.0 pub const P2POOL_VERSION: &str = "v3.7"; pub const XMRIG_VERSION: &str = "v6.20.0"; -pub const COMMIT: &str = include_str!("../.git/refs/heads/main"); +pub const COMMIT: &str = env!("COMMIT"); // set in build.rs // e.g: Gupax_v1_0_0 // Would have been [Gupax_v1.0.0] but P2Pool truncates everything after [.] pub const GUPAX_VERSION_UNDERSCORE: &str = concat!(