diff --git a/ldk-server-cli/build.rs b/ldk-server-cli/build.rs new file mode 100644 index 00000000..cc6e3d1c --- /dev/null +++ b/ldk-server-cli/build.rs @@ -0,0 +1,26 @@ +// This file is Copyright its original authors, visible in version control +// history. +// +// This file is licensed under the Apache License, Version 2.0 or the MIT license +// , at your option. +// You may not use this file except in accordance with one or both of these +// licenses. + +use std::env; +use std::process::Command; + +fn main() { + println!("cargo:rerun-if-changed=build.rs"); + println!("cargo:rerun-if-env-changed=GIT_HASH"); + + if env::var("GIT_HASH").is_err() { + let output = Command::new("git") + .args(["rev-parse", "HEAD"]) + .output() + .expect("Failed to execute 'git rev-parse HEAD' command"); + + let git_hash = String::from_utf8_lossy(&output.stdout).trim().to_string(); + println!("cargo:rustc-env=GIT_HASH={git_hash}"); + } +} diff --git a/ldk-server-cli/src/main.rs b/ldk-server-cli/src/main.rs index 3aa6f1c8..918f57a3 100644 --- a/ldk-server-cli/src/main.rs +++ b/ldk-server-cli/src/main.rs @@ -60,6 +60,8 @@ use types::{ mod types; +const FULL_VERSION: &str = concat!(env!("CARGO_PKG_VERSION"), " (", env!("GIT_HASH"), ")"); + const DEFAULT_DIR: &str = if cfg!(target_os = "macos") { "~/Library/Application Support/ldk-server" } else if cfg!(target_os = "windows") { @@ -71,7 +73,7 @@ const DEFAULT_DIR: &str = if cfg!(target_os = "macos") { #[derive(Parser, Debug)] #[command( name = "ldk-server-cli", - version, + version = FULL_VERSION, about = "CLI for interacting with an LDK Server node", override_usage = "ldk-server-cli [OPTIONS] " )] diff --git a/ldk-server/build.rs b/ldk-server/build.rs new file mode 100644 index 00000000..cc6e3d1c --- /dev/null +++ b/ldk-server/build.rs @@ -0,0 +1,26 @@ +// This file is Copyright its original authors, visible in version control +// history. +// +// This file is licensed under the Apache License, Version 2.0 or the MIT license +// , at your option. +// You may not use this file except in accordance with one or both of these +// licenses. + +use std::env; +use std::process::Command; + +fn main() { + println!("cargo:rerun-if-changed=build.rs"); + println!("cargo:rerun-if-env-changed=GIT_HASH"); + + if env::var("GIT_HASH").is_err() { + let output = Command::new("git") + .args(["rev-parse", "HEAD"]) + .output() + .expect("Failed to execute 'git rev-parse HEAD' command"); + + let git_hash = String::from_utf8_lossy(&output.stdout).trim().to_string(); + println!("cargo:rustc-env=GIT_HASH={git_hash}"); + } +} diff --git a/ldk-server/src/main.rs b/ldk-server/src/main.rs index 1d12cd21..6d2dc9a6 100644 --- a/ldk-server/src/main.rs +++ b/ldk-server/src/main.rs @@ -58,6 +58,7 @@ use crate::util::tls::get_or_generate_tls_config; use crate::util::{systemd, write_new}; const API_KEY_FILE: &str = "api_key"; +const FULL_VERSION: &str = concat!(env!("CARGO_PKG_VERSION"), " (", env!("GIT_HASH"), ")"); pub fn get_default_data_dir() -> Option { #[cfg(target_os = "macos")] @@ -241,7 +242,7 @@ fn main() { let (event_sender, _) = broadcast::channel::(1024); let (shutdown_tx, shutdown_rx) = tokio::sync::watch::channel(false); - info!("Starting up..."); + info!("Starting ldk-server version {FULL_VERSION}"); match node.start() { Ok(()) => {}, Err(e) => { diff --git a/ldk-server/src/util/config.rs b/ldk-server/src/util/config.rs index 0bf0d115..1a342fe1 100644 --- a/ldk-server/src/util/config.rs +++ b/ldk-server/src/util/config.rs @@ -742,7 +742,7 @@ impl TryFrom<&LSPSClientTomlConfig> for LSPSClientConfig { #[derive(Parser, Debug)] #[command( - version, + version = crate::FULL_VERSION, about = "LDK Server Configuration", long_about = None, override_usage = "ldk-server [config_path]"