Skip to content

Commit bd4d441

Browse files
committed
Merge #182: Simplify cargo features
405311a chore: Update justfile (valued mammal) 1aeb576 ci: Add Check job to check build features matrix (valued mammal) 58bbb50 build!: Always implement `calls_made` (valued mammal) 02c72cc build!: Remove unused `minimal` feature (valued mammal) c2976cf build: Enable plaintext Client using --no-default-features (valued mammal) bb5c839 build: move away from `use-` feature naming (valued mammal) 19d243a refactor: remove `default` feature gating (valued mammal) d010264 build: Clean up `proxy` feature (valued mammal) Pull request description: ## Description This PR is meant to streamline the handling of feature flags in the library, in particular by removing the Client's dependency on the `proxy` feature and overall simplifying the feature gating logic. Additionally, we move away from the old `use-*` feature naming convention by introducing simpler feature names, remove the unused `minimal` feature, and get rid of conditional compilation for `debug-calls` while retaining the ability to atomically count calls made. fixes #91 fixes #42 ACKs for top commit: oleonardolima: ACK 405311a Tree-SHA512: f53229407d957dc7c716b152879b4a376ddc0b30829fe9bc492f9d88c7d287201d6ffa028a90ca4c9f74f557c7759320db4b1ad607bbc314374a3aba0ce82344
2 parents 7c716cc + 405311a commit bd4d441

File tree

8 files changed

+121
-113
lines changed

8 files changed

+121
-113
lines changed

.github/workflows/cont_integration.yml

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,40 @@ jobs:
3030
toolchain: ${{ matrix.rust }}
3131
- name: Test
3232
run: cargo test --verbose --all-features
33-
- run: cargo check --verbose --features=use-openssl
34-
- run: cargo check --verbose --no-default-features --features=proxy
35-
- run: cargo check --verbose --no-default-features --features=minimal
36-
- run: cargo check --verbose --no-default-features --features=minimal,debug-calls
37-
- run: cargo check --verbose --no-default-features --features=proxy,use-openssl
38-
- run: cargo check --verbose --no-default-features --features=proxy,use-rustls
39-
- run: cargo check --verbose --no-default-features --features=proxy,use-rustls-ring
40-
- run: cargo check --verbose --no-default-features --features=proxy,use-rustls,use-rustls-ring
33+
34+
check:
35+
name: Check
36+
runs-on: ubuntu-latest
37+
strategy:
38+
matrix:
39+
rust:
40+
- stable # STABLE
41+
- 1.75.0 # MSRV
42+
features:
43+
- --features default
44+
- --no-default-features
45+
- --no-default-features --features proxy
46+
- --no-default-features --features openssl
47+
- --no-default-features --features rustls
48+
- --no-default-features --features rustls-ring
49+
- --no-default-features --features proxy,openssl,rustls,rustls-ring
50+
steps:
51+
- name: Checkout
52+
uses: actions/checkout@v4
53+
- name: Cache
54+
uses: actions/cache@v4
55+
with:
56+
path: |
57+
~/.cargo/registry
58+
~/.cargo/git
59+
target
60+
key: ${{ runner.os }}-cargo-${{ github.job }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
61+
- name: Install rust
62+
uses: dtolnay/rust-toolchain@stable
63+
with:
64+
toolchain: ${{ matrix.rust }}
65+
- name: Check features
66+
run: cargo check --verbose ${{ matrix.features }}
4167

4268
fmt:
4369
name: Rust fmt

Cargo.toml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ libc = { version = "0.2", optional = true }
3838
winapi = { version="0.3.9", features=["winsock2"], optional = true }
3939

4040
[features]
41-
default = ["proxy", "use-rustls"]
42-
minimal = []
43-
debug-calls = []
41+
default = ["proxy", "rustls"]
4442
proxy = ["byteorder", "winapi", "libc"]
45-
use-rustls = ["webpki-roots", "rustls/default"]
46-
use-rustls-ring = ["webpki-roots", "rustls/ring", "rustls/logging", "rustls/std", "rustls/tls12"]
43+
rustls = ["webpki-roots", "dep:rustls", "rustls/default"]
44+
rustls-ring = ["webpki-roots", "dep:rustls", "rustls/ring", "rustls/logging", "rustls/std", "rustls/tls12"]
45+
openssl = ["dep:openssl"]
46+
47+
# Old feature names
48+
use-rustls = ["rustls"]
49+
use-rustls-ring = ["rustls-ring"]
4750
use-openssl = ["openssl"]

justfile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,23 @@ build:
1414
# Check code: formatting, compilation, linting, doc comments, and commit signature
1515
check:
1616
cargo +nightly fmt --all -- --check
17-
cargo check --all-features --all-targets
17+
@just _check-features
1818
cargo clippy --all-features --all-targets -- -D warnings
19-
RUSTDOCFLAGS="-D warnings" cargo doc --all-features --no-deps
19+
cargo rustdoc --all-features -- -D warnings
2020
@[ "$(git log --pretty='format:%G?' -1 HEAD)" = "N" ] && \
2121
echo "\n⚠️ Unsigned commit: BDK requires that commits be signed." || \
2222
true
2323

24+
# Check feature configurations (matches CI)
25+
_check-features:
26+
cargo check --features "default"
27+
cargo check --no-default-features
28+
cargo check --no-default-features --features "proxy"
29+
cargo check --no-default-features --features "openssl"
30+
cargo check --no-default-features --features "rustls"
31+
cargo check --no-default-features --features "rustls-ring"
32+
cargo check --no-default-features --features "proxy,openssl,rustls,rustls-ring"
33+
2434
# Format all code
2535
fmt:
2636
cargo +nightly fmt

src/api.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ where
187187
(**self).ping()
188188
}
189189

