Skip to content

Commit 025452e

Browse files
feat: make tracing dependency optional (default: enabled)
Supersedes #30. The `tracing` dependency of the `httpsig` crate is now gated behind a new `tracing` feature, enabled by default so that existing users keep their log output. Unlike #30, log call sites are left untouched: the `trace` facade module now provides no-op macros when the feature is disabled, so a missing cfg guard can never break a feature combination (#30 failed to compile with `--features rsa-signature` alone). The dependency is also declared with `default-features = false`, which drops `tracing-attributes` from the dependency graph since only the bang-style macros are used. Verified: cargo check/test across default, --no-default-features, rsa-signature with and without tracing, --all-features, and the whole workspace. Co-authored-by: keskalukasfri <270303466+keskalukasfri@users.noreply.github.com>
1 parent 002c430 commit 025452e

2 files changed

Lines changed: 45 additions & 4 deletions

File tree

httpsig/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ rust-version.workspace = true
1313
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1414

1515
[features]
16-
default = []
16+
default = ["tracing"]
1717
rsa-signature = ["rsa"]
18+
tracing = ["dep:tracing"]
1819

1920
[dependencies]
2021
thiserror = { version = "2.0.19" }
21-
tracing = { version = "0.1.44" }
22+
tracing = { version = "0.1.44", default-features = false, optional = true }
2223
rustc-hash = { version = "2.1.3" }
2324
indexmap = { version = "2.14.0" }
2425
rand = { version = "0.10.2" }
@@ -56,4 +57,3 @@ base64 = { version = "0.22.1" }
5657

5758
# for rfc8941 structured field values
5859
sfv = { version = "0.15.0" }
59-

httpsig/src/trace.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,43 @@
1+
#[cfg(feature = "tracing")]
12
#[allow(unused)]
2-
pub use tracing::{debug, error, info, trace, warn};
3+
pub(crate) use tracing::{debug, error, info, trace, warn};
4+
5+
/// No-op macros used when the `tracing` feature is disabled.
6+
/// They expand to `()` so that they are usable both in statement and
7+
/// expression positions, like the original `tracing` macros.
8+
/// `warn` is defined as `warn_` and re-exported, since a macro named
9+
/// `warn` conflicts with the built-in `warn` attribute (E0659).
10+
#[cfg(not(feature = "tracing"))]
11+
mod noop {
12+
#![allow(unused_macros)]
13+
macro_rules! debug {
14+
($($arg:tt)*) => {
15+
()
16+
};
17+
}
18+
macro_rules! error {
19+
($($arg:tt)*) => {
20+
()
21+
};
22+
}
23+
macro_rules! info {
24+
($($arg:tt)*) => {
25+
()
26+
};
27+
}
28+
macro_rules! trace {
29+
($($arg:tt)*) => {
30+
()
31+
};
32+
}
33+
macro_rules! warn_ {
34+
($($arg:tt)*) => {
35+
()
36+
};
37+
}
38+
#[allow(unused_imports)]
39+
pub(crate) use {debug, error, info, trace, warn_ as warn};
40+
}
41+
#[cfg(not(feature = "tracing"))]
42+
#[allow(unused)]
43+
pub(crate) use noop::*;

0 commit comments

Comments
 (0)