Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable 2018 edition, bump MSRV to 1.41 and bump to v2.0.0 #41

Merged
merged 11 commits into from
Feb 28, 2023
100 changes: 100 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
on: [push, pull_request]

name: Continuous integration

jobs:
Stable:
name: Test - stable toolchain
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Checkout Crate
uses: actions/checkout@v3
- name: Checkout Toolchain
# https://github.com/dtolnay/rust-toolchain
uses: dtolnay/rust-toolchain@stable
- name: Running test script
env:
DO_NO_STD: true
DO_FEATURE_MATRIX: true
run: ./contrib/test.sh

Beta:
name: Test - beta toolchain
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Checkout Crate
uses: actions/checkout@v3
- name: Checkout Toolchain
uses: dtolnay/rust-toolchain@beta
- name: Running test script
env:
DO_NO_STD: true
run: ./contrib/test.sh

Nightly:
name: Test - nightly toolchain
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Checkout Crate
uses: actions/checkout@v3
- name: Checkout Toolchain
uses: dtolnay/rust-toolchain@nightly
- name: Running test script
env:
DO_NO_STD: true
run: ./contrib/test.sh

MSRV:
name: Test - 1.41.1 toolchain
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Checkout Crate
uses: actions/checkout@v3
- name: Checkout Toolchain
uses: dtolnay/[email protected]
- name: Running test script
env:
DO_NO_STD: true
DO_FEATURE_MATRIX: true
run: ./contrib/test.sh

Arch32bit:
name: Test 32-bit version
runs-on: ubuntu-latest
steps:
- name: Checkout Crate
uses: actions/checkout@v3
- name: Checkout Toolchain
uses: dtolnay/rust-toolchain@stable
- name: Add architecture i386
run: sudo dpkg --add-architecture i386
- name: Install i686 gcc
run: sudo apt-get update -y && sudo apt-get install -y gcc-multilib
- name: Install target
run: rustup target add i686-unknown-linux-gnu
- name: Run test on i686
run: cargo test --target i686-unknown-linux-gnu

Cross:
name: Cross test
if: ${{ !github.event.act }}
runs-on: ubuntu-latest
steps:
- name: Checkout Crate
uses: actions/checkout@v3
- name: Checkout Toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install target
run: rustup target add s390x-unknown-linux-gnu
- name: install cross
run: cargo install cross --locked
- name: run cross test
run: cross test --target s390x-unknown-linux-gnu
28 changes: 0 additions & 28 deletions .travis.yml

This file was deleted.

9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
CHANGELOG
=========

# v2.0.0

- Set Rust edition to 2018
- Make `rand` and `rand_core` dependencies more flexible
- Increase maximum version in constraint
- Make `rand_core` optional too
- Expose both crates
- Bump MSRV to 1.41.1

# v1.2.0

- Add `Mnemonic::parse_in_normalized_without_checksum_check`
Expand Down
25 changes: 13 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bip39"
version = "1.2.0"
version = "2.0.0"
authors = ["Steven Roose <[email protected]>"]
license = "CC0-1.0"
homepage = "https://github.com/rust-bitcoin/rust-bip39/"
Expand All @@ -9,14 +9,12 @@ documentation = "https://docs.rs/bip39/"
description = "Library for BIP-39 Bitcoin mnemonic codes"
keywords = [ "crypto", "bitcoin", "bip39", "mnemonic" ]
readme = "README.md"

[lib]
name = "bip39"
path = "src/lib.rs"
edition = "2018"

[features]
default = [ "std" ]
std = [ "unicode-normalization", "serde/std" ]
rand = [ "crate_rand", "rand_core" ]

# Note: English is the standard for bip39 so always included
chinese-simplified = []
Expand All @@ -40,16 +38,19 @@ all-languages = [
]

[dependencies]
bitcoin_hashes = { version = "0.11.0", default-features = false }
rand_core = "0.4.0"
rand_core = { version = ">=0.4.0, <0.7.0", optional = true }
crate_rand = { package = "rand", version = ">=0.6.0, <0.9.0", optional = true }
serde = { version = "1.0", default-features = false, features = [ "alloc" ], optional = true }

