From 1b3d3d900b855b168fa0b39a45c613bf72900a43 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Fri, 13 Mar 2026 15:03:12 -0400 Subject: [PATCH] Move git SHA/build date from fabro-util to fabro-cli build.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fabro-util is a low-level crate depended on by almost everything, so its build.rs reruns cascaded through the whole workspace. fabro-cli is the leaf binary — nothing depends on it, so rebuilds are limited to just that one crate. Co-Authored-By: Claude Opus 4.6 (1M context) --- lib/crates/fabro-cli/Cargo.toml | 3 +++ lib/crates/fabro-cli/build.rs | 23 +++++++++++++++++++ lib/crates/fabro-cli/src/main.rs | 11 ++++++++- lib/crates/fabro-util/Cargo.toml | 1 - lib/crates/fabro-util/build.rs | 22 ------------------ lib/crates/fabro-util/src/version.rs | 7 ------ .../fabro-workflows/src/cli/progress.rs | 2 +- 7 files changed, 37 insertions(+), 32 deletions(-) create mode 100644 lib/crates/fabro-cli/build.rs diff --git a/lib/crates/fabro-cli/Cargo.toml b/lib/crates/fabro-cli/Cargo.toml index 7f7979a07..1d71a2282 100644 --- a/lib/crates/fabro-cli/Cargo.toml +++ b/lib/crates/fabro-cli/Cargo.toml @@ -53,6 +53,9 @@ axum = "0.8" open = "5" serde_json.workspace = true +[build-dependencies] +chrono = { workspace = true } + [dev-dependencies] assert_cmd = "2" insta = { workspace = true } diff --git a/lib/crates/fabro-cli/build.rs b/lib/crates/fabro-cli/build.rs new file mode 100644 index 000000000..6ec1c3c48 --- /dev/null +++ b/lib/crates/fabro-cli/build.rs @@ -0,0 +1,23 @@ +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}"); +} diff --git a/lib/crates/fabro-cli/src/main.rs b/lib/crates/fabro-cli/src/main.rs index 4d1359a9d..417e241ac 100644 --- a/lib/crates/fabro-cli/src/main.rs +++ b/lib/crates/fabro-cli/src/main.rs @@ -11,8 +11,17 @@ use anyhow::Result; use clap::{Parser, Subcommand}; use tracing::debug; +const LONG_VERSION: &str = concat!( + env!("CARGO_PKG_VERSION"), + " (", + env!("FABRO_GIT_SHA"), + " ", + env!("FABRO_BUILD_DATE"), + ")" +); + #[derive(Parser)] -#[command(name = "fabro", version, long_version = fabro_util::version::LONG_VERSION.as_str())] +#[command(name = "fabro", version, long_version = LONG_VERSION)] struct Cli { /// Enable DEBUG-level logging (default is INFO) #[arg(long, global = true)] diff --git a/lib/crates/fabro-util/Cargo.toml b/lib/crates/fabro-util/Cargo.toml index d32c85db2..055b28b91 100644 --- a/lib/crates/fabro-util/Cargo.toml +++ b/lib/crates/fabro-util/Cargo.toml @@ -31,7 +31,6 @@ git2.workspace = true [build-dependencies] toml = "0.8" serde = { workspace = true } -chrono = { workspace = true } [dev-dependencies] insta = { workspace = true } diff --git a/lib/crates/fabro-util/build.rs b/lib/crates/fabro-util/build.rs index 6bcdb4808..f46bad7a0 100644 --- a/lib/crates/fabro-util/build.rs +++ b/lib/crates/fabro-util/build.rs @@ -53,28 +53,6 @@ fn escape_rust_string(s: &str) -> String { } fn main() { - // Emit git SHA and build date for version info - 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}"); - println!("cargo:rerun-if-changed=data/gitleaks.toml"); let toml_path = Path::new("data/gitleaks.toml"); diff --git a/lib/crates/fabro-util/src/version.rs b/lib/crates/fabro-util/src/version.rs index 5d897423f..52e6ae760 100644 --- a/lib/crates/fabro-util/src/version.rs +++ b/lib/crates/fabro-util/src/version.rs @@ -1,8 +1 @@ -use std::sync::LazyLock; - pub const FABRO_VERSION: &str = env!("CARGO_PKG_VERSION"); -pub const FABRO_GIT_SHA: &str = env!("FABRO_GIT_SHA"); -pub const FABRO_BUILD_DATE: &str = env!("FABRO_BUILD_DATE"); - -pub static LONG_VERSION: LazyLock = - LazyLock::new(|| format!("{FABRO_VERSION} ({FABRO_GIT_SHA} {FABRO_BUILD_DATE})")); diff --git a/lib/crates/fabro-workflows/src/cli/progress.rs b/lib/crates/fabro-workflows/src/cli/progress.rs index 135e511ed..895334b01 100644 --- a/lib/crates/fabro-workflows/src/cli/progress.rs +++ b/lib/crates/fabro-workflows/src/cli/progress.rs @@ -787,7 +787,7 @@ impl ProgressUI { } pub fn show_version(&mut self) { - let version = fabro_util::version::LONG_VERSION.as_str(); + let version = fabro_util::version::FABRO_VERSION; match &self.renderer { ProgressRenderer::Tty(tty) => { let bar = tty.multi.add(ProgressBar::new_spinner());