View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0012366 | Taler | taler-rust | public | 2026-12-06 03:52 | 2026-12-06 03:52 |
| Reporter | bot-cg [agent] | ||||
| Priority | normal | Severity | feature | Reproducibility | N/A |
| Status | new | ||||
| Summary | 0012366: taler-common: make sqlx, tokio and aws-lc-rs optional, for programs that only read the configuration (patch attached) | ||||
| Description | Every program that uses `taler-common` links all of it: sqlx with its Postgres driver, a multi-threaded tokio runtime, and aws-lc-rs, whose build compiles AWS-LC from C with cmake. That is so even for a program that only reads a Taler configuration file and logs with `taler_logger`. Beekeeper has two such programs: a lookup helper and a converter service. They use `taler_common::config` and `taler_common::log`, nothing else, yet carry a database driver, a TLS stack and a C crypto library they never call. Found in the same audit of Beekeeper's dependencies as 0012365. **Suggestion.** Make the three heavy parts optional Cargo features of `taler-common`, all on by default, so that no current user changes: * `db` (sqlx): the pool and migrations of `db`, the sqlx encoding of `Amount`, `Decimal`, `Base32`, `TalerTimestamp`, `EddsaPublicKey`, `TransferState` and `IncomingType`, `Section::postgres`, and `bench`; * `runtime` (tokio): `taler_main` and the task ids that `taler_logger` prints; * `crypto` (aws-lc-rs): the `api` and `signature` modules and `Amount::signature_bytes`. A program that wants only the configuration and the logger then uses `taler-common = { ..., default-features = false }`. A separate crate for the configuration parser would be the other way to split. But the typed getters (`amount`, `payto`) need the types, and the orphan rule keeps the sqlx impls of those types in their own crate. So a separate crate would end up needing these features too. One change outside taler-common is needed. The workspace's `compact_str` dependency turned on its `sqlx-postgres` feature, which pulls sqlx back in. The patch moves that feature to the members that use it: taler-common's `db`, taler-api, the three adapters, and the APNs relay. **Effect** (`cargo tree --target x86_64-unknown-linux-gnu -p taler-common`, distinct crates): | | linked (`-e normal,no-proc-macro`) | with proc macros (`-e normal`) | everything compiled (`-e normal,build`) | |---|---|---|---| | default features | 148 | 173 | 182 | | `--no-default-features` | 85 | 107 | 107 | Without the default features, the tree has no tokio, sqlx, rustls, aws-lc-sys, cc or cmake. **Tested** on master 4bfeb4d: * `cargo check -p taler-common` with `RUSTFLAGS=-D warnings` in seven feature combinations: default, none, each feature alone, `db,crypto` and `runtime,crypto`. All are clean. * `cargo check -p <member> --all-targets` for each of the 11 workspace members on its own, so that feature unification cannot hide a missing feature. * `cargo test -p taler-common`: 22 passed with the default features, 21 without them. * `cargo test -p taler-api`: 21 passed. * `cargo clippy -p taler-common --all-targets`: the same warnings as before the patch. * `cargo fmt --check -p taler-common` is clean. I did not run `rustfmt-unstable`; the patch changes no imports apart from adding `cfg` attributes. One caveat for users: Cargo unifies features across a single build. A program that turns the features off must be built in a cargo invocation of its own, not together with programs that keep them on. The patch (also attached): ``` From 9760483cc2608ae5f554789464391e95443904a4 Mon Sep 17 00:00:00 2001 From: Christian Grothoff <christian@grothoff.org> Date: Sun, 6 Dec 2026 04:51:18 +0100 Subject: [PATCH] common: make taler-common's database, runtime and crypto parts optional features A program that only reads Taler configuration files and logs (a helper, a converter) then links 85 crates instead of 148 and compiles no C; the default features keep every current user unchanged. Assisted by LLM --- Cargo.toml | 4 +++- adapters/taler-cyclos/Cargo.toml | 2 +- adapters/taler-magnet-bank/Cargo.toml | 2 +- adapters/taler-wise/Cargo.toml | 2 +- common/taler-api/Cargo.toml | 2 +- common/taler-common/Cargo.toml | 17 ++++++++++++++--- common/taler-common/src/api.rs | 3 +++ common/taler-common/src/api/wire.rs | 5 +++-- common/taler-common/src/config.rs | 1 + common/taler-common/src/db.rs | 13 +++++++++++-- common/taler-common/src/lib.rs | 8 ++++++++ common/taler-common/src/log.rs | 3 +++ common/taler-common/src/types/amount.rs | 8 ++++++++ common/taler-common/src/types/base32.rs | 3 +++ common/taler-common/src/types/time.rs | 3 +++ taler-apns-relay/Cargo.toml | 2 +- 16 files changed, 65 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dde1cfe..aba7996 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,7 +57,9 @@ anyhow = "1" http-body-util = "0.1.2" owo-colors = "4.2.3" aws-lc-rs = { version = "1.15", default-features = false, features = ["alloc", "aws-lc-sys"] } -compact_str = { version = "0.10", features = ["serde", "sqlx-postgres"] } +# The members that bind it in queries add "sqlx-postgres" (taler-common with +# its feature "db"). +compact_str = { version = "0.10", features = ["serde"] } hyper-util = "0.1" hyper-rustls = { version = "0.27", features = [ "aws-lc-rs", diff --git a/adapters/taler-cyclos/Cargo.toml b/adapters/taler-cyclos/Cargo.toml index 559e985..5546d8a 100644 --- a/adapters/taler-cyclos/Cargo.toml +++ b/adapters/taler-cyclos/Cargo.toml @@ -29,7 +29,7 @@ serde_path_to_error.workspace = true thiserror.workspace = true tracing.workspace = true tokio.workspace = true -compact_str.workspace = true +compact_str = { workspace = true, features = ["sqlx-postgres"] } anyhow.workspace = true owo-colors.workspace = true failure-injection.workspace = true diff --git a/adapters/taler-magnet-bank/Cargo.toml b/adapters/taler-magnet-bank/Cargo.toml index 5ba6234..85e9ef3 100644 --- a/adapters/taler-magnet-bank/Cargo.toml +++ b/adapters/taler-magnet-bank/Cargo.toml @@ -39,7 +39,7 @@ failure-injection.workspace = true http.workspace = true url.workspace = true aws-lc-rs.workspace = true -compact_str.workspace = true +compact_str = { workspace = true, features = ["sqlx-postgres"] } prometheus-client.workspace = true [dev-dependencies] diff --git a/adapters/taler-wise/Cargo.toml b/adapters/taler-wise/Cargo.toml index f22bb87..6711413 100644 --- a/adapters/taler-wise/Cargo.toml +++ b/adapters/taler-wise/Cargo.toml @@ -14,7 +14,7 @@ doctest = false [dependencies] pem = "4" clap.workspace = true -compact_str.workspace = true +compact_str = { workspace = true, features = ["sqlx-postgres"] } jiff.workspace = true sqlx.workspace = true taler-api.workspace = true diff --git a/common/taler-api/Cargo.toml b/common/taler-api/Cargo.toml index 21b411b..a5bde16 100644 --- a/common/taler-api/Cargo.toml +++ b/common/taler-api/Cargo.toml @@ -39,7 +39,7 @@ taler-common.workspace = true sqlx.workspace = true jiff.workspace = true aws-lc-rs.workspace = true -compact_str.workspace = true +compact_str = { workspace = true, features = ["sqlx-postgres"] } regex.workspace = true prometheus-client.workspace = true diff --git a/common/taler-common/Cargo.toml b/common/taler-common/Cargo.toml index f64ac11..04c5faf 100644 --- a/common/taler-common/Cargo.toml +++ b/common/taler-common/Cargo.toml @@ -30,13 +30,24 @@ tracing.workspace = true clap.workspace = true anyhow.workspace = true tracing-subscriber.workspace = true -tokio = { workspace = true, features = ["rt-multi-thread"] } -sqlx = { workspace = true, features = ["derive"] } +tokio = { workspace = true, features = ["rt-multi-thread"], optional = true } +sqlx = { workspace = true, features = ["derive"], optional = true } compact_str.workspace = true -aws-lc-rs.workspace = true +aws-lc-rs = { workspace = true, optional = true } regex.workspace = true taler-macros.workspace = true +[features] +default = ["db", "runtime", "crypto"] +# The PostgreSQL side: the `db` module's pool and migrations, the sqlx +# encoding of the types, and `Section::postgres`. +db = ["dep:sqlx", "compact_str/sqlx-postgres"] +# `taler_main` and the task ids of the log, on a tokio runtime. +runtime = ["dep:tokio"] +# Ed25519 and SHA-512 with aws-lc-rs: the `api` and `signature` modules and +# `Amount::signature_bytes`. +crypto = ["dep:aws-lc-rs"] + [dev-dependencies] criterion.workspace = true diff --git a/common/taler-common/src/api.rs b/common/taler-common/src/api.rs index 74dea70..9ac3507 100644 --- a/common/taler-common/src/api.rs +++ b/common/taler-common/src/api.rs @@ -230,12 +230,14 @@ impl EddsaPublicKey { } } +#[cfg(feature = "db")] impl sqlx::Type<sqlx::Postgres> for EddsaPublicKey { fn type_info() -> sqlx::postgres::PgTypeInfo { <Base32<32>>::type_info() } } +#[cfg(feature = "db")] impl<'q> sqlx::Encode<'q, sqlx::Postgres> for EddsaPublicKey { fn encode_by_ref( &self, @@ -245,6 +247,7 @@ impl<'q> sqlx::Encode<'q, sqlx::Postgres> for EddsaPublicKey { } } +#[cfg(feature = "db")] impl<'r> sqlx::Decode<'r, sqlx::Postgres> for EddsaPublicKey { fn decode(value: sqlx::postgres::PgValueRef<'r>) -> Result<Self, sqlx::error::BoxDynError> { let raw = <Base32<32>>::decode(value)?; diff --git a/common/taler-common/src/api/wire.rs b/common/taler-common/src/api/wire.rs index ee541c6..0b8f39c 100644 --- a/common/taler-common/src/api/wire.rs +++ b/common/taler-common/src/api/wire.rs @@ -186,9 +186,10 @@ pub struct AddMappedRequest { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct AccountInfo {} -#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, sqlx::Type)] +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "db", derive(sqlx::Type))] #[allow(non_camel_case_types)] -#[sqlx(type_name = "transfer_status")] +#[cfg_attr(feature = "db", sqlx(type_name = "transfer_status"))] pub enum TransferState { pending, transient_failure, diff --git a/common/taler-common/src/config.rs b/common/taler-common/src/config.rs index 1e73f6d..27be893 100644 --- a/common/taler-common/src/config.rs +++ b/common/taler-common/src/config.rs @@ -994,6 +994,7 @@ impl<'cfg, 'arg> Section<'cfg, 'arg> { } /** Access [option] as Postgres URI */ + #[cfg(feature = "db")] pub fn postgres(&self, option: &'arg str) -> Value<'arg, sqlx::postgres::PgConnectOptions> { self.parse("Postgres URI", option) } diff --git a/common/taler-common/src/db.rs b/common/taler-common/src/db.rs index e57a674..02ab9c9 100644 --- a/common/taler-common/src/db.rs +++ b/common/taler-common/src/db.rs @@ -14,22 +14,26 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ +#[cfg(feature = "db")] use std::{ io::ErrorKind, path::{Path, PathBuf}, sync::Arc, }; +#[cfg(feature = "db")] use sqlx::{ AssertSqlSafe, Connection, PgConnection, PgPool, Postgres, Row, Transaction, postgres::{PgConnectOptions, PgPoolOptions, PgRow}, }; use taler_macros::EnumMeta; +#[cfg(feature = "db")] use tracing::{debug, info}; -#[derive(Debug, Clone, Copy, PartialEq, Eq, sqlx::Type, EnumMeta)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, EnumMeta)] +#[cfg_attr(feature = "db", derive(sqlx::Type))] #[allow(non_camel_case_types)] -#[sqlx(type_name = "incoming_type")] +#[cfg_attr(feature = "db", sqlx(type_name = "incoming_type"))] #[enum_meta(Str)] pub enum IncomingType { reserve, @@ -39,10 +43,12 @@ pub enum IncomingType { /* ----- Pool ----- */ +#[cfg(feature = "db")] pub async fn pool(cfg: PgConnectOptions, schema: &str) -> sqlx::Result<PgPool> { pool_with_options(cfg, schema, PgPoolOptions::new()).await } +#[cfg(feature = "db")] pub async fn pool_with_options( cfg: PgConnectOptions, schema: &str, @@ -70,6 +76,7 @@ pub async fn pool_with_options( /* ----- Migration----- */ +#[cfg(feature = "db")] #[derive(Debug, thiserror::Error)] pub enum MigrationErr { #[error("could not read patch at '{}': {}", .0.to_string_lossy(), .1.kind())] @@ -78,6 +85,7 @@ pub enum MigrationErr { Sql(#[from] sqlx::Error), } +#[cfg(feature = "db")] pub async fn dbinit( conn: &mut PgConnection, sql_dir: &Path, @@ -87,6 +95,7 @@ pub async fn dbinit( dbinit_setup(conn, sql_dir, prefix, reset, async |_| Ok(())).await } +#[cfg(feature = "db")] pub async fn dbinit_setup( conn: &mut PgConnection, sql_dir: &Path, diff --git a/common/taler-common/src/lib.rs b/common/taler-common/src/lib.rs index 5481072..1adf04b 100644 --- a/common/taler-common/src/lib.rs +++ b/common/taler-common/src/lib.rs @@ -16,13 +16,19 @@ use std::{path::PathBuf, time::Duration}; +#[cfg(feature = "runtime")] use config::{Config, parser::ConfigSource}; +#[cfg(feature = "runtime")] use tracing::error; +#[cfg(feature = "runtime")] use tracing_subscriber::util::SubscriberInitExt; +#[cfg(feature = "runtime")] use crate::log::taler_logger; +#[cfg(feature = "crypto")] pub mod api; +#[cfg(feature = "db")] pub mod bench; pub mod cli; pub mod config; @@ -32,6 +38,7 @@ pub mod error; pub mod error_code; pub mod json_file; pub mod log; +#[cfg(feature = "crypto")] pub mod signature; pub mod types; @@ -55,6 +62,7 @@ pub struct CommonArgs { #[error("{0}")] pub struct PermanentErr(String); +#[cfg(feature = "runtime")] pub fn taler_main( src: ConfigSource, args: CommonArgs, diff --git a/common/taler-common/src/log.rs b/common/taler-common/src/log.rs index 2f8ac06..4f0dd4b 100644 --- a/common/taler-common/src/log.rs +++ b/common/taler-common/src/log.rs @@ -16,6 +16,7 @@ use std::io::IsTerminal; +#[cfg(feature = "runtime")] use compact_str::CompactString; use jiff::{Timestamp, fmt::StdFmtWrite, tz::TimeZone}; use tracing::{Event, Level, Subscriber}; @@ -26,6 +27,7 @@ use tracing_subscriber::{ util::SubscriberInitExt, }; +#[cfg(feature = "runtime")] tokio::task_local! { pub static LOG_TASK_ID: CompactString; } @@ -101,6 +103,7 @@ where if ansi { write!(&mut w, "\x1b[2;37m")?; // Dim fg } + #[cfg(feature = "runtime")] LOG_TASK_ID .try_with(|id| write!(w, "({id})")) .ok() diff --git a/common/taler-common/src/types/amount.rs b/common/taler-common/src/types/amount.rs index 7c95086..27b06a7 100644 --- a/common/taler-common/src/types/amount.rs +++ b/common/taler-common/src/types/amount.rs @@ -25,6 +25,7 @@ use std::{ use compact_str::format_compact; use super::utils::InlineStr; +#[cfg(feature = "crypto")] use crate::signature::Buf; /** Number of characters we use to represent currency names */ @@ -135,6 +136,7 @@ impl Display for Currency { } } +#[cfg(feature = "db")] #[derive(sqlx::Type)] #[sqlx(type_name = "taler_amount")] struct PgTalerAmount { @@ -282,12 +284,14 @@ impl Debug for Decimal { } } +#[cfg(feature = "db")] impl sqlx::Type<sqlx::Postgres> for Decimal { fn type_info() -> sqlx::postgres::PgTypeInfo { PgTalerAmount::type_info() } } +#[cfg(feature = "db")] impl<'q> sqlx::Encode<'q, sqlx::Postgres> for Decimal { fn encode_by_ref( &self, @@ -301,6 +305,7 @@ impl<'q> sqlx::Encode<'q, sqlx::Postgres> for Decimal { } } +#[cfg(feature = "db")] impl<'r> sqlx::Decode<'r, sqlx::Postgres> for Decimal { fn decode(value: sqlx::postgres::PgValueRef<'r>) -> Result<Self, sqlx::error::BoxDynError> { let pg = PgTalerAmount::decode(value)?; @@ -385,6 +390,7 @@ impl Amount { } /** Encode amount for signature */ + #[cfg(feature = "crypto")] pub fn signature_bytes(self) -> [u8; 24] { Buf::new() .put_u64(self.val) @@ -452,12 +458,14 @@ impl Debug for Amount { } } +#[cfg(feature = "db")] impl sqlx::Type<sqlx::Postgres> for Amount { fn type_info() -> sqlx::postgres::PgTypeInfo { PgTalerAmount::type_info() } } +#[cfg(feature = "db")] impl<'q> sqlx::Encode<'q, sqlx::Postgres> for Amount { fn encode_by_ref( &self, diff --git a/common/taler-common/src/types/base32.rs b/common/taler-common/src/types/base32.rs index 3311a9b..de77e11 100644 --- a/common/taler-common/src/types/base32.rs +++ b/common/taler-common/src/types/base32.rs @@ -104,12 +104,14 @@ impl<'a, const L: usize> TryFrom<&'a [u8]> for Base32<L> { } } +#[cfg(feature = "db")] impl<const L: usize> sqlx::Type<sqlx::Postgres> for Base32<L> { fn type_info() -> sqlx::postgres::PgTypeInfo { <&[u8]>::type_info() } } +#[cfg(feature = "db")] impl<'q, const L: usize> sqlx::Encode<'q, sqlx::Postgres> for Base32<L> { fn encode_by_ref( &self, @@ -119,6 +121,7 @@ impl<'q, const L: usize> sqlx::Encode<'q, sqlx::Postgres> for Base32<L> { } } +#[cfg(feature = "db")] impl<'r, const L: usize> sqlx::Decode<'r, sqlx::Postgres> for Base32<L> { fn decode(value: sqlx::postgres::PgValueRef<'r>) -> Result<Self, sqlx::error::BoxDynError> { let array = <[u8; L]>::decode(value)?; diff --git a/common/taler-common/src/types/time.rs b/common/taler-common/src/types/time.rs index 5d98c04..66676ea 100644 --- a/common/taler-common/src/types/time.rs +++ b/common/taler-common/src/types/time.rs @@ -140,12 +140,14 @@ impl Add<jiff::Span> for TalerTimestamp { } } +#[cfg(feature = "db")] impl sqlx::Type<sqlx::Postgres> for TalerTimestamp { fn type_info() -> <sqlx::Postgres as sqlx::Database>::TypeInfo { Option::<i64>::type_info() } } +#[cfg(feature = "db")] impl<'q> sqlx::Encode<'q, sqlx::Postgres> for TalerTimestamp { fn encode_by_ref( &self, @@ -159,6 +161,7 @@ impl<'q> sqlx::Encode<'q, sqlx::Postgres> for TalerTimestamp { } } +#[cfg(feature = "db")] impl<'r> sqlx::Decode<'r, sqlx::Postgres> for TalerTimestamp { fn decode( value: <sqlx::Postgres as sqlx::Database>::ValueRef<'r>, diff --git a/taler-apns-relay/Cargo.toml b/taler-apns-relay/Cargo.toml index a83fbbb..568bba9 100644 --- a/taler-apns-relay/Cargo.toml +++ b/taler-apns-relay/Cargo.toml @@ -31,7 +31,7 @@ rustls.workspace = true jiff.workspace = true tokio.workspace = true aws-lc-rs.workspace = true -compact_str.workspace = true +compact_str = { workspace = true, features = ["sqlx-postgres"] } tracing.workspace = true thiserror.workspace = true -- 2.47.3 ``` | ||||
| Tags | No tags attached. | ||||
| Attached Files | 0001-common-make-taler-common-s-database-runtime-and-cryp.patch (15,078 bytes)
From 9760483cc2608ae5f554789464391e95443904a4 Mon Sep 17 00:00:00 2001
From: Christian Grothoff <christian@grothoff.org>
Date: Sun, 6 Dec 2026 04:51:18 +0100
Subject: [PATCH] common: make taler-common's database, runtime and crypto
parts optional features
A program that only reads Taler configuration files and logs (a helper, a converter) then links 85 crates instead of 148 and compiles no C; the default features keep every current user unchanged.
Assisted by LLM
---
Cargo.toml | 4 +++-
adapters/taler-cyclos/Cargo.toml | 2 +-
adapters/taler-magnet-bank/Cargo.toml | 2 +-
adapters/taler-wise/Cargo.toml | 2 +-
common/taler-api/Cargo.toml | 2 +-
common/taler-common/Cargo.toml | 17 ++++++++++++++---
common/taler-common/src/api.rs | 3 +++
common/taler-common/src/api/wire.rs | 5 +++--
common/taler-common/src/config.rs | 1 +
common/taler-common/src/db.rs | 13 +++++++++++--
common/taler-common/src/lib.rs | 8 ++++++++
common/taler-common/src/log.rs | 3 +++
common/taler-common/src/types/amount.rs | 8 ++++++++
common/taler-common/src/types/base32.rs | 3 +++
common/taler-common/src/types/time.rs | 3 +++
taler-apns-relay/Cargo.toml | 2 +-
16 files changed, 65 insertions(+), 13 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index dde1cfe..aba7996 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -57,7 +57,9 @@ anyhow = "1"
http-body-util = "0.1.2"
owo-colors = "4.2.3"
aws-lc-rs = { version = "1.15", default-features = false, features = ["alloc", "aws-lc-sys"] }
-compact_str = { version = "0.10", features = ["serde", "sqlx-postgres"] }
+# The members that bind it in queries add "sqlx-postgres" (taler-common with
+# its feature "db").
+compact_str = { version = "0.10", features = ["serde"] }
hyper-util = "0.1"
hyper-rustls = { version = "0.27", features = [
"aws-lc-rs",
diff --git a/adapters/taler-cyclos/Cargo.toml b/adapters/taler-cyclos/Cargo.toml
index 559e985..5546d8a 100644
--- a/adapters/taler-cyclos/Cargo.toml
+++ b/adapters/taler-cyclos/Cargo.toml
@@ -29,7 +29,7 @@ serde_path_to_error.workspace = true
thiserror.workspace = true
tracing.workspace = true
tokio.workspace = true
-compact_str.workspace = true
+compact_str = { workspace = true, features = ["sqlx-postgres"] }
anyhow.workspace = true
owo-colors.workspace = true
failure-injection.workspace = true
diff --git a/adapters/taler-magnet-bank/Cargo.toml b/adapters/taler-magnet-bank/Cargo.toml
index 5ba6234..85e9ef3 100644
--- a/adapters/taler-magnet-bank/Cargo.toml
+++ b/adapters/taler-magnet-bank/Cargo.toml
@@ -39,7 +39,7 @@ failure-injection.workspace = true
http.workspace = true
url.workspace = true
aws-lc-rs.workspace = true
-compact_str.workspace = true
+compact_str = { workspace = true, features = ["sqlx-postgres"] }
prometheus-client.workspace = true
[dev-dependencies]
diff --git a/adapters/taler-wise/Cargo.toml b/adapters/taler-wise/Cargo.toml
index f22bb87..6711413 100644
--- a/adapters/taler-wise/Cargo.toml
+++ b/adapters/taler-wise/Cargo.toml
@@ -14,7 +14,7 @@ doctest = false
[dependencies]
pem = "4"
clap.workspace = true
-compact_str.workspace = true
+compact_str = { workspace = true, features = ["sqlx-postgres"] }
jiff.workspace = true
sqlx.workspace = true
taler-api.workspace = true
diff --git a/common/taler-api/Cargo.toml b/common/taler-api/Cargo.toml
index 21b411b..a5bde16 100644
--- a/common/taler-api/Cargo.toml
+++ b/common/taler-api/Cargo.toml
@@ -39,7 +39,7 @@ taler-common.workspace = true
sqlx.workspace = true
jiff.workspace = true
aws-lc-rs.workspace = true
-compact_str.workspace = true
+compact_str = { workspace = true, features = ["sqlx-postgres"] }
regex.workspace = true
prometheus-client.workspace = true
diff --git a/common/taler-common/Cargo.toml b/common/taler-common/Cargo.toml
index f64ac11..04c5faf 100644
--- a/common/taler-common/Cargo.toml
+++ b/common/taler-common/Cargo.toml
@@ -30,13 +30,24 @@ tracing.workspace = true
clap.workspace = true
anyhow.workspace = true
tracing-subscriber.workspace = true
-tokio = { workspace = true, features = ["rt-multi-thread"] }
-sqlx = { workspace = true, features = ["derive"] }
+tokio = { workspace = true, features = ["rt-multi-thread"], optional = true }
+sqlx = { workspace = true, features = ["derive"], optional = true }
compact_str.workspace = true
-aws-lc-rs.workspace = true
+aws-lc-rs = { workspace = true, optional = true }
regex.workspace = true
taler-macros.workspace = true
+[features]
+default = ["db", "runtime", "crypto"]
+# The PostgreSQL side: the `db` module's pool and migrations, the sqlx
+# encoding of the types, and `Section::postgres`.
+db = ["dep:sqlx", "compact_str/sqlx-postgres"]
+# `taler_main` and the task ids of the log, on a tokio runtime.
+runtime = ["dep:tokio"]
+# Ed25519 and SHA-512 with aws-lc-rs: the `api` and `signature` modules and
+# `Amount::signature_bytes`.
+crypto = ["dep:aws-lc-rs"]
+
[dev-dependencies]
criterion.workspace = true
diff --git a/common/taler-common/src/api.rs b/common/taler-common/src/api.rs
index 74dea70..9ac3507 100644
--- a/common/taler-common/src/api.rs
+++ b/common/taler-common/src/api.rs
@@ -230,12 +230,14 @@ impl EddsaPublicKey {
}
}
+#[cfg(feature = "db")]
impl sqlx::Type<sqlx::Postgres> for EddsaPublicKey {
fn type_info() -> sqlx::postgres::PgTypeInfo {
<Base32<32>>::type_info()
}
}
+#[cfg(feature = "db")]
impl<'q> sqlx::Encode<'q, sqlx::Postgres> for EddsaPublicKey {
fn encode_by_ref(
&self,
@@ -245,6 +247,7 @@ impl<'q> sqlx::Encode<'q, sqlx::Postgres> for EddsaPublicKey {
}
}
+#[cfg(feature = "db")]
impl<'r> sqlx::Decode<'r, sqlx::Postgres> for EddsaPublicKey {
fn decode(value: sqlx::postgres::PgValueRef<'r>) -> Result<Self, sqlx::error::BoxDynError> {
let raw = <Base32<32>>::decode(value)?;
diff --git a/common/taler-common/src/api/wire.rs b/common/taler-common/src/api/wire.rs
index ee541c6..0b8f39c 100644
--- a/common/taler-common/src/api/wire.rs
+++ b/common/taler-common/src/api/wire.rs
@@ -186,9 +186,10 @@ pub struct AddMappedRequest {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AccountInfo {}
-#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, sqlx::Type)]
+#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
+#[cfg_attr(feature = "db", derive(sqlx::Type))]
#[allow(non_camel_case_types)]
-#[sqlx(type_name = "transfer_status")]
+#[cfg_attr(feature = "db", sqlx(type_name = "transfer_status"))]
pub enum TransferState {
pending,
transient_failure,
diff --git a/common/taler-common/src/config.rs b/common/taler-common/src/config.rs
index 1e73f6d..27be893 100644
--- a/common/taler-common/src/config.rs
+++ b/common/taler-common/src/config.rs
@@ -994,6 +994,7 @@ impl<'cfg, 'arg> Section<'cfg, 'arg> {
}
/** Access [option] as Postgres URI */
+ #[cfg(feature = "db")]
pub fn postgres(&self, option: &'arg str) -> Value<'arg, sqlx::postgres::PgConnectOptions> {
self.parse("Postgres URI", option)
}
diff --git a/common/taler-common/src/db.rs b/common/taler-common/src/db.rs
index e57a674..02ab9c9 100644
--- a/common/taler-common/src/db.rs
+++ b/common/taler-common/src/db.rs
@@ -14,22 +14,26 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
+#[cfg(feature = "db")]
use std::{
io::ErrorKind,
path::{Path, PathBuf},
sync::Arc,
};
+#[cfg(feature = "db")]
use sqlx::{
AssertSqlSafe, Connection, PgConnection, PgPool, Postgres, Row, Transaction,
postgres::{PgConnectOptions, PgPoolOptions, PgRow},
};
use taler_macros::EnumMeta;
+#[cfg(feature = "db")]
use tracing::{debug, info};
-#[derive(Debug, Clone, Copy, PartialEq, Eq, sqlx::Type, EnumMeta)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, EnumMeta)]
+#[cfg_attr(feature = "db", derive(sqlx::Type))]
#[allow(non_camel_case_types)]
-#[sqlx(type_name = "incoming_type")]
+#[cfg_attr(feature = "db", sqlx(type_name = "incoming_type"))]
#[enum_meta(Str)]
pub enum IncomingType {
reserve,
@@ -39,10 +43,12 @@ pub enum IncomingType {
/* ----- Pool ----- */
+#[cfg(feature = "db")]
pub async fn pool(cfg: PgConnectOptions, schema: &str) -> sqlx::Result<PgPool> {
pool_with_options(cfg, schema, PgPoolOptions::new()).await
}
+#[cfg(feature = "db")]
pub async fn pool_with_options(
cfg: PgConnectOptions,
schema: &str,
@@ -70,6 +76,7 @@ pub async fn pool_with_options(
/* ----- Migration----- */
+#[cfg(feature = "db")]
#[derive(Debug, thiserror::Error)]
pub enum MigrationErr {
#[error("could not read patch at '{}': {}", .0.to_string_lossy(), .1.kind())]
@@ -78,6 +85,7 @@ pub enum MigrationErr {
Sql(#[from] sqlx::Error),
}
+#[cfg(feature = "db")]
pub async fn dbinit(
conn: &mut PgConnection,
sql_dir: &Path,
@@ -87,6 +95,7 @@ pub async fn dbinit(
dbinit_setup(conn, sql_dir, prefix, reset, async |_| Ok(())).await
}
+#[cfg(feature = "db")]
pub async fn dbinit_setup(
conn: &mut PgConnection,
sql_dir: &Path,
diff --git a/common/taler-common/src/lib.rs b/common/taler-common/src/lib.rs
index 5481072..1adf04b 100644
--- a/common/taler-common/src/lib.rs
+++ b/common/taler-common/src/lib.rs
@@ -16,13 +16,19 @@
use std::{path::PathBuf, time::Duration};
+#[cfg(feature = "runtime")]
use config::{Config, parser::ConfigSource};
+#[cfg(feature = "runtime")]
use tracing::error;
+#[cfg(feature = "runtime")]
use tracing_subscriber::util::SubscriberInitExt;
+#[cfg(feature = "runtime")]
use crate::log::taler_logger;
+#[cfg(feature = "crypto")]
pub mod api;
+#[cfg(feature = "db")]
pub mod bench;
pub mod cli;
pub mod config;
@@ -32,6 +38,7 @@ pub mod error;
pub mod error_code;
pub mod json_file;
pub mod log;
+#[cfg(feature = "crypto")]
pub mod signature;
pub mod types;
@@ -55,6 +62,7 @@ pub struct CommonArgs {
#[error("{0}")]
pub struct PermanentErr(String);
+#[cfg(feature = "runtime")]
pub fn taler_main(
src: ConfigSource,
args: CommonArgs,
diff --git a/common/taler-common/src/log.rs b/common/taler-common/src/log.rs
index 2f8ac06..4f0dd4b 100644
--- a/common/taler-common/src/log.rs
+++ b/common/taler-common/src/log.rs
@@ -16,6 +16,7 @@
use std::io::IsTerminal;
+#[cfg(feature = "runtime")]
use compact_str::CompactString;
use jiff::{Timestamp, fmt::StdFmtWrite, tz::TimeZone};
use tracing::{Event, Level, Subscriber};
@@ -26,6 +27,7 @@ use tracing_subscriber::{
util::SubscriberInitExt,
};
+#[cfg(feature = "runtime")]
tokio::task_local! {
pub static LOG_TASK_ID: CompactString;
}
@@ -101,6 +103,7 @@ where
if ansi {
write!(&mut w, "\x1b[2;37m")?; // Dim fg
}
+ #[cfg(feature = "runtime")]
LOG_TASK_ID
.try_with(|id| write!(w, "({id})"))
.ok()
diff --git a/common/taler-common/src/types/amount.rs b/common/taler-common/src/types/amount.rs
index 7c95086..27b06a7 100644
--- a/common/taler-common/src/types/amount.rs
+++ b/common/taler-common/src/types/amount.rs
@@ -25,6 +25,7 @@ use std::{
use compact_str::format_compact;
use super::utils::InlineStr;
+#[cfg(feature = "crypto")]
use crate::signature::Buf;
/** Number of characters we use to represent currency names */
@@ -135,6 +136,7 @@ impl Display for Currency {
}
}
+#[cfg(feature = "db")]
#[derive(sqlx::Type)]
#[sqlx(type_name = "taler_amount")]
struct PgTalerAmount {
@@ -282,12 +284,14 @@ impl Debug for Decimal {
}
}
+#[cfg(feature = "db")]
impl sqlx::Type<sqlx::Postgres> for Decimal {
fn type_info() -> sqlx::postgres::PgTypeInfo {
PgTalerAmount::type_info()
}
}
+#[cfg(feature = "db")]
impl<'q> sqlx::Encode<'q, sqlx::Postgres> for Decimal {
fn encode_by_ref(
&self,
@@ -301,6 +305,7 @@ impl<'q> sqlx::Encode<'q, sqlx::Postgres> for Decimal {
}
}
+#[cfg(feature = "db")]
impl<'r> sqlx::Decode<'r, sqlx::Postgres> for Decimal {
fn decode(value: sqlx::postgres::PgValueRef<'r>) -> Result<Self, sqlx::error::BoxDynError> {
let pg = PgTalerAmount::decode(value)?;
@@ -385,6 +390,7 @@ impl Amount {
}
/** Encode amount for signature */
+ #[cfg(feature = "crypto")]
pub fn signature_bytes(self) -> [u8; 24] {
Buf::new()
.put_u64(self.val)
@@ -452,12 +458,14 @@ impl Debug for Amount {
}
}
+#[cfg(feature = "db")]
impl sqlx::Type<sqlx::Postgres> for Amount {
fn type_info() -> sqlx::postgres::PgTypeInfo {
PgTalerAmount::type_info()
}
}
+#[cfg(feature = "db")]
impl<'q> sqlx::Encode<'q, sqlx::Postgres> for Amount {
fn encode_by_ref(
&self,
diff --git a/common/taler-common/src/types/base32.rs b/common/taler-common/src/types/base32.rs
index 3311a9b..de77e11 100644
--- a/common/taler-common/src/types/base32.rs
+++ b/common/taler-common/src/types/base32.rs
@@ -104,12 +104,14 @@ impl<'a, const L: usize> TryFrom<&'a [u8]> for Base32<L> {
}
}
+#[cfg(feature = "db")]
impl<const L: usize> sqlx::Type<sqlx::Postgres> for Base32<L> {
fn type_info() -> sqlx::postgres::PgTypeInfo {
<&[u8]>::type_info()
}
}
+#[cfg(feature = "db")]
impl<'q, const L: usize> sqlx::Encode<'q, sqlx::Postgres> for Base32<L> {
fn encode_by_ref(
&self,
@@ -119,6 +121,7 @@ impl<'q, const L: usize> sqlx::Encode<'q, sqlx::Postgres> for Base32<L> {
}
}
+#[cfg(feature = "db")]
impl<'r, const L: usize> sqlx::Decode<'r, sqlx::Postgres> for Base32<L> {
fn decode(value: sqlx::postgres::PgValueRef<'r>) -> Result<Self, sqlx::error::BoxDynError> {
let array = <[u8; L]>::decode(value)?;
diff --git a/common/taler-common/src/types/time.rs b/common/taler-common/src/types/time.rs
index 5d98c04..66676ea 100644
--- a/common/taler-common/src/types/time.rs
+++ b/common/taler-common/src/types/time.rs
@@ -140,12 +140,14 @@ impl Add<jiff::Span> for TalerTimestamp {
}
}
+#[cfg(feature = "db")]
impl sqlx::Type<sqlx::Postgres> for TalerTimestamp {
fn type_info() -> <sqlx::Postgres as sqlx::Database>::TypeInfo {
Option::<i64>::type_info()
}
}
+#[cfg(feature = "db")]
impl<'q> sqlx::Encode<'q, sqlx::Postgres> for TalerTimestamp {
fn encode_by_ref(
&self,
@@ -159,6 +161,7 @@ impl<'q> sqlx::Encode<'q, sqlx::Postgres> for TalerTimestamp {
}
}
+#[cfg(feature = "db")]
impl<'r> sqlx::Decode<'r, sqlx::Postgres> for TalerTimestamp {
fn decode(
value: <sqlx::Postgres as sqlx::Database>::ValueRef<'r>,
diff --git a/taler-apns-relay/Cargo.toml b/taler-apns-relay/Cargo.toml
index a83fbbb..568bba9 100644
--- a/taler-apns-relay/Cargo.toml
+++ b/taler-apns-relay/Cargo.toml
@@ -31,7 +31,7 @@ rustls.workspace = true
jiff.workspace = true
tokio.workspace = true
aws-lc-rs.workspace = true
-compact_str.workspace = true
+compact_str = { workspace = true, features = ["sqlx-postgres"] }
tracing.workspace = true
thiserror.workspace = true
--
2.47.3
| ||||
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2026-12-06 03:52 | bot-cg | New Issue | |
| 2026-12-06 03:52 | bot-cg | Implementer | => Antoine A |
| 2026-12-06 03:52 | bot-cg | Reviewer | => Florian Dold |
| 2026-12-06 03:52 | bot-cg | Release signed by | => Antoine A |
| 2026-12-06 03:52 | bot-cg | Deployed by | => Antoine A |
| 2026-12-06 03:52 | bot-cg | Verifier | => Antoine A |
| 2026-12-06 03:52 | bot-cg | Communicator | => CM_7 |
| 2026-12-06 03:52 | bot-cg | File Added: 0001-common-make-taler-common-s-database-runtime-and-cryp.patch |