taler-rust

GNU Taler code in Rust. Largely core banking integrations.
Log | Files | Refs | Submodules | README | LICENSE

commit c54f6749015195116f85782cf9fb5936302a87a6
parent be74a7b8a7931e6944491ec145866adf28fe0b61
Author: Antoine A <>
Date:   Tue, 25 Nov 2025 10:03:56 +0100

common: fix git hash in version

Diffstat:
MCargo.toml | 2++
MMakefile | 2--
Acommon/taler-build/Cargo.toml | 9+++++++++
Acommon/taler-build/build.rs | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Acommon/taler-build/src/lib.rs | 27+++++++++++++++++++++++++++
Mcommon/taler-common/src/cli.rs | 12------------
Mtaler-magnet-bank/Cargo.toml | 1+
Mtaler-magnet-bank/src/bin/magnet-bank-harness.rs | 2+-
Mtaler-magnet-bank/src/main.rs | 3++-
9 files changed, 92 insertions(+), 16 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml @@ -3,6 +3,7 @@ resolver = "3" members = [ "common/taler-api", "common/taler-common", + "common/taler-build", "common/taler-test-utils", "taler-magnet-bank", ] @@ -45,6 +46,7 @@ tempfile = "3.15" taler-common = { path = "common/taler-common" } taler-api = { path = "common/taler-api" } taler-test-utils = { path = "common/taler-test-utils" } +taler-build = { path = "common/taler-build" } anyhow = "1" http-body-util = "0.1.2" libdeflater = "1.22.0" diff --git a/Makefile b/Makefile @@ -1,8 +1,6 @@ # This Makefile has been placed under the public domain -include build-system/config.mk -export GIT_HASH=$(shell git rev-parse --short HEAD) - # Absolute DESTDIR or empty string if DESTDIR unset/empty abs_destdir=$(abspath $(DESTDIR)) diff --git a/common/taler-build/Cargo.toml b/common/taler-build/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "taler-build" +version.workspace = true +edition.workspace = true +authors.workspace = true +homepage.workspace = true +repository.workspace = true +license-file.workspace = true +\ No newline at end of file diff --git a/common/taler-build/build.rs b/common/taler-build/build.rs @@ -0,0 +1,50 @@ +/* + This file is part of TALER + Copyright (C) 2025 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +*/ + +use std::process::Command; + +fn run_command(command: &str, args: &[&str]) -> Result<String, String> { + let output = Command::new(command) + .args(args) + .output() + .map_err(|e| format!("Failed to execute {}: {}", command, e))?; + + if output.status.success() { + Ok(String::from_utf8_lossy(&output.stdout).trim().to_string()) + } else { + Err(format!( + "Command failed: {} {:?}\nStderr: {}", + command, + args, + String::from_utf8_lossy(&output.stderr) + )) + } +} + +fn main() -> Result<(), String> { + // Tell Cargo to re-run the build script if the commit hash changes + // This covers both detached HEAD state and changes to local branch references + println!("cargo:rerun-if-changed=.git/HEAD"); + println!("cargo:rerun-if-changed=.git/refs/"); + + // Get the short commit hash + let commit_hash = run_command("git", &["rev-parse", "--short", "HEAD"])?; + + // Set the environment variable VERSION + println!("cargo:rustc-env=GIT_HASH={}", commit_hash); + + Ok(()) +} diff --git a/common/taler-build/src/lib.rs b/common/taler-build/src/lib.rs @@ -0,0 +1,27 @@ +/* + This file is part of TALER + Copyright (C) 2025 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +*/ + +/// Taler component version format +pub fn long_version() -> &'static str { + let version = env!("CARGO_PKG_VERSION"); + let git_hash = option_env!("GIT_HASH"); + if let Some(hash) = git_hash { + format!("v{version}-git-{hash}") + } else { + format!("v{version}") + } + .leak() +} diff --git a/common/taler-common/src/cli.rs b/common/taler-common/src/cli.rs @@ -18,18 +18,6 @@ use std::io::Write as _; use crate::config::Config; -/// Taler component version format, you should set GIT_HASH in your building script -pub fn long_version() -> &'static str { - let version = env!("CARGO_PKG_VERSION"); - let git_hash = option_env!("GIT_HASH"); - if let Some(hash) = git_hash { - format!("v{version}-git-{hash}") - } else { - format!("v{version}-git") - } - .leak() -} - /// Inspect the configuration #[derive(clap::Subcommand, Debug)] pub enum ConfigCmd { diff --git a/taler-magnet-bank/Cargo.toml b/taler-magnet-bank/Cargo.toml @@ -24,6 +24,7 @@ serde_json = { workspace = true, features = ["raw_value"] } jiff = { workspace = true, features = ["serde"] } taler-common.workspace = true taler-api.workspace = true +taler-build.workspace = true clap.workspace = true serde.workspace = true serde_with.workspace = true diff --git a/taler-magnet-bank/src/bin/magnet-bank-harness.rs b/taler-magnet-bank/src/bin/magnet-bank-harness.rs @@ -21,12 +21,12 @@ use jiff::{Timestamp, Zoned}; use owo_colors::OwoColorize; use p256::ecdsa::SigningKey; use sqlx::PgPool; +use taler_build::long_version; use taler_common::{ CommonArgs, api_common::{EddsaPublicKey, HashCode, ShortHashCode, rand_edsa_pub_key}, api_params::{History, Page}, api_wire::{IncomingBankTransaction, TransferRequest, TransferState}, - cli::long_version, config::Config, db::{dbinit, pool}, taler_main, diff --git a/taler-magnet-bank/src/main.rs b/taler-magnet-bank/src/main.rs @@ -17,9 +17,10 @@ use anyhow::bail; use clap::Parser; use taler_api::config::{ApiCfg, AuthCfg}; +use taler_build::long_version; use taler_common::{ CommonArgs, - cli::{ConfigCmd, long_version}, + cli::ConfigCmd, config::Config, db::{dbinit, pool}, taler_main,