190-
#[cfg(feature = "debug-calls")]
191190
fn calls_made(&self) -> Result<usize, Error> {
192191
(**self).calls_made()
193192
}
@@ -453,7 +452,6 @@ pub trait ElectrumApi {
453452
/// of incoming block header or script notifications.
454453
fn ping(&self) -> Result<(), Error>;
455454

456-
#[cfg(feature = "debug-calls")]
457455
/// Returns the number of network calls made since the creation of the client.
458456
fn calls_made(&self) -> Result<usize, Error>;
459457
}
@@ -677,7 +675,6 @@ mod test {
677675
unreachable!()
678676
}
679677

680-
#[cfg(feature = "debug-calls")]
681678
fn calls_made(&self) -> Result<usize, super::Error> {
682679
unreachable!()
683680
}

src/client.rs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ use std::convert::TryFrom;
1717
/// [`RawClient`](client/struct.RawClient.html) and provides a more user-friendly
1818
/// constructor that can choose the right backend based on the url prefix.
1919
///
20-
/// **This is available only with the `default` features, or if `proxy` and one ssl implementation are enabled**
20+
/// **Note the `Socks5` client type requires the `proxy` feature to be enabled.**
2121
pub enum ClientType {
2222
#[allow(missing_docs)]
2323
TCP(RawClient<ElectrumPlaintextStream>),
2424
#[allow(missing_docs)]
25+
#[cfg(any(feature = "openssl", feature = "rustls", feature = "rustls-ring"))]
2526
SSL(RawClient<ElectrumSslStream>),
2627
#[allow(missing_docs)]
28+
#[cfg(feature = "proxy")]
2729
Socks5(RawClient<ElectrumProxyStream>),
2830
}
2931

