From 36970032fd2b82010c6db7187990446d2a73fe2a Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Wed, 2 Mar 2022 09:01:12 +0000 Subject: [PATCH] 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. --- Cargo.toml | 4 ++++ contrib/test.sh | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 147d8ce26..4ceaad25d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,9 @@ default = ["std"] std = ["secp256k1-sys/std"] # allow use of Secp256k1::new and related API that requires an allocator alloc = [] +bitcoin-hashes-std = ["bitcoin_hashes/std"] rand-std = ["rand/std"] +serde-std = ["serde/std"] recovery = ["secp256k1-sys/recovery"] lowmemory = ["secp256k1-sys/lowmemory"] global-context = ["std"] @@ -38,6 +40,8 @@ global-context-less-secure = [] [dependencies] secp256k1-sys = { version = "0.4.2", default-features = false, path = "./secp256k1-sys" } +# You likely only want to enable these if you explicitly do not want to use "std", otherwise enable +# the respective -std feature e.g., bitcoin-hashes-std bitcoin_hashes = { version = "0.10", default-features = false, optional = true } rand = { version = "0.6", default-features = false, optional = true } serde = { version = "1.0", default-features = false, optional = true } diff --git a/contrib/test.sh b/contrib/test.sh index c79d3f8ea..a74c6babd 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -1,7 +1,7 @@ #!/bin/sh -ex # TODO: Add "alloc" once we bump MSRV to past 1.29 -FEATURES="bitcoin_hashes global-context lowmemory rand rand-std recovery serde std" +FEATURES="bitcoin_hashes global-context lowmemory rand recovery serde std" # Use toolchain if explicitly specified if [ -n "$TOOLCHAIN" ] @@ -36,8 +36,11 @@ if [ "$DO_FEATURE_MATRIX" = true ]; then # Other combos RUSTFLAGS='--cfg=fuzzing' RUSTDOCFLAGS=$RUSTFLAGS cargo test --all RUSTFLAGS='--cfg=fuzzing' RUSTDOCFLAGS=$RUSTFLAGS cargo test --all --features="$FEATURES" - cargo test --all --features="rand rand-std" cargo test --all --features="rand serde" + # Test features that will likely only be enabled along with `std`. + cargo test --all --features="rand-std" + cargo test --all --features="bitcoin-hashes-std" + cargo test --all --features="serde-std" if [ "$DO_BENCH" = true ]; then # proxy for us having a nightly compiler cargo test --all --all-features