Files
worklane/build.rs
T
Ansho ReiandClaude Opus 5 32a43b5201 (c28bc04) Report the version and the commit it was built from
worklane --version exited 2: the Cli derive set name and about but never
version, so clap generated no flag. Nothing could say what a given binary
was, which matters here because the opencode tools shell out to whatever
worklane is on PATH, so an agent can be driving a stale build with no way
to notice.

The crate version alone would not have answered it. Cargo.toml is pinned
at 0.1.0 and nobody bumps it per install, so a stale install and a fresh
build both claim the same thing. A build script stamps the short sha
alongside it, giving "worklane 0.1.0 (df97b06)", and falls back to
"unknown" where there is no git directory, as when installing from a
published crate.

propagate_version lets subcommands answer too. This overrides the ticket's
own plan step, which said to skip the sha if it needed a build script.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-20 14:48:37 +02:00

39 lines
1.1 KiB
Rust

//! Stamps the build with the commit it came from.
//!
//! The crate version alone cannot tell a stale install from a fresh build: it is
//! pinned at 0.1.0 and nobody bumps it per install, so both binaries claim the
//! same thing. The short sha is what makes `worklane --version` able to answer
//! "is this the binary with the fix in it".
//!
//! Absent a git directory, as when installing from a published crate, the sha is
//! "unknown" rather than a build failure.
use std::process::Command;
fn main() {
// Without these, an incremental build keeps stamping the sha it first saw.
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rerun-if-changed=.git/refs");
println!("cargo:rustc-env=WORKLANE_GIT_SHA={}", git_sha());
}
fn git_sha() -> String {
let output = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output();
let sha = match output {
Ok(output) if output.status.success() => String::from_utf8_lossy(&output.stdout)
.trim()
.to_string(),
_ => String::new(),
};
if sha.is_empty() {
"unknown".to_string()
} else {
sha
}
}