unicode-normalization = { version = "=0.1.9", optional = true }
rand = { version = "0.6.0", optional = true }
serde = { version = "1.0", default-features = false, optional = true }
# Enabling this feature raises the MSRV to 1.51
zeroize = {version = "1.5", features = ["zeroize_derive"], optional = true}
zeroize = { version = "1.5", features = ["zeroize_derive"], optional = true }

# Unexported dependnecies
bitcoin_hashes = { version = "0.11.0", default-features = false }
unicode-normalization = { version = "=0.1.22", optional = true }

[dev-dependencies]
rand = { version = "0.6.0", optional = false }
rand_core = { version = "0.6.4", optional = false }
crate_rand = { package = "rand", version = "0.8.5", optional = false }
bitcoin_hashes = "0.11.0" # enable default features for test

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ Use the `all-languages` feature to enable all languages.

## MSRV

This crate supports Rust v1.29 and up and works with `no_std`.
This crate supports Rust v1.41.1 and up and works with `no_std`.

If you enable the `zeroize` feature the MSRV becomes 1.51
If you enable the `zeroize` feature the MSRV becomes 1.51.
54 changes: 54 additions & 0 deletions contrib/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/sh

set -ex

FEATURES="serde rand all-languages"

cargo --version
rustc --version

# Work out if we are using a nightly toolchain.
NIGHTLY=false
if cargo --version | grep nightly; then
NIGHTLY=true
fi

# Pin dependencies as required if we are using MSRV toolchain.
# if cargo --version | grep "1\.41"; then
# fi

echo "********* Testing std *************"
# Test without any features other than std first
cargo test --verbose --no-default-features --features="std"

echo "********* Testing default *************"
# Then test with the default features
cargo test --verbose

if [ "$DO_NO_STD" = true ]
then
echo "********* Testing no-std build *************"
# Build no_std, to make sure that cfg(test) doesn't hide any issues
cargo build --verbose --no-default-features

# Build std + no_std, to make sure they are not incompatible
cargo build --verbose
# Test no_std
cargo test --verbose --no-default-features

# Build all features
cargo build --verbose --features="$FEATURES" --no-default-features

# Build specific features
for feature in ${FEATURES}
do
cargo build --verbose --features="$feature" --no-default-features
done
fi

# Test each feature
for feature in ${FEATURES}
do
echo "********* Testing $feature *************"
cargo test --verbose --features="$feature"
done
5 changes: 3 additions & 2 deletions src/internal_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ macro_rules! serde_string_impl {
where
D: $crate::serde::de::Deserializer<'de>,
{
use std::fmt::{self, Formatter};
use std::str::FromStr;
use core::fmt::{self, Formatter};
use core::str::FromStr;
use alloc::string::String;

struct Visitor;
impl<'de> $crate::serde::de::Visitor<'de> for Visitor {
Expand Down
11 changes: 7 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@
#[cfg(any(test, feature = "std"))]
pub extern crate core;

extern crate alloc;

extern crate bitcoin_hashes;
extern crate rand_core;

#[cfg(feature = "std")]
extern crate unicode_normalization;

#[cfg(feature = "rand_core")]
pub extern crate rand_core;
#[cfg(feature = "rand")]
extern crate rand;
pub extern crate crate_rand as rand;
#[cfg(feature = "serde")]
pub extern crate serde;

Expand Down Expand Up @@ -246,14 +249,14 @@ impl Mnemonic {
/// Example:
///
/// ```
/// extern crate rand;
/// extern crate bip39;
///
/// use bip39::{Mnemonic, Language};
///
/// let mut rng = rand::thread_rng();
/// let mut rng = bip39::rand::thread_rng();
/// let m = Mnemonic::generate_in_with(&mut rng, Language::English, 24).unwrap();
/// ```
#[cfg(feature = "rand_core")]
pub fn generate_in_with<R>(
rng: &mut R,
language: Language,
Expand Down