fabro/lib/crates/fabro-cli/build.rs
Bryan Helmkamp b0349e9873
feat(cli): surface debug build profile in version output
Non-release builds now append the profile to `fabro --version`
(`x.y (sha date debug)`), `fabro version`, and `fabro system info`,
so users can tell a local build apart from a shipped release. The
API's `SystemInfoResponse` gains a `profile` field so the client
can render the server's build profile too.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 09:44:54 -04:00

36 lines
1.2 KiB
Rust

#[expect(
clippy::disallowed_methods,
reason = "Build scripts run outside Tokio and need a synchronous git probe for the embedded build SHA."
)]
fn main() {
println!("cargo:rerun-if-changed=../../../.git/HEAD");
let sha = std::process::Command::new("git")
.args(["rev-list", "-1", "HEAD"])
.output()
.ok()
.and_then(|o| {
if o.status.success() {
String::from_utf8(o.stdout)
.ok()
.map(|s| s.trim().to_string())
} else {
None
}
})
.unwrap_or_default();
let short_sha = if sha.len() >= 7 { &sha[..7] } else { &sha };
println!("cargo:rustc-env=FABRO_GIT_SHA={short_sha}");
let build_date = chrono::Utc::now().format("%Y-%m-%d").to_string();
println!("cargo:rustc-env=FABRO_BUILD_DATE={build_date}");
let profile = std::env::var("PROFILE").unwrap_or_default();
let profile_suffix = if profile == "release" {
String::new()
} else {
format!(" {profile}")
};
println!("cargo:rustc-env=FABRO_BUILD_PROFILE={profile}");
println!("cargo:rustc-env=FABRO_BUILD_PROFILE_SUFFIX={profile_suffix}");
}