From ec2a2cc1342a767f002226b0f21c24e7039cfecb Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 8 Apr 2024 06:53:08 +1000 Subject: [PATCH 1/4] Remove path dev-dependency Currently we are enabling "rand" using a path dependency in the dev-dependencies because of the benches. This is reducing coverage in CI because "std" is always enabled. Feature gate the bench that requires "rand" and remove the path dependency. --- Cargo.toml | 2 -- benches/bench.rs | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cc521ff..f4605c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,8 +53,6 @@ bitcoin_hashes = { version = ">=0.12, <=0.13", default-features = false } unicode-normalization = { version = "=0.1.22", default-features = false, optional = true } [dev-dependencies] -# Enabling the "rand" feature by default to run the benches -bip39 = { path = ".", features = ["rand"] } bitcoin_hashes = ">=0.12,<0.14" # enable default features for test diff --git a/benches/bench.rs b/benches/bench.rs index a11b129..a15926a 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -59,6 +59,7 @@ fn from_entropy(b: &mut Bencher) { }); } +#[cfg(feature = "rand")] #[bench] fn new_mnemonic(b: &mut Bencher) { b.iter(|| { From e7bad948b592278a99515aad89215a94c251dbad Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 8 Apr 2024 09:19:35 +1000 Subject: [PATCH 2/4] This should be PR 69 --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index feb3ac2..463a887 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,6 +46,8 @@ pub extern crate serde; #[cfg(feature = "alloc")] use alloc::borrow::Cow; +#[cfg(all(feature = "alloc", not(feature = "std")))] +use alloc::{string::ToString, vec::Vec}; use core::{fmt, str}; /// We support a wide range of dependency versions for `rand` and `rand_core` and not From 93d3484a09db34f5f5885ed65bd78e2a91ed64e8 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 8 Apr 2024 09:24:18 +1000 Subject: [PATCH 3/4] Document MSRV effect of different versions of hashes We use a range dependency for `bitcoin_hashes`, the different allowed versions each have a different MSRV, which implies using each changes the MSRV of `bip39`. --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index aecd61f..c97c10d 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,11 @@ Use the `all-languages` feature to enable all languages. This crate supports Rust v1.41.1 and up and works with `no_std`. +The `bitcoin_hashes` range dependency effects the MSRV as follows + +- `bitcoin_hashes v0.12`: MSRV v1.41.1 +- `bitcoin_hashes v0.13`: MSRV v1.48.0 + When using older version of Rust, you might have to pin the version of the `bitcoin_hashes` crate used as such: ``` From af383fbca5402bc2211ff5cf3a7b5391a0c3107b Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 8 Apr 2024 09:25:34 +1000 Subject: [PATCH 4/4] Add hashes 0.14 to the dependency range We just release a new version of `bitcoin_hashes` which works with `bip39` with no changes. Add `bitcoin_hashes v0.14` to the dependency range and document its effect on the MSRV. (Note, the "alloc" feature is required as of 0.14). --- Cargo.toml | 4 ++-- README.md | 1 + src/internal_macros.rs | 2 ++ src/lib.rs | 2 ++ 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f4605c0..41cfa5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,11 +49,11 @@ serde = { version = "1.0", default-features = false, features = [ "alloc" ], opt zeroize = { version = "1.5", features = ["zeroize_derive"], optional = true } # Unexported dependnecies -bitcoin_hashes = { version = ">=0.12, <=0.13", default-features = false } +bitcoin_hashes = { version = ">=0.12, <=0.14", default-features = false, features = ["alloc"] } unicode-normalization = { version = "=0.1.22", default-features = false, optional = true } [dev-dependencies] -bitcoin_hashes = ">=0.12,<0.14" # enable default features for test +bitcoin_hashes = ">=0.12,<=0.14" # enable default features for test [package.metadata.docs.rs] diff --git a/README.md b/README.md index c97c10d..ccc5c0f 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ The `bitcoin_hashes` range dependency effects the MSRV as follows - `bitcoin_hashes v0.12`: MSRV v1.41.1 - `bitcoin_hashes v0.13`: MSRV v1.48.0 +- `bitcoin_hashes v0.14`: MSRV v1.56.1 When using older version of Rust, you might have to pin the version of the `bitcoin_hashes` crate used as such: diff --git a/src/internal_macros.rs b/src/internal_macros.rs index 4d4ece1..707effe 100644 --- a/src/internal_macros.rs +++ b/src/internal_macros.rs @@ -10,6 +10,7 @@ macro_rules! serde_string_impl { { use core::fmt::{self, Formatter}; use core::str::FromStr; + #[cfg(feature = "alloc")] use alloc::string::String; struct Visitor; @@ -34,6 +35,7 @@ macro_rules! serde_string_impl { self.visit_str(v) } + #[cfg(feature = "alloc")] fn visit_string(self, v: String) -> Result where E: $crate::serde::de::Error, diff --git a/src/lib.rs b/src/lib.rs index 463a887..7bed102 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -622,6 +622,7 @@ impl Mnemonic { /// following assertion should hold: /// /// ```rust + /// # # [cfg(feature = "alloc")] { /// # use bip39::Mnemonic; /// # use bitcoin_hashes::{Hash, sha256, hex::FromHex}; /// # let ent = Vec::from_hex("98FE3D0FF6E955A484B0A1D0C9CE10F6").unwrap(); @@ -629,6 +630,7 @@ impl Mnemonic { /// let checksum_width = m.word_count() / 3; /// let shift_width = 8 - checksum_width; /// assert_eq!(sha256::Hash::hash(&m.to_entropy())[0] >> shift_width, m.checksum()); + /// # } /// ``` /// /// Note that since this library constrains initialization of `Mnemonic` instances through an