From b6f169f0837a6a43135f721bfb9371c3ddd01f3f Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Tue, 1 Mar 2022 16:22:37 +0000 Subject: [PATCH 1/3] Improve manifest whitespace Mirror the whitespacing in `rust-bitcoin` by doing: - Only use single line of whitespace between sections - Separate optional dependencies from non-optional ones --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a8d5a56d5..bc421e9ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,11 +37,11 @@ global-context-less-secure = [] [dependencies] secp256k1-sys = { version = "0.4.2", default-features = false, path = "./secp256k1-sys" } + bitcoin_hashes = { version = "0.10", optional = true } rand = { version = "0.6", default-features = false, optional = true } serde = { version = "1.0", default-features = false, optional = true } - [dev-dependencies] rand = "0.6" rand_core = "0.4" From 555833b70f1ceaa6f3e5185330a1ee7cd810534f Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Tue, 1 Mar 2022 16:24:05 +0000 Subject: [PATCH 2/3] Disable bitcoin_hashes default features Currently we use default features for the `bitcoin_hashes` dependency, doing so breaks the `no-std` feature in `rust-bitcoin` because `std` is part of `bitcoin_hashes` default feature set. Disable `bitcoin_hashes` default features, no changes to `rust-bitcoin` are require after this change since we manually turn on `std` and `alloc` as part of the `std`/`no-std` features of `rust-bitcoin`. For other users of `rust-secp256k1` this is a breaking change but is unlikely to cause too much bother because `std` is so commonly used. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index bc421e9ed..147d8ce26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ global-context-less-secure = [] [dependencies] secp256k1-sys = { version = "0.4.2", default-features = false, path = "./secp256k1-sys" } -bitcoin_hashes = { version = "0.10", optional = true } +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 } From 6bcf3ea0d0216d154b7a4955110dcb749935d588 Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Wed, 2 Mar 2022 09:01:12 +0000 Subject: [PATCH 3/3] 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. --- Cargo.toml | 5 ++++- contrib/test.sh | 13 ++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 147d8ce26..31faa5f0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ 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"] recovery = ["secp256k1-sys/recovery"] lowmemory = ["secp256k1-sys/lowmemory"] @@ -37,10 +38,12 @@ global-context-less-secure = [] [dependencies] secp256k1-sys = { version = "0.4.2", default-features = false, path = "./secp256k1-sys" } +serde = { version = "1.0", default-features = false, optional = true } +# 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 } [dev-dependencies] rand = "0.6" diff --git a/contrib/test.sh b/contrib/test.sh index c79d3f8ea..5ac08d045 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -1,7 +1,10 @@ #!/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" +# These features are typically enabled along with the 'std' feature, so we test +# them together with 'std'. +STD_FEATURES="rand-std bitcoin-hashes-std" # Use toolchain if explicitly specified if [ -n "$TOOLCHAIN" ] @@ -32,11 +35,15 @@ if [ "$DO_FEATURE_MATRIX" = true ]; then cargo build --all --no-default-features --features="$feature" cargo test --all --no-default-features --features="$feature" done - + # Features tested with 'std' feature enabled. + for feature in ${FEATURES} + do + cargo build --all --no-default-features --features="std,$feature" + cargo test --all --no-default-features --features="std,$feature" + done # 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" if [ "$DO_BENCH" = true ]; then # proxy for us having a nightly compiler