Files
OpenFUT/openfut-redirector-host/build.rs
T
funman300 c03702707b redirector: commit stamp + shared build-identity verifier that REFUSES
The binary records only the commit it was built from -- no dirty-tree flag.
Cargo will not re-run a build script because another crate's source changed, so
a compiled-in 'clean' claim can be stale and is not a safeguard; that was
verified on the Blaze host.

scripts/verify-build-identity.sh establishes both facts at LAUNCH, where they
cannot go stale: the stamped commit equals HEAD, and the migration crates are
clean. It REFUSES rather than warns, because for a migration gate a warning on
stderr is something to scroll past.

--identity prints the stamp without valid configuration. The launcher must be
able to establish which commit a binary came from BEFORE deciding whether to
run it; requiring a correct environment first would invert the check.

redirector.sh mirrors sidecar.sh: refuses to start with an orphan present or
the port busy, matches the resolved executable rather than the command line
(pgrep -f matches any shell mentioning the name), and stop PROVES the process
is gone and the port free.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-11 03:46:07 +00:00

40 lines
1.5 KiB
Rust

//! Stamp the commit this binary was built from.
//!
//! Deliberately records ONLY the commit — no dirty-tree flag. Cargo will not
//! re-run a build script because another crate's source changed, so a
//! compiled-in "clean" claim can be stale and is therefore not a safeguard.
//! (Verified on the Blaze host: editing the adapter and rebuilding left its
//! flag reading clean.)
//!
//! The authoritative checks run at launch, in `scripts/verify-build-identity.sh`,
//! which compares this stamp against the checkout's real HEAD and inspects the
//! working tree as it is at that moment.
use std::process::Command;
fn git(args: &[&str]) -> Option<String> {
let out = Command::new("git").args(args).output().ok()?;
out.status
.success()
.then(|| String::from_utf8_lossy(&out.stdout).trim().to_string())
}
fn main() {
let commit = git(&["rev-parse", "--short=7", "HEAD"]).unwrap_or_else(|| "unknown".into());
println!("cargo:rustc-env=OPENFUT_BUILD_COMMIT={commit}");
// Committing updates refs/heads/<branch>, not the HEAD file, so watching
// HEAD alone leaves the stamp a commit behind.
for p in ["../.git/HEAD", "../.git/index"] {
if std::path::Path::new(p).exists() {
println!("cargo:rerun-if-changed={p}");
}
}
if let Some(rf) = git(&["symbolic-ref", "-q", "HEAD"]) {
let path = format!("../.git/{rf}");
if std::path::Path::new(&path).exists() {
println!("cargo:rerun-if-changed={path}");
}
}
}