Skip to content

Commit 3697003

Browse files
committed
Add -std features
Currently we provide dependencies with default features disabled, this is so that the 'alloc' feature (e.g. `no-std`) functions correctly. However, this means that in the common case users of the library must add an explicit dependency for `bitcoin_hashes` and `serde` if they wish to use 'std'. Especially for `bitcoin_hashes` this is inconvenient. Add -std features so that users do not need an explicit dependency in the common case. For this very reason, this patch opens up the way to remove the `bitcoin_hashes` dependency from `rust-bitcoin`. 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 3697003

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ 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"]
28+
serde-std = ["serde/std"]
2729
recovery = ["secp256k1-sys/recovery"]
2830
lowmemory = ["secp256k1-sys/lowmemory"]
2931
global-context = ["std"]
@@ -38,6 +40,8 @@ global-context-less-secure = []
3840
[dependencies]
3941
secp256k1-sys = { version = "0.4.2", default-features = false, path = "./secp256k1-sys" }
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 }
4347
serde = { version = "1.0", default-features = false, optional = true }

contrib/test.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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"
55

66
# Use toolchain if explicitly specified
77
if [ -n "$TOOLCHAIN" ]
@@ -36,8 +36,11 @@ if [ "$DO_FEATURE_MATRIX" = true ]; then
3636
# Other combos
3737
RUSTFLAGS='--cfg=fuzzing' RUSTDOCFLAGS=$RUSTFLAGS cargo test --all
3838
RUSTFLAGS='--cfg=fuzzing' RUSTDOCFLAGS=$RUSTFLAGS cargo test --all --features="$FEATURES"
39-
cargo test --all --features="rand rand-std"
4039
cargo test --all --features="rand serde"
40+
# Test features that will likely only be enabled along with `std`.
41+
cargo test --all --features="rand-std"
42+
cargo test --all --features="bitcoin-hashes-std"
43+
cargo test --all --features="serde-std"
4144

4245
if [ "$DO_BENCH" = true ]; then # proxy for us having a nightly compiler
4346
cargo test --all --all-features

0 commit comments

Comments
 (0)