From 74fbf3e1c719edbce69e34ad31484e4c2ad23c74 Mon Sep 17 00:00:00 2001 From: diogo464 Date: Sun, 9 Nov 2025 18:53:44 +0000 Subject: feat: added --version flag --- build.rs | 13 +++++++++++++ src/main.rs | 1 + 2 files changed, 14 insertions(+) create mode 100644 build.rs diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..671cc39 --- /dev/null +++ b/build.rs @@ -0,0 +1,13 @@ +use std::process::Command; +fn main() { + // Tell Cargo to rerun this build script if HEAD changes + println!("cargo:rerun-if-changed=.git/HEAD"); + println!("cargo:rerun-if-changed=.git/refs/tags"); + + let output = Command::new("git") + .args(&["describe", "--tags", "--dirty", "--always"]) + .output() + .unwrap(); + let git_version = String::from_utf8(output.stdout).unwrap(); + println!("cargo:rustc-env=GIT_VERSION={}", git_version.trim()); +} diff --git a/src/main.rs b/src/main.rs index 4c49fad..972f1bb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,6 +34,7 @@ pub mod signal; const CONTAINER_IMAGE_NAME: &str = "local/oar-p2p-networking"; #[derive(Debug, Parser)] +#[command(version = env!("GIT_VERSION"))] struct Cli { #[clap(subcommand)] cmd: SubCmd, -- cgit