facett-demo build stamp (version + git-hash)
The nordisk LAW: every shipped binary must be able to tell an operator WHICH build is running. facett-demo was the one facett binary still missing it — it had no build.rs and no --version. This note records how it now complies.
What was added
-
facett-demo/build.rs— facett-demo's only build-time work. It reads the git metadata as plain files only (NOgit, NOstd::process::Command, NO shell — the pure-Rust zero-shell law) and emitscargo:rustc-env=FACETT_GIT_HASH=<short sha>(12 chars). It handles:- a normal
.gitdirectory, - a linked-worktree
.gitfile (gitdir: <path>→ the worktree gitdir, whose refs live in the sharedcommondir), - a workspace subdir (walks up from
CARGO_MANIFEST_DIRto the repo root), - loose refs and the
packed-refsfallback, - a detached HEAD (the sha is in
HEADdirectly), - and falls back to
unknown(a crates.io tarball build has no.git), soenv!("FACETT_GIT_HASH")always resolves.
- a normal
cargo:rerun-if-changed is emitted for HEAD, the resolved loose ref, and packed-refs, so the stamp refreshes on commit/checkout without a clean rebuild.
-
facett_demo::version_line()(insrc/lib.rs) — returnsfacett-demo v<CARGO_PKG_VERSION> (<FACETT_GIT_HASH>), the single source of the stamp string. -
--version/-V(insrc/main.rs, nativemain) — printsversion_line()andreturn Ok(())beforeeframe::NativeOptions/run_native, so it never brings up the viewport. -
Gallery header —
draw_control_stripshows the stamp as a weak label beside thefacett-demoheading (full line on hover), so the running build is visible in the live app too.
Proof
$ cargo build --release -p facett-demo --bin facett-demo
$ ./target/release/facett-demo --version
facett-demo v0.1.13 (003697de8dab)
The hash matches main HEAD 003697d.
Notes
- This is a native-only stamp: the wasm
mainis empty and the web demo is not a CLI, so--versionis gated behindcfg(not(target_arch = "wasm32"))implicitly by living in the nativemain.version_line()and the header label arecfg-free (they only read compile-time env), so the wasm build carries the same stamp string for the header. - Pattern mirrors the sibling
dwarves-demo/build.rs/version_line()(same LAW).