Skip to content

Commit 30acbe0

Browse files
committed
Merge rust-bitcoin/rust-bitcoin#1092: Create configuration conditional "bench"
f3b2120 Create configuration conditional bench (Tobin C. Harding) f60c92c Add informative error message to DO_BENCH (Tobin C. Harding) c6d5a12 Add cargo/rustc sanity calls (Tobin C. Harding) 34d5a31 Put triple ticks on their own line (Tobin C. Harding) Pull request description: 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 { ... } ``` ACKs for top commit: Kixunil: ACK f3b2120 apoelstra: ACK f3b2120 Tree-SHA512: 7ec2a501a30bfe2ce72601077cd675cf5e5ac2f0f93f97fc7e83cb7401606b69ae909b35bfc0ace8bd1ea771ca4fba70e2ad9ac9ba26f2b6e371494cf694c0a8
2 parents b44620b + 62dceff commit 30acbe0

File tree

7 files changed

+38
-14
lines changed

7 files changed

+38
-14
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ edition = "2018"
1515
# Please don't forget to add relevant features to docs.rs below
1616
[features]
1717
default = [ "std", "secp-recovery" ]
18-
unstable = []
1918
rand = ["secp256k1/rand-std"]
2019
serde = ["actual-serde", "bitcoin_hashes/serde", "secp256k1/serde"]
2120
secp-lowmemory = ["secp256k1/lowmemory"]

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,14 @@ Please refer to the [`cargo` documentation](https://doc.rust-lang.org/stable/car
106106
We build docs with the nightly toolchain, you may wish to use the following
107107
shell alias to check your documentation changes build correctly.
108108

109-
```alias build-docs='RUSTDOCFLAGS="--cfg docsrs" cargo +nightly rustdoc --features="$FEATURES" -- -D rustdoc::broken-intra-doc-links'```
109+
```
110+
alias build-docs='RUSTDOCFLAGS="--cfg docsrs" cargo +nightly rustdoc --features="$FEATURES" -- -D rustdoc::broken-intra-doc-links'
111+
```
112+
113+
### Running benchmarks
114+
115+
We use a custom Rust compiler configuration conditional to guard the bench mark code. To run the
116+
bench marks use: `RUSTFLAGS='--cfg=bench' cargo +nightly bench`.
110117

111118
## Pull Requests
112119

contrib/test.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ then
1313
export RUSTFLAGS="-C link-dead-code"
1414
fi
1515

16+
cargo --version
17+
rustc --version
18+
19+
# Work out if we are using a nightly toolchain.
20+
NIGHTLY=false
21+
if cargo --version | grep nightly; then
22+
NIGHTLY=true
23+
fi
1624

1725
echo "********* Testing std *************"
1826
# Test without any features other than std first
@@ -69,10 +77,20 @@ then
6977
)
7078
fi
7179

72-
# Bench if told to
80+
# Bench if told to, only works with non-stable toolchain (nightly, beta).
7381
if [ "$DO_BENCH" = true ]
7482
then
75-
cargo bench --features unstable
83+
if [ "NIGHTLY" = false ]
84+
then
85+
if [ -n "TOOLCHAIN" ]
86+
then
87+
echo "TOOLCHAIN is set to a non-nightly toolchain but DO_BENCH requires a nightly toolchain"
88+
else
89+
echo "DO_BENCH requires a nightly toolchain"
90+
fi
91+
exit 1
92+
fi
93+
RUSTFLAGS='--cfg=bench' cargo bench
7694
fi
7795

7896
# Use as dependency if told to

src/blockdata/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ mod tests {
528528
}
529529
}
530530

531-
#[cfg(all(test, feature = "unstable"))]
531+
#[cfg(bench)]
532532
mod benches {
533533
use super::Block;
534534
use crate::EmptyWrite;

src/blockdata/transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1724,7 +1724,7 @@ mod tests {
17241724
}
17251725
}
17261726

1727-
#[cfg(all(test, feature = "unstable"))]
1727+
#[cfg(bench)]
17281728
mod benches {
17291729
use super::Transaction;
17301730
use crate::EmptyWrite;

src/blockdata/witness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ mod test {
441441
}
442442

443443

444-
#[cfg(all(test, feature = "unstable"))]
444+
#[cfg(bench)]
445445
mod benches {
446446
use test::{Bencher, black_box};
447447
use super::Witness;

src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
//! * `std` - the usual dependency on `std` (default).
2020
//! * `secp-recovery` - enables calculating public key from a signature and message.
2121
//! * `base64` - (dependency), enables encoding of PSBTs and message signatures.
22-
//! * `unstable` - enables unstable features for testing.
2322
//! * `rand` - (dependency), makes it more convenient to generate random values.
2423
//! * `serde` - (dependency), implements `serde`-based serialization and
2524
//! deserialization.
@@ -31,9 +30,8 @@
3130
3231
#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
3332

34-
// Experimental features we need
35-
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
36-
33+
// Experimental features we need.
34+
#![cfg_attr(bench, feature(test))]
3735
#![cfg_attr(docsrs, feature(doc_cfg))]
3836

3937
// Coding conventions
@@ -56,6 +54,8 @@ compile_error!("rust-bitcoin currently only supports architectures with pointers
5654
than 16 bits, let us know if you want 16-bit support. Note that we do
5755
NOT guarantee that we will implement it!");
5856

57+
#[cfg(bench)] extern crate test;
58+
5959
#[cfg(feature = "no-std")]
6060
#[macro_use]
6161
extern crate alloc;
@@ -181,10 +181,10 @@ mod prelude {
181181
pub use std::collections::HashSet;
182182
}
183183

184-
#[cfg(all(test, feature = "unstable"))] use tests::EmptyWrite;
184+
#[cfg(bench)] use bench::EmptyWrite;
185185

186-
#[cfg(all(test, feature = "unstable"))]
187-
mod tests {
186+
#[cfg(bench)]
187+
mod bench {
188188
use core::fmt::Arguments;
189189
use crate::io::{IoSlice, Result, Write};
190190

0 commit comments

Comments
 (0)