Skip to content

Commit 6bcf3ea

Browse files
committed
Add bitcoin-hashes-std features
Currently we use 'no default features' for the `bitcoin_hashes` dependency. Doing so means that if users want the `std` feature they need to explicitly add a `bitcoin_hashes` dependency even though we re-export `bitcoin_hashes` as `hashes`. This means that in the common case the re-export is pointless. As an example, `rust-bitcoin` unnecessarily requires an explicit dependency on `bitcoin_hashes`. Add `bitcoin-hashes-std` feature so that users do not need an explicit dependency in the common use case. Change the test matrix to only test '*-std' features when 'std' is enabled since enabling one without the other is illogical. Please note, this replaces the test run of feature 'std'+'rand'+'rand-std' with just 'std'+'rand-std' because enabling 'rand-std' enables 'rand' so the explicit additional feature is redundant.
1 parent 555833b commit 6bcf3ea

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ default = ["std"]
2323
std = ["secp256k1-sys/std"]
2424
# allow use of Secp256k1::new and related API that requires an allocator
2525
alloc = []
26+
bitcoin-hashes-std = ["bitcoin_hashes/std"]
2627
rand-std = ["rand/std"]
2728
recovery = ["secp256k1-sys/recovery"]
2829
lowmemory = ["secp256k1-sys/lowmemory"]
@@ -37,10 +38,12 @@ global-context-less-secure = []
3738

3839
[dependencies]
3940
secp256k1-sys = { version = "0.4.2", default-features = false, path = "./secp256k1-sys" }
41+
serde = { version = "1.0", default-features = false, optional = true }
4042

43+
# You likely only want to enable these if you explicitly do not want to use "std", otherwise enable
44+
# the respective -std feature e.g., bitcoin-hashes-std
4145
bitcoin_hashes = { version = "0.10", default-features = false, optional = true }
4246
rand = { version = "0.6", default-features = false, optional = true }
43-
serde = { version = "1.0", default-features = false, optional = true }
4447

4548
[dev-dependencies]
4649
rand = "0.6"

contrib/test.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/bin/sh -ex
22

33
# TODO: Add "alloc" once we bump MSRV to past 1.29
4-
FEATURES="bitcoin_hashes global-context lowmemory rand rand-std recovery serde std"
4+
FEATURES="bitcoin_hashes global-context lowmemory rand recovery serde std"
5+
# These features are typically enabled along with the 'std' feature, so we test
6+
# them together with 'std'.
7+
STD_FEATURES="rand-std bitcoin-hashes-std"
58

69
# Use toolchain if explicitly specified
710
if [ -n "$TOOLCHAIN" ]
@@ -32,11 +35,15 @@ if [ "$DO_FEATURE_MATRIX" = true ]; then
3235
cargo build --all --no-default-features --features="$feature"
3336
cargo test --all --no-default-features --features="$feature"
3437
done
35-
38+
# Features tested with 'std' feature enabled.
39+
for feature in ${FEATURES}
40+
do
41+
cargo build --all --no-default-features --features="std,$feature"
42+
cargo test --all --no-default-features --features="std,$feature"
43+
done
3644
# Other combos
3745
RUSTFLAGS='--cfg=fuzzing' RUSTDOCFLAGS=$RUSTFLAGS cargo test --all
3846
RUSTFLAGS='--cfg=fuzzing' RUSTDOCFLAGS=$RUSTFLAGS cargo test --all --features="$FEATURES"
39-
cargo test --all --features="rand rand-std"
4047
cargo test --all --features="rand serde"
4148

4249
if [ "$DO_BENCH" = true ]; then # proxy for us having a nightly compiler

0 commit comments

Comments
 (0)