@@ -43,7 +45,9 @@ macro_rules! impl_inner_call {
4345
let read_client = $self.client_type.read().unwrap();
4446
let res = match &*read_client {
4547
ClientType::TCP(inner) => inner.$name( $($args, )* ),
48+
#[cfg(any(feature = "openssl", feature = "rustls", feature = "rustls-ring"))]
4649
ClientType::SSL(inner) => inner.$name( $($args, )* ),
50+
#[cfg(feature = "proxy")]
4751
ClientType::Socks5(inner) => inner.$name( $($args, )* ),
4852
};
4953
drop(read_client);
@@ -108,8 +112,10 @@ impl ClientType {
108112
/// Constructor that supports multiple backends and allows configuration through
109113
/// the [Config]
110114
pub fn from_config(url: &str, config: &Config) -> Result<Self, Error> {
115+
#[cfg(any(feature = "openssl", feature = "rustls", feature = "rustls-ring"))]
111116
if url.starts_with("ssl://") {
112117
let url = url.replacen("ssl://", "", 1);
118+
#[cfg(feature = "proxy")]
113119
let client = match config.socks5() {
114120
Some(socks5) => RawClient::new_proxy_ssl(
115121
url.as_str(),
@@ -121,19 +127,36 @@ impl ClientType {
121127
RawClient::new_ssl(url.as_str(), config.validate_domain(), config.timeout())?
122128
}
123129
};
130+
#[cfg(not(feature = "proxy"))]
131+
let client =
132+
RawClient::new_ssl(url.as_str(), config.validate_domain(), config.timeout())?;
124133

125-
Ok(ClientType::SSL(client))
126-
} else {
127-
let url = url.replacen("tcp://", "", 1);
134+
return Ok(ClientType::SSL(client));
135+
}
128136

129-
Ok(match config.socks5().as_ref() {
130-
None => ClientType::TCP(RawClient::new(url.as_str(), config.timeout())?),
137+
#[cfg(not(any(feature = "openssl", feature = "rustls", feature = "rustls-ring")))]
138+
if url.starts_with("ssl://") {
139+
return Err(Error::Message(
140+
"SSL connections require one of the following features to be enabled: openssl, rustls, or rustls-ring".to_string()
141+
));
142+
}
143+
144+
{
145+
let url = url.replacen("tcp://", "", 1);
146+
#[cfg(feature = "proxy")]
147+
let client = match config.socks5() {
131148
Some(socks5) => ClientType::Socks5(RawClient::new_proxy(
132149
url.as_str(),
133150
socks5,
134151
config.timeout(),
135152
)?),
136-
})
153+
None => ClientType::TCP(RawClient::new(url.as_str(), config.timeout())?),
154+
};
155+
156+
#[cfg(not(feature = "proxy"))]
157+
let client = ClientType::TCP(RawClient::new(url.as_str(), config.timeout())?);
158+
159+
Ok(client)
137160
}
138161
}
139162
}
@@ -381,7 +404,6 @@ impl ElectrumApi for Client {
381404
}
382405

383406
#[inline]
384-
#[cfg(feature = "debug-calls")]
385407
fn calls_made(&self) -> Result<usize, Error> {
386408
impl_inner_call!(self, calls_made)
387409
}

src/lib.rs

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! plaintext connections over a socks proxy, useful for Onion servers. Using different features,
88
//! the SSL implementation can be removed or replaced with [`openssl`](https://docs.rs/openssl).
99
//!
10-
//! A `minimal` configuration is also provided, which only includes the plaintext TCP client.
10+
//! For a minimal configuration the library can be built with `--no-default-features`, which only includes the plaintext TCP client.
1111
//!
1212
//! # Example
1313
//!
@@ -22,46 +22,30 @@
2222
pub extern crate bitcoin;
2323
extern crate core;
2424
extern crate log;
25-
#[cfg(feature = "use-openssl")]
25+
#[cfg(feature = "openssl")]
2626
extern crate openssl;
27-
#[cfg(all(
28-
any(
29-
feature = "default",
30-
feature = "use-rustls",
31-
feature = "use-rustls-ring"
32-
),
33-
not(feature = "use-openssl")
34-
))]
27+
#[cfg(any(feature = "rustls", feature = "rustls-ring"))]
3528
extern crate rustls;
3629
extern crate serde;
3730
extern crate serde_json;
3831

39-
#[cfg(any(
40-
feature = "default",
41-
feature = "use-rustls",
42-
feature = "use-rustls-ring"
43-
))]
32+
#[cfg(any(feature = "rustls", feature = "rustls-ring"))]
4433
extern crate webpki_roots;
4534

46-
#[cfg(any(feature = "default", feature = "proxy"))]
35+
#[cfg(feature = "proxy")]
4736
extern crate byteorder;
4837

49-
#[cfg(all(unix, any(feature = "default", feature = "proxy")))]
38+
#[cfg(all(unix, feature = "proxy"))]
5039
extern crate libc;
51-
#[cfg(all(windows, any(feature = "default", feature = "proxy")))]
40+
#[cfg(all(windows, feature = "proxy"))]
5241
extern crate winapi;
5342

54-
#[cfg(any(feature = "default", feature = "proxy"))]
43+
#[cfg(feature = "proxy")]
5544
pub mod socks;
5645

5746
mod api;
5847
mod batch;
5948

60-
#[cfg(any(
61-
all(feature = "proxy", feature = "use-openssl"),
62-
all(feature = "proxy", feature = "use-rustls"),
63-
all(feature = "proxy", feature = "use-rustls-ring")
64-
))]
6549
pub mod client;
6650

6751
mod config;
@@ -73,11 +57,6 @@ pub mod utils;
7357

7458
pub use api::ElectrumApi;
7559
pub use batch::Batch;
76-
#[cfg(any(
77-
all(feature = "proxy", feature = "use-openssl"),
78-
all(feature = "proxy", feature = "use-rustls"),
79-
all(feature = "proxy", feature = "use-rustls-ring")
80-
))]
8160
pub use client::*;
8261
pub use config::{Config, ConfigBuilder, Socks5Config};
8362
pub use types::*;

0 commit comments

Comments
 (0)