From 0275928616a7151c18b442ad5afdd2d127830a8a Mon Sep 17 00:00:00 2001 From: Johnosezele Date: Sun, 17 Aug 2025 15:02:45 +0100 Subject: [PATCH] Allow building payjoin crate with no default features Previously, the payjoin crate would fail to build if none of the features 'v1', 'v2', or 'directory' were enabled, due to an explicit compile_error! macro. This prevented the use of tools like cargo-all-features for comprehensive CI and dead code detection. This change removes the compile_error! and replaces it with a doc-only module that is included when no features are enabled, making the crate a no-op in that configuration. The documentation and Cargo.toml are updated to clarify that at least one of the main features must be enabled for any functionality. This enables better CI, linting, and future modularity, while preserving clear guidance for users and contributors. Closes #921 --- README.md | 10 ++++++++++ payjoin/Cargo.toml | 2 ++ payjoin/src/lib.rs | 6 +++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4bfed3065..c42334fc1 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,16 @@ The Payjoin Dev Kit `payjoin` library implements both [BIP 78 Payjoin V1](https://github.com/bitcoin/bips/blob/master/bip-0078.mediawiki) and [BIP 77 Payjoin V2](https://github.com/bitcoin/bips/blob/master/bip-0077.md). +### Feature Flags + +The `payjoin` crate supports the following features: +- `v1`: Enables BIP 78 Payjoin V1 support. +- `v2`: Enables BIP 77 Payjoin V2 support (enabled by default). +- `directory`: Enables Payjoin Directory support. + +**Note:** +The crate will now build with no features enabled (e.g., `cargo build --no-default-features`), but in this configuration, no functionality is available. This is intended to support comprehensive CI and linting. To use the library, enable at least one of the features above. + ### `payjoin-cli` The [`payjoin-cli`](https://github.com/payjoin/rust-payjoin/tree/master/payjoin-cli) crate performs no-frills Payjoin as a reference implementation using Bitcoin Core wallet. diff --git a/payjoin/Cargo.toml b/payjoin/Cargo.toml index 65c3f2f83..6930e1c85 100644 --- a/payjoin/Cargo.toml +++ b/payjoin/Cargo.toml @@ -16,6 +16,8 @@ exclude = ["tests"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] +# The crate will build with no features enabled, but will provide no functionality. +# Enable at least one of: 'v1', 'v2', or 'directory' to use the library. default = ["v2"] #[doc = "Core features for payjoin state machines"] _core = ["bitcoin/rand-std", "serde_json", "url", "bitcoin_uri", "serde", "bitcoin/serde"] diff --git a/payjoin/src/lib.rs b/payjoin/src/lib.rs index af73afcee..e9d954f49 100644 --- a/payjoin/src/lib.rs +++ b/payjoin/src/lib.rs @@ -18,7 +18,11 @@ //! **Use at your own risk. This crate has not yet been reviewed by independent Rust and Bitcoin security professionals.** #[cfg(not(any(feature = "directory", feature = "v1", feature = "v2")))] -compile_error!("At least one of the features ['directory', 'v1', 'v2'] must be enabled"); +#[doc(hidden)] +pub mod no_features_enabled { + //! This crate was built with no features enabled. No functionality is available. + //! Enable at least one of the features: `directory`, `v1`, or `v2`. +} #[cfg(any(feature = "v2", feature = "directory"))] pub(crate) mod bech32;