From 5419443fe065e36cf7b8742ab490ba3a4a6aed72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20P=C5=82aczek?= Date: Sat, 7 Sep 2024 17:39:07 +0100 Subject: [PATCH] feat: log build commit --- build.rs | 28 ++++++++++++++++++++++++++++ src/main.rs | 5 +++++ 2 files changed, 33 insertions(+) create mode 100644 build.rs diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..b7d7bf0 --- /dev/null +++ b/build.rs @@ -0,0 +1,28 @@ +use std::process::Command; + +// https://stackoverflow.com/a/44407625/19020549 + +#[allow(clippy::unnecessary_wraps)] +fn try_main() -> Result<(), Box> { + let Ok(output) = Command::new("git") + .args(["rev-parse", "--short", "HEAD"]) + .output() + else { + return Err("Failed to get current Git commit using command".into()); + }; + + let Ok(git_hash) = String::from_utf8(output.stdout) else { + return Err("Failed to convert Git output to UTF-8 string".into()); + }; + + println!("cargo:rustc-env=GIT_HASH={git_hash}"); + + Ok(()) +} + +fn main() { + if let Err(e) = try_main() { + eprintln!("Error: {e:#?}"); + std::process::exit(1) + } +} diff --git a/src/main.rs b/src/main.rs index e75c657..4495bfa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -104,6 +104,11 @@ async fn main() -> Result<()> { .init(); } tracing::info!("Logging to {log_path:?}"); + tracing::debug!( + "Running {} built from Git commit {}", + env!("CARGO_CRATE_NAME"), + env!("GIT_HASH") + ); tracing::info!("Creating TLS config"); let cert_dirs_to_search = get_cert_dirs_to_search(&exe_path);