diff --git a/Cargo.toml b/Cargo.toml index b7513158..3213e694 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,6 @@ edition = "2018" # Please don't forget to add relevant features to docs.rs below [features] default = [ "std", "secp-recovery" ] -unstable = [] rand = ["secp256k1/rand-std"] serde = ["actual-serde", "bitcoin_hashes/serde", "secp256k1/serde"] secp-lowmemory = ["secp256k1/lowmemory"] diff --git a/README.md b/README.md index 434eb4ee..316e467c 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,11 @@ shell alias to check your documentation changes build correctly. alias build-docs='RUSTDOCFLAGS="--cfg docsrs" cargo +nightly rustdoc --features="$FEATURES" -- -D rustdoc::broken-intra-doc-links' ``` +### Running benchmarks + +We use a custom Rust compiler configuration conditional to guard the bench mark code. To run the +bench marks use: `RUSTFLAGS='--cfg=bench' cargo +nightly bench`. + ## Pull Requests Every PR needs at least two reviews to get merged. During the review phase diff --git a/contrib/test.sh b/contrib/test.sh index f46a2de5..37b8cfd2 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -77,7 +77,7 @@ then ) fi -# Bench if told to +# Bench if told to, only works with non-stable toolchain (nightly, beta). if [ "$DO_BENCH" = true ] then if [ "NIGHTLY" = false ] @@ -90,7 +90,7 @@ then fi exit 1 fi - cargo bench --features unstable + RUSTFLAGS='--cfg=bench' cargo bench fi # Use as dependency if told to diff --git a/src/blockdata/block.rs b/src/blockdata/block.rs index 0b639e12..0fd6155c 100644 --- a/src/blockdata/block.rs +++ b/src/blockdata/block.rs @@ -528,7 +528,7 @@ mod tests { } } -#[cfg(all(test, feature = "unstable"))] +#[cfg(bench)] mod benches { use super::Block; use crate::EmptyWrite; diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index c6d1534b..271ce69d 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -1724,7 +1724,7 @@ mod tests { } } -#[cfg(all(test, feature = "unstable"))] +#[cfg(bench)] mod benches { use super::Transaction; use crate::EmptyWrite; diff --git a/src/blockdata/witness.rs b/src/blockdata/witness.rs index d2733c90..9b6da04a 100644 --- a/src/blockdata/witness.rs +++ b/src/blockdata/witness.rs @@ -441,7 +441,7 @@ mod test { } -#[cfg(all(test, feature = "unstable"))] +#[cfg(bench)] mod benches { use test::{Bencher, black_box}; use super::Witness; diff --git a/src/lib.rs b/src/lib.rs index 12262aa8..f32839f5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,7 +19,6 @@ //! * `std` - the usual dependency on `std` (default). //! * `secp-recovery` - enables calculating public key from a signature and message. //! * `base64` - (dependency), enables encoding of PSBTs and message signatures. -//! * `unstable` - enables unstable features for testing. //! * `rand` - (dependency), makes it more convenient to generate random values. //! * `serde` - (dependency), implements `serde`-based serialization and //! deserialization. @@ -31,9 +30,8 @@ #![cfg_attr(all(not(feature = "std"), not(test)), no_std)] -// Experimental features we need -#![cfg_attr(all(test, feature = "unstable"), feature(test))] - +// Experimental features we need. +#![cfg_attr(bench, feature(test))] #![cfg_attr(docsrs, feature(doc_cfg))] // Coding conventions @@ -56,6 +54,8 @@ compile_error!("rust-bitcoin currently only supports architectures with pointers than 16 bits, let us know if you want 16-bit support. Note that we do NOT guarantee that we will implement it!"); +#[cfg(bench)] extern crate test; + #[cfg(feature = "no-std")] #[macro_use] extern crate alloc; @@ -184,10 +184,10 @@ mod prelude { pub use std::collections::HashSet; } -#[cfg(all(test, feature = "unstable"))] use tests::EmptyWrite; +#[cfg(bench)] use bench::EmptyWrite; -#[cfg(all(test, feature = "unstable"))] -mod tests { +#[cfg(bench)] +mod bench { use core::fmt::Arguments; use crate::io::{IoSlice, Result, Write};