35 lines
1.0 KiB
Rust
35 lines
1.0 KiB
Rust
use std::process::Command;
|
|
|
|
fn main() {
|
|
let mut git_hash = Command::new("git")
|
|
.args(["rev-parse", "--short", "HEAD"])
|
|
.output()
|
|
.ok()
|
|
.and_then(|out| String::from_utf8(out.stdout).ok())
|
|
.unwrap_or_else(|| "unknown".to_string());
|
|
|
|
git_hash = git_hash.trim().to_string();
|
|
|
|
let is_dirty = Command::new("git")
|
|
.args(["status", "--porcelain"])
|
|
.output()
|
|
.is_ok_and(|out| !out.stdout.is_empty());
|
|
|
|
if is_dirty {
|
|
git_hash.push_str("-dirty");
|
|
}
|
|
|
|
let build_date = chrono::Local::now().format("%y.%m.%d.%H%M%S").to_string();
|
|
|
|
let version = format!("{build_date} ({git_hash})");
|
|
println!("cargo:rustc-env=APP_VERSION={version}");
|
|
println!("cargo:rerun-if-changed=../.git/HEAD");
|
|
println!("cargo:rerun-if-changed=../.git/index");
|
|
|
|
if std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default() == "windows" {
|
|
let mut res = winres::WindowsResource::new();
|
|
res.set_icon("app.ico");
|
|
res.compile().unwrap();
|
|
}
|
|
}
|