worklyn / zukapublic
Agent-first git hosting. One Rust binary: git over HTTP and SSH, a REST API, MCP, CI, and multi-tenant isolation.
Get a copy:
git clone https://zuka.worklyn.com/worklyn/zuka.git
| 1 | // Embeds the git commit into the binary. |
| 2 | // |
| 3 | // The semantic version is bumped by CI and is for humans. The build identity is |
| 4 | // version plus commit, and it is what upgrade detection compares — because a |
| 5 | // forgotten version bump would otherwise make an old tenant look current, and the |
| 6 | // failure mode of that is a security patch silently not landing. |
| 7 | |
| 8 | use std::process::Command; |
| 9 | |
| 10 | fn main() { |
| 11 | let commit = Command::new("git") |
| 12 | .args(["rev-parse", "--short=12", "HEAD"]) |
| 13 | .output() |
| 14 | .ok() |
| 15 | .filter(|o| o.status.success()) |
| 16 | .map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string()) |
| 17 | .filter(|s| !s.is_empty()) |
| 18 | // A source tarball with no git history still has to build. `unknown` is a |
| 19 | // distinct value, so two such builds compare equal — which is the honest |
| 20 | // answer when there is nothing to distinguish them. |
| 21 | .unwrap_or_else(|| "unknown".to_string()); |
| 22 | |
| 23 | let dirty = Command::new("git") |
| 24 | .args(["status", "--porcelain"]) |
| 25 | .output() |
| 26 | .ok() |
| 27 | .filter(|o| o.status.success()) |
| 28 | .map(|o| !o.stdout.is_empty()) |
| 29 | .unwrap_or(false); |
| 30 | |
| 31 | println!( |
| 32 | "cargo:rustc-env=ZUKA_BUILD_COMMIT={commit}{}", |
| 33 | if dirty { "-dirty" } else { "" } |
| 34 | ); |
| 35 | |
| 36 | // Rebuild when HEAD moves, so the embedded commit cannot go stale. |
| 37 | println!("cargo:rerun-if-changed=.git/HEAD"); |
| 38 | println!("cargo:rerun-if-changed=.git/refs"); |
| 39 | } |