Skip to content

Commit

Permalink
Remove unstable feature
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
tcharding committed Jul 13, 2023
1 parent 1f7f575 commit 17ffc7b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ no-std = ["hashbrown", "bitcoin/no-std"]
compiler = []
trace = []

unstable = []
serde = ["actual-serde", "bitcoin/serde"]
rand = ["bitcoin/rand"]
base64 = ["bitcoin/base64"]
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ architectural mismatches. If you have any questions or ideas you want to discuss
please join us in
[##miniscript](https://web.libera.chat/?channels=##miniscript) on Libera.

## 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`.


## Release Notes

Expand Down
18 changes: 16 additions & 2 deletions contrib/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ FEATURES="compiler serde rand base64"
cargo --version
rustc --version

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

# Format if told to
if [ "$DO_FMT" = true ]
then
Expand Down Expand Up @@ -82,10 +88,18 @@ then
done
fi

# Bench if told to (this only works with the nightly toolchain)
# Bench if told to, only works with non-stable toolchain (nightly, beta).
if [ "$DO_BENCH" = true ]
then
cargo bench --features="unstable compiler"
if [ "$NIGHTLY" = false ]; then
if [ -n "$RUSTUP_TOOLCHAIN" ]; then
echo "RUSTUP_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
RUSTFLAGS='--cfg=bench' cargo bench
fi

# Build the docs if told to (this only works with the nightly toolchain)
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
//!

#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
// Experimental features we need.
#![cfg_attr(bench, feature(test))]
// Coding conventions
#![deny(unsafe_code)]
#![deny(non_upper_case_globals)]
Expand Down Expand Up @@ -107,7 +108,8 @@ extern crate core;

#[cfg(feature = "serde")]
pub use actual_serde as serde;
#[cfg(all(test, feature = "unstable"))]

#[cfg(bench)]
extern crate test;

#[macro_use]
Expand Down
2 changes: 1 addition & 1 deletion src/policy/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,7 @@ mod tests {
}
}

#[cfg(all(test, feature = "unstable"))]
#[cfg(bench)]
mod benches {
use std::str::FromStr;

Expand Down
2 changes: 1 addition & 1 deletion src/policy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ mod tests {
}
}

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

Expand Down

0 comments on commit 17ffc7b

Please sign in to comment.