Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions ldk-server-cli/build.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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}");
}
}
4 changes: 3 additions & 1 deletion ldk-server-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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] <COMMAND>"
)]
Expand Down
26 changes: 26 additions & 0 deletions ldk-server/build.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make sure to update GIT_HASH if HEAD changes after the first from-clean build. Here it seems HEAD could change, and we'd ship a binary with a wrong rev ?

Or perhaps cargo install always re-runs build.rs so we might be good here.

@tankyleo tankyleo Jun 8, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also trying to understand how this triggers. After build.rs sets GIT_HASH, what other thing could cause GIT_HASH to change, and trigger build.rs again ?


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}");
}
}
3 changes: 2 additions & 1 deletion ldk-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf> {
#[cfg(target_os = "macos")]
Expand Down Expand Up @@ -241,7 +242,7 @@ fn main() {
let (event_sender, _) = broadcast::channel::<EventEnvelope>(1024);
let (shutdown_tx, shutdown_rx) = tokio::sync::watch::channel(false);

info!("Starting up...");
info!("Starting ldk-server version {FULL_VERSION}");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also do this when we rotate the logs ?

match node.start() {
Ok(()) => {},
Err(e) => {
Expand Down
2 changes: 1 addition & 1 deletion ldk-server/src/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand Down