taler-rust

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

commit 2947dcf84935c35bd2056eba4279fea29bd14849
parent f56f65eed7b2e7d83602ddafd78f707b9e137b68
Author: Florian Dold <dold@taler.net>
Date:   Fri,  4 Sep 2026 21:26:11 +0200

taler-rust: replace build-common with local configure

Diffstat:
M.gitmodules | 3---
MMakefile | 7+++----
Mbootstrap | 2+-
Mbuild-system/configure.py | 153++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
Dbuild-system/taler-build-scripts | 1-
5 files changed, 94 insertions(+), 72 deletions(-)

diff --git a/.gitmodules b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "build-system/taler-build-scripts"] - path = build-system/taler-build-scripts - url = ../build-common.git [submodule "doc/prebuilt"] path = doc/prebuilt url = ../taler-docs.git diff --git a/Makefile b/Makefile @@ -1,7 +1,7 @@ # This Makefile has been placed under the public domain --include build-system/config.mk +-include .config.mk -# Defaults for an unconfigured tree. config.mk is included above, so whatever +# Defaults for an unconfigured tree. .config.mk is included above, so whatever # ./configure resolved wins over these; a plain `make` without ./configure still # works and uses whichever cargo is on $PATH. No rustup required either way. cargo ?= cargo @@ -81,4 +81,4 @@ coverage-cyclos: $(cargo) llvm-cov clean --workspace $(cargo) llvm-cov test --no-clean $(cargo) llvm-cov run --bin cyclos-harness --no-clean -- -c dev.conf logic - $(cargo) llvm-cov report --lcov --output-path ./target/lcov.info -\ No newline at end of file + $(cargo) llvm-cov report --lcov --output-path ./target/lcov.info diff --git a/bootstrap b/bootstrap @@ -22,4 +22,4 @@ git config --local submodule.recurse true git submodule sync git submodule update --init rm -f ./configure -cp build-system/taler-build-scripts/configure ./configure +cp build-system/configure.py ./configure diff --git a/build-system/configure.py b/build-system/configure.py @@ -1,11 +1,17 @@ -# This configure.py.template file is in the public domain. +#!/usr/bin/env python3 +"""Configure the taler-rust installation prefix and Rust toolchain.""" + +from __future__ import annotations + +import argparse import os +from pathlib import Path import re import shutil import subprocess +import sys -from talerbuildconfig import * # Oldest Rust release that can build this tree. Keep the reason for the number # next to it -- the point of the check is to report an unusable toolchain here, @@ -19,72 +25,93 @@ from talerbuildconfig import * # Debian trixie ships 1.85, which is too old; trixie-backports and testing both # ship a new enough rustc. Keep this in step with `rust-version` in Cargo.toml. RUST_MIN_VERSION = "1.93" +BUILD_VARIABLE = re.compile(r"[A-Za-z_][A-Za-z0-9_]*=.*", re.DOTALL) -def _version_tuple(version): - parts = [int(p) for p in version.split(".")[:3]] +def version_tuple(version: str) -> tuple[int, int, int]: + parts = [int(part) for part in version.split(".")[:3]] return tuple(parts + [0] * (3 - len(parts))) -class RustTool(Tool): - """A Rust toolchain program (cargo, rustc) found on $PATH. +def tool_version(path: str) -> str | None: + try: + output = subprocess.run( + [path, "--version"], + check=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, + ).stdout + except (OSError, subprocess.SubprocessError): + return None + found = re.search(r"\d+(?:\.\d+)+", output) + return found.group(0) if found else None + + +def find_tool(name: str) -> tuple[str, str | None]: + requested = os.environ.get(name.upper()) or name + path = shutil.which(requested) + if path is None: + print(f"configure: error: tool '{name}' not available", file=sys.stderr) + print( + f"configure: hint: install '{name}' or point {name.upper()}= at it", + file=sys.stderr, + ) + raise SystemExit(1) + return path, tool_version(path) + + +def parse_args() -> argparse.Namespace: + parser = argparse.ArgumentParser( + usage="./configure [--prefix=DIR] [VARIABLE=VALUE]...", + description="Configure the installation prefix and Rust toolchain.", + ) + parser.add_argument("--prefix", default="/usr/local", help="installation prefix") + parser.add_argument("build_variables", nargs="*", metavar="VARIABLE=VALUE") + args = parser.parse_args() + if not args.prefix: + parser.error("installation prefix must not be empty") + for argument in args.build_variables: + if not BUILD_VARIABLE.fullmatch(argument): + parser.error(f"unrecognized argument: {argument}") + variable = argument.partition("=")[0] + print( + f"configure: WARNING: unsupported variable '{variable}' is ignored", + file=sys.stderr, + ) + return args + + +def main() -> int: + args = parse_args() + cargo_path, cargo_version = find_tool("cargo") + rustc_path, rustc_version = find_tool("rustc") + + for name, path, version in ( + ("cargo", cargo_path, cargo_version), + ("rustc", rustc_path, rustc_version), + ): + suffix = f" (version {version})" if version else "" + print(f"found {name} as {path}{suffix}") + + if rustc_version and version_tuple(rustc_version) < version_tuple(RUST_MIN_VERSION): + print( + f"configure: WARNING: rustc {rustc_version} is older than" + f" {RUST_MIN_VERSION}; this tree will not compile with it." + " On Debian stable: apt install -t trixie-backports rustc cargo", + file=sys.stderr, + ) - Unlike PosixTool this honours a CARGO=/RUSTC= environment override and - records the resolved path *and* version in config.mk. Nothing here wants - rustup: any cargo/rustc on $PATH will do, including the distribution's. - """ + config = ( + "# This makefile fragment is generated by configure.\n" + f"prefix = {args.prefix}\n" + f"cargo = {cargo_path}\n" + f"rustc = {rustc_path}\n" + ) + Path(".config.mk").write_text(config, encoding="utf-8") + print("writing .config.mk") + return 0 - def __init__(self, name, min_version=None): - self.name = name - self.min_version = min_version - self.hint = ( - f"install a Rust toolchain providing '{name}' -- the distribution's" - f" rustc/cargo packages are fine (on Debian stable they come from" - f" trixie-backports), as is rustup -- or point {name.upper()}= at one" - ) - def args(self, parser): - pass - - def check(self, buildconfig): - prog = os.environ.get(self.name.upper()) or self.name - path = shutil.which(prog) - if path is None: - return False - - version = self._version(path) - buildconfig._set_tool(self.name, path, version=version) - - if self.min_version is None or version is None: - return True - - if _version_tuple(version) < _version_tuple(self.min_version): - # A warning, not an error: configuring is still useful (the - # non-build targets work), and `rust-version` in Cargo.toml makes - # cargo itself refuse the build with a precise message. - buildconfig._warn( - f"{self.name} {version} is older than {self.min_version};" - f" this tree will not compile with it." - f" On Debian stable: apt install -t trixie-backports rustc cargo" - ) - return True - - @staticmethod - def _version(path): - try: - out = subprocess.run( - [path, "--version"], capture_output=True, text=True, check=True - ).stdout - except (OSError, subprocess.SubprocessError): - return None - # "cargo 1.95.0 (f2d3ce0bd 2026-03-21)", "rustc 1.95.0 (59807616e ...)" - found = re.search(r"\d+(?:\.\d+)+", out) - return found.group(0) if found else None - - -b = BuildConfig() -b.enable_prefix() -b.enable_configmk() -b.add_tool(RustTool("cargo")) -b.add_tool(RustTool("rustc", min_version=RUST_MIN_VERSION)) -b.run() +if __name__ == "__main__": + sys.exit(main()) diff --git a/build-system/taler-build-scripts b/build-system/taler-build-scripts @@ -1 +0,0 @@ -Subproject commit 884e13fe65b584f63d4cf92348fab1136af4bd69