From 34d5a3141d78c00081edbec2ca0f5b0a8960d9c5 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 13 Jul 2022 10:07:55 +1000 Subject: [PATCH 1/4] Put triple ticks on their own line In markdown triple ticks go on a line of their own. This change does not effect the rendering in GitHub which is managing to parse this section correctly already. --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6ae301cb01..434eb4eedc 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,9 @@ Please refer to the [`cargo` documentation](https://doc.rust-lang.org/stable/car We build docs with the nightly toolchain, you may wish to use the following 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'``` +``` +alias build-docs='RUSTDOCFLAGS="--cfg docsrs" cargo +nightly rustdoc --features="$FEATURES" -- -D rustdoc::broken-intra-doc-links' +``` ## Pull Requests From c6d5a12b607d7a947f75be0d685afc8a6fae69e7 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 14 Jul 2022 09:43:59 +1000 Subject: [PATCH 2/4] Add cargo/rustc sanity calls Add trivial calls to `cargo` and `rustc` as sanity checks before starting the script proper. --- contrib/test.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/test.sh b/contrib/test.sh index 4031b87509..6238d29913 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -13,6 +13,8 @@ then export RUSTFLAGS="-C link-dead-code" fi +cargo --version +rustc --version echo "********* Testing std *************" # Test without any features other than std first From f60c92ca58db9dd941224d02779e3a97a00d3b4f Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 14 Jul 2022 09:53:31 +1000 Subject: [PATCH 3/4] Add informative error message to DO_BENCH If CI script is run with `DO_BENCH=true` and `TOOLCHAIN` set to a non-nightly toolchain the build will fail with a less than meaningful error. To assist runners of the script output an informative error message if an attempt is made at using the wrong toolchain. --- contrib/test.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/contrib/test.sh b/contrib/test.sh index 6238d29913..f46a2de5b5 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -16,6 +16,12 @@ fi cargo --version rustc --version +# Work out if we are using a nightly toolchain. +NIGHTLY=false +if cargo --version | grep nightly; then + NIGHTLY=true +fi + echo "********* Testing std *************" # Test without any features other than std first cargo test --verbose --no-default-features --features="std" @@ -74,6 +80,16 @@ fi # Bench if told to if [ "$DO_BENCH" = true ] then + if [ "NIGHTLY" = false ] + then + if [ -n "TOOLCHAIN" ] + then + echo "TOOLCHAIN is set to a non-nightly toolchain but DO_BENCH requires a nightly toolchain" + else + echo "DO_BENCH requires a nightly toolchain" + fi + exit 1 + fi cargo bench --features unstable fi From f3b2120ec92636759c08c9dfe105c6bb08766007 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 12 Jul 2022 10:07:38 +1000 Subject: [PATCH 4/4] Create configuration conditional bench Currently we are unable to build with all features enabled with a non-nightly toolchain, this is because of the use of `#![cfg_attr(all(test, feature = "unstable"), feature(test))]` which causes the following error when building: error[E0554]: `#![feature]` may not be used on the stable release channel The "unstable" feature is used to guard bench mark modules, this is widely suggested online but there is a better way. When running the bench marks use the following incantation: `RUSTFLAGS='--cfg=bench' cargo bench` This creates a configuration conditional "bench" that can be used to guard the bench mark modules. #[cfg(bench)] mod benches { ... } --- Cargo.toml | 1 - README.md | 5 +++++ contrib/test.sh | 4 ++-- src/blockdata/block.rs | 2 +- src/blockdata/transaction.rs | 2 +- src/blockdata/witness.rs | 2 +- src/lib.rs | 14 +++++++------- 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b7513158a8..3213e694e9 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 434eb4eedc..316e467c73 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 f46a2de5b5..37b8cfd2dd 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 0b639e1264..0fd6155cb8 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 c6d1534be9..271ce69d48 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 d2733c90dc..9b6da04aad 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 12262aa8ce..f32839f556 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};