Skip to content

Commit 17ffc7b

Browse files
committed
Remove unstable feature
Currently it is not possible to run the test suite with `cargo test --all-features`, this is because we use a feature called `unstable` to enable the unstable `test` crate that is used for benchmarking. There is another way to conditionally enable the test crate and guard the benchmark code. We can use a custom configuration option `bench` and then set it using `RUSTFLAGS='--cfg=bench`.
1 parent 1f7f575 commit 17ffc7b

File tree

6 files changed

+27
-7
lines changed

6 files changed

+27
-7
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ no-std = ["hashbrown", "bitcoin/no-std"]
1717
compiler = []
1818
trace = []
1919

20-
unstable = []
2120
serde = ["actual-serde", "bitcoin/serde"]
2221
rand = ["bitcoin/rand"]
2322
base64 = ["bitcoin/base64"]

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ architectural mismatches. If you have any questions or ideas you want to discuss
5454
please join us in
5555
[##miniscript](https://web.libera.chat/?channels=##miniscript) on Libera.
5656

57+
## Benchmarks
58+
59+
We use a custom Rust compiler configuration conditional to guard the bench mark code. To run the
60+
bench marks use: `RUSTFLAGS='--cfg=bench' cargo +nightly bench`.
61+
5762

5863
## Release Notes
5964

contrib/test.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ FEATURES="compiler serde rand base64"
77
cargo --version
88
rustc --version
99

10+
# Cache the toolchain we are using.
11+
NIGHTLY=false
12+
if cargo --version | grep nightly; then
13+
NIGHTLY=true
14+
fi
15+
1016
# Format if told to
1117
if [ "$DO_FMT" = true ]
1218
then
@@ -82,10 +88,18 @@ then
8288
done
8389
fi
8490

85-
# Bench if told to (this only works with the nightly toolchain)
91+
# Bench if told to, only works with non-stable toolchain (nightly, beta).
8692
if [ "$DO_BENCH" = true ]
8793
then
88-
cargo bench --features="unstable compiler"
94+
if [ "$NIGHTLY" = false ]; then
95+
if [ -n "$RUSTUP_TOOLCHAIN" ]; then
96+
echo "RUSTUP_TOOLCHAIN is set to a non-nightly toolchain but DO_BENCH requires a nightly toolchain"
97+
else
98+
echo "DO_BENCH requires a nightly toolchain"
99+
fi
100+
exit 1
101+
fi
102+
RUSTFLAGS='--cfg=bench' cargo bench
89103
fi
90104

91105
# Build the docs if told to (this only works with the nightly toolchain)

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@
7474
//!
7575
7676
#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
77-
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
77+
// Experimental features we need.
78+
#![cfg_attr(bench, feature(test))]
7879
// Coding conventions
7980
#![deny(unsafe_code)]
8081
#![deny(non_upper_case_globals)]
@@ -107,7 +108,8 @@ extern crate core;
107108

108109
#[cfg(feature = "serde")]
109110
pub use actual_serde as serde;
110-
#[cfg(all(test, feature = "unstable"))]
111+
112+
#[cfg(bench)]
111113
extern crate test;
112114

113115
#[macro_use]

src/policy/compiler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,7 @@ mod tests {
15881588
}
15891589
}
15901590

1591-
#[cfg(all(test, feature = "unstable"))]
1591+
#[cfg(bench)]
15921592
mod benches {
15931593
use std::str::FromStr;
15941594

src/policy/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ mod tests {
541541
}
542542
}
543543

544-
#[cfg(all(test, feature = "compiler", feature = "unstable"))]
544+
#[cfg(bench)]
545545
mod benches {
546546
use core::str::FromStr;
547547

0 commit comments

Comments
 (0)