use std::ops::Add;
use chrono::Utc;
fn main() {
if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows" {
let mut res = winresource::WindowsResource::new();
res.set_icon("../MDB_Logo.ico").set_language(0x0009);
res.compile().unwrap();
}
let git_output = std::process::Command::new("git")
.args(["rev-parse", "--git-dir"])
.output()
.ok();
let git_dir = git_output
.as_ref()
.and_then(|output| std::str::from_utf8(&output.stdout).ok().map(str::trim));
if let Some(git_dir) = git_dir {
let git_path = std::path::Path::new(git_dir);
let refs_path = git_path.join("refs");
if git_path.join("HEAD").exists() {
println!("cargo:rerun-if-changed={}/HEAD", git_dir);
}
if git_path.join("packed-refs").exists() {
println!("cargo:rerun-if-changed={}/packed-refs", git_dir);
}
if refs_path.join("heads").exists() {
println!("cargo:rerun-if-changed={}/refs/heads", git_dir);
}
if refs_path.join("tags").exists() {
println!("cargo:rerun-if-changed={}/refs/tags", git_dir);
}
let git_short_hash_cmd = std::process::Command::new("git")
.args(["rev-parse", "--short", "head"])
.output()
.ok();
let git_short_hash = git_short_hash_cmd
.as_ref()
.and_then(|output| std::str::from_utf8(&output.stdout).ok().map(str::trim));
let mut git_describe = String::from(env!("CARGO_PKG_VERSION"));
if let Some(git_short_hash) = git_short_hash {
git_describe = format!("v{git_describe}-{git_short_hash}");
}
let git_dirty_cmd = std::process::Command::new("git")
.args(["describe", "--dirty"])
.output()
.ok();
let git_dirty = git_dirty_cmd
.as_ref()
.and_then(|output| std::str::from_utf8(&output.stdout).ok().map(str::trim));
let dirty = git_dirty.map(|d| d.contains("dirty")).unwrap_or(false);
if dirty {
git_describe = git_describe.add("-dirty");
}
println!("cargo:rustc-env=MDB_VERSION={}", git_describe);
} else {
println!("cargo:rustc-env=MDB_VERSION=v{}", env!("CARGO_PKG_VERSION"));
}
println!(
"cargo:rustc-env=MDB_BUILD_DATE={}",
Utc::now().format("%Y-%m-%d")
);
}