From 48a59496b28c1bb0666397d276fe79837712bfc1 Mon Sep 17 00:00:00 2001 From: DuProcess <273172371+DuProcess@users.noreply.github.com> Date: Sat, 27 Jun 2026 13:45:48 -0400 Subject: [PATCH] Expose build identity in version output --- Cargo.lock | 2 +- Cargo.toml | 2 +- build.rs | 26 ++++++++++++++++++++++++++ src/bin/dosh-auth.rs | 5 +++++ src/bin/dosh-bench.rs | 6 +++++- src/bin/dosh-client.rs | 6 +++++- src/bin/dosh-server.rs | 6 +++++- src/build_info.rs | 11 +++++++++++ src/lib.rs | 1 + 9 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 build.rs create mode 100644 src/build_info.rs diff --git a/Cargo.lock b/Cargo.lock index 17f95df..2ebc74c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -436,7 +436,7 @@ dependencies = [ [[package]] name = "dosh" -version = "0.1.1" +version = "0.1.2" dependencies = [ "anyhow", "base64", diff --git a/Cargo.toml b/Cargo.toml index 294fe37..9f5e165 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dosh" -version = "0.1.1" +version = "0.1.2" edition = "2024" license = "MIT" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..2e13954 --- /dev/null +++ b/build.rs @@ -0,0 +1,26 @@ +use std::process::Command; + +fn git(args: &[&str]) -> Option { + let output = Command::new("git").args(args).output().ok()?; + if !output.status.success() { + return None; + } + let text = String::from_utf8(output.stdout).ok()?; + Some(text.trim().to_string()) +} + +fn main() { + println!("cargo:rerun-if-changed=.git/HEAD"); + println!("cargo:rerun-if-changed=.git/index"); + + let hash = git(&["rev-parse", "--short=12", "HEAD"]).unwrap_or_else(|| "unknown".into()); + let date = git(&["show", "-s", "--format=%cs", "HEAD"]).unwrap_or_else(|| "unknown".into()); + let dirty = Command::new("git") + .args(["diff", "--quiet", "--ignore-submodules", "--"]) + .status() + .map(|status| if status.success() { "" } else { "+dirty" }) + .unwrap_or(""); + + println!("cargo:rustc-env=DOSH_GIT_HASH={hash}{dirty}"); + println!("cargo:rustc-env=DOSH_COMMIT_DATE={date}"); +} diff --git a/src/bin/dosh-auth.rs b/src/bin/dosh-auth.rs index 0692e10..8782f16 100644 --- a/src/bin/dosh-auth.rs +++ b/src/bin/dosh-auth.rs @@ -5,6 +5,11 @@ use dosh::config::load_server_config; use dosh::native::{host_public_key, host_public_key_line, load_or_create_host_key}; #[derive(Debug, Parser)] +#[command( + name = "dosh-auth", + version = dosh::build_info::VERSION, + long_version = dosh::build_info::LONG_VERSION +)] struct Args { #[arg(long, default_value_t = 1)] protocol: u8, diff --git a/src/bin/dosh-bench.rs b/src/bin/dosh-bench.rs index 2011d1c..b65165b 100644 --- a/src/bin/dosh-bench.rs +++ b/src/bin/dosh-bench.rs @@ -11,7 +11,11 @@ use std::sync::mpsc; use std::time::{Duration, Instant}; #[derive(Debug, Parser)] -#[command(name = "dosh-bench")] +#[command( + name = "dosh-bench", + version = dosh::build_info::VERSION, + long_version = dosh::build_info::LONG_VERSION +)] struct Args { #[arg(long, default_value = "local")] server: String, diff --git a/src/bin/dosh-client.rs b/src/bin/dosh-client.rs index 1da07df..f51c6d6 100644 --- a/src/bin/dosh-client.rs +++ b/src/bin/dosh-client.rs @@ -69,7 +69,11 @@ fn terminal_size() -> (u16, u16) { } #[derive(Debug, Clone, Parser)] -#[command(name = "dosh-client", version)] +#[command( + name = "dosh-client", + version = dosh::build_info::VERSION, + long_version = dosh::build_info::LONG_VERSION +)] struct Args { #[arg()] server: Option, diff --git a/src/bin/dosh-server.rs b/src/bin/dosh-server.rs index 0f74072..9865de6 100644 --- a/src/bin/dosh-server.rs +++ b/src/bin/dosh-server.rs @@ -51,7 +51,11 @@ static AGENT_SOCK_COUNTER: AtomicU64 = AtomicU64::new(0); const NATIVE_HANDSHAKE_TTL_SECS: u64 = 30; #[derive(Debug, Parser)] -#[command(name = "dosh-server")] +#[command( + name = "dosh-server", + version = dosh::build_info::VERSION, + long_version = dosh::build_info::LONG_VERSION +)] struct Args { #[command(subcommand)] command: Command, diff --git a/src/build_info.rs b/src/build_info.rs new file mode 100644 index 0000000..7a8edd4 --- /dev/null +++ b/src/build_info.rs @@ -0,0 +1,11 @@ +pub const VERSION: &str = env!("CARGO_PKG_VERSION"); +pub const GIT_HASH: &str = env!("DOSH_GIT_HASH"); +pub const COMMIT_DATE: &str = env!("DOSH_COMMIT_DATE"); +pub const LONG_VERSION: &str = concat!( + env!("CARGO_PKG_VERSION"), + " (", + env!("DOSH_GIT_HASH"), + ", ", + env!("DOSH_COMMIT_DATE"), + ")" +); diff --git a/src/lib.rs b/src/lib.rs index 52cbf08..08cb824 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ pub mod auth; +pub mod build_info; pub mod config; pub mod crypto; pub mod native;