Skip to content

Commit

Permalink
Merge rust-bitcoin#4055: hashes: Only enable hex/std, and hex/alloc w…
Browse files Browse the repository at this point in the history
…hen hex is

7c12d92 Only enable hex/std, alloc when hex is (Jamil Lambert, PhD)
11770ca Add hashes to io dev-depencies and require hex (Jamil Lambert, PhD)
e7c6564 Add missing hex feature gate (Jamil Lambert, PhD)

Pull request description:

  `hex/std` and `hex/alloc` should only be included if optional dependency `hex` is enabled.  A bunch of tests that need `hex` relied on an `alloc` feature gate to ensure `hex/alloc` was enabled.

  Add feature gates to the tests that require `hex`.

  Add `?` so `hex/alloc` or `hex/std` are only included if the optional feature `hex` is enabled.

  Audit rest of crates `Cargo.toml` files: no other cases found.

  Close rust-bitcoin#4035

ACKs for top commit:
  Kixunil:
    ACK 7c12d92
  apoelstra:
    ACK 7c12d92; successfully ran local tests; Played with cargo a bit; `cargo tree` seems to confirm that you can mix dev and non-dev dependencies like this.

Tree-SHA512: bd752d3c074dd8c93b09aa318d98ccb761b2f9baa2797566dd1d5f486349a92fbcd05787ddeb53d1f05ef0b29fbf559152f6373674fbec01e1251e74ad61e61f
  • Loading branch information
apoelstra committed Feb 15, 2025
2 parents 0a19d01 + 7c12d92 commit 3fb5275
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions hashes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ exclude = ["tests", "contrib"]

[features]
default = ["std"]
std = ["alloc", "hex/std"]
alloc = ["hex/alloc"]
std = ["alloc", "hex?/std"]
alloc = ["hex?/alloc"]
serde = ["dep:serde", "hex"]
# Smaller (but slower) implementation of sha256, sha512 and ripemd160
small-hash = []
Expand Down
1 change: 1 addition & 0 deletions hashes/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ mod tests {
}

#[cfg(bench)]
#[cfg(feature = "hex")]
mod benches {
use test::Bencher;

Expand Down
1 change: 1 addition & 0 deletions hashes/src/hash160/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ impl crate::HashEngine for HashEngine {
mod tests {
#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn test() {
use alloc::string::ToString;

Expand Down
1 change: 1 addition & 0 deletions hashes/src/hkdf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ where

#[cfg(test)]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
mod tests {
use hex::prelude::{DisplayHex, FromHex};

Expand Down
1 change: 1 addition & 0 deletions hashes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ mod tests {

#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn newtype_fmt_roundtrip() {
use alloc::format;

Expand Down
1 change: 1 addition & 0 deletions hashes/src/ripemd160/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn test() {
use alloc::string::ToString;

Expand Down
1 change: 1 addition & 0 deletions hashes/src/sha1/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn test() {
use alloc::string::ToString;

Expand Down
2 changes: 2 additions & 0 deletions hashes/src/sha256/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{sha256, HashEngine};

#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn test() {
use alloc::string::ToString;

Expand Down Expand Up @@ -70,6 +71,7 @@ fn test() {

#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn fmt_roundtrips() {
use alloc::format;

Expand Down
2 changes: 2 additions & 0 deletions hashes/src/sha256d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ mod tests {

#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn test() {
use alloc::string::ToString;

Expand Down Expand Up @@ -98,6 +99,7 @@ mod tests {

#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn fmt_roundtrips() {
use alloc::format;

Expand Down
4 changes: 4 additions & 0 deletions hashes/src/sha256t/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,12 @@ mod tests {

// The digest created by sha256 hashing `&[0]` starting with `TEST_MIDSTATE`.
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
const HASH_ZERO_BACKWARD: &str =
"29589d5122ec666ab5b4695070b6debc63881a4f85d88d93ddc90078038213ed";
// And the same thing, forward.
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
const HASH_ZERO_FORWARD: &str =
"ed1382037800c9dd938dd8854f1a8863bcdeb6705069b4b56a66ec22519d5829";

Expand All @@ -198,10 +200,12 @@ mod tests {

// We support manually implementing `Tag` and creating a tagged hash from it.
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
pub type TestHash = sha256t::Hash<TestHashTag>;

#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn manually_created_sha256t_hash_type() {
use alloc::string::ToString;

Expand Down
1 change: 1 addition & 0 deletions hashes/src/sha384/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl crate::HashEngine for HashEngine {
mod tests {
#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn test() {
use alloc::string::ToString;

Expand Down
1 change: 1 addition & 0 deletions hashes/src/sha512/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn test() {
use alloc::string::ToString;

Expand Down
1 change: 1 addition & 0 deletions hashes/src/sha512_256/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl crate::HashEngine for HashEngine {
mod tests {
#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn test() {
use alloc::string::ToString;

Expand Down
3 changes: 3 additions & 0 deletions io/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ internals = { package = "bitcoin-internals", version = "0.4.0" }

hashes = { package = "bitcoin_hashes", version = "0.16.0", default-features = false, optional = true }

[dev-dependencies]
hashes = { package = "bitcoin_hashes", version = "0.16.0", default-features = false, features = ["hex"] }

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
Expand Down

0 comments on commit 3fb5275

Please sign in to comment.