From d971f36f10f055dbda95a26e9f6a3404770f4d54 Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Sat, 4 Jul 2026 18:58:33 +0200 Subject: [PATCH] chore(firmware): stamp builds with UTC time and git hash Emit BUILD_TIME and BUILD_GIT (git describe --always --dirty) as rustc env vars so the running firmware can identify itself on serial and on-panel. A rerun-if-changed on a nonexistent file forces the script every build, keeping the timestamp fresh. Bring-up lesson: know which build you're diagnosing. --- firmware/build.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/firmware/build.rs b/firmware/build.rs index 112ec3f..8eaeefd 100644 --- a/firmware/build.rs +++ b/firmware/build.rs @@ -1,3 +1,27 @@ +use std::process::Command; + fn main() { embuild::espidf::sysenv::output(); + + // Stamp the binary so serial output and on-panel text identify the + // exact build (bring-up lesson: know which build you're diagnosing). + let git = Command::new("git") + .args(["describe", "--always", "--dirty"]) + .output() + .ok() + .filter(|o| o.status.success()) + .map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string()) + .unwrap_or_else(|| "unknown".into()); + let time = Command::new("date") + .args(["-u", "+%m-%d %H:%M"]) + .output() + .ok() + .filter(|o| o.status.success()) + .map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string()) + .unwrap_or_else(|| "unknown".into()); + println!("cargo:rustc-env=BUILD_GIT={git}"); + println!("cargo:rustc-env=BUILD_TIME={time}Z"); + // Pointing rerun-if-changed at a file that never exists forces this + // script to rerun on every build, keeping BUILD_TIME fresh. + println!("cargo:rerun-if-changed=.force-build-stamp"); }