constants: use build-time COMMIT env var

This commit is contained in:
hinto.janai 2023-11-24 09:30:15 -05:00
parent ea79447133
commit 8976641d48
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
2 changed files with 22 additions and 2 deletions

View file

@ -5,6 +5,8 @@
// pre-compiled bytes using [include_bytes!()] on the images in [images/]. // pre-compiled bytes using [include_bytes!()] on the images in [images/].
#[cfg(windows)] #[cfg(windows)]
fn main() -> std::io::Result<()> { fn main() -> std::io::Result<()> {
set_commit_env();
static_vcruntime::metabuild(); static_vcruntime::metabuild();
let mut res = winres::WindowsResource::new(); let mut res = winres::WindowsResource::new();
// This sets the icon. // This sets the icon.
@ -27,4 +29,22 @@ fn main() -> std::io::Result<()> {
} }
#[cfg(unix)] #[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}");
}

View file

@ -18,7 +18,7 @@
pub const GUPAX_VERSION: &str = concat!("v", env!("CARGO_PKG_VERSION")); // e.g: v1.0.0 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 P2POOL_VERSION: &str = "v3.7";
pub const XMRIG_VERSION: &str = "v6.20.0"; 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 // e.g: Gupax_v1_0_0
// Would have been [Gupax_v1.0.0] but P2Pool truncates everything after [.] // Would have been [Gupax_v1.0.0] but P2Pool truncates everything after [.]
pub const GUPAX_VERSION_UNDERSCORE: &str = concat!( pub const GUPAX_VERSION_UNDERSCORE: &str = concat!(