From b2da9bdbf5fcde9a6f1426a54c2269135267a0f8 Mon Sep 17 00:00:00 2001 From: murilo ijanc Date: Tue, 18 Nov 2025 13:57:40 -0300 Subject: Create build to fill environment variables git (commit and date) --- build.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 build.rs diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..52cbd9f --- /dev/null +++ b/build.rs @@ -0,0 +1,21 @@ +use std::process::Command; + +fn main() { + let git_hash = Command::new("git") + .args(["rev-parse", "HEAD"]) + .output() + .map(|out| String::from_utf8_lossy(&out.stdout).trim().to_string()) + .unwrap_or_else(|_| "unknown".into()); + + let git_date = Command::new("git") + .args(["show", "-s", "--format=%cI", "HEAD"]) + .output() + .map(|out| String::from_utf8_lossy(&out.stdout).trim().to_string()) + .unwrap_or_else(|_| "unknown".into()); + + println!("cargo:rustc-env=GIT_HASH={}", git_hash); + println!("cargo:rustc-env=BUILD_DATE={}", git_date); + + println!("cargo:rerun-if-changed=.git/HEAD"); + println!("cargo:rerun-if-changed=.git/refs/heads"); +} -- cgit v1.2.3