@@ -86,34 +86,41 @@ main() {
8686
8787 case $task in
8888 stable)
89+ need_toolchain " stable"
8990 # Test, run examples, do feature matrix.
9091 # crate/contrib/test_vars.sh is sourced in this function.
9192 build_and_test
9293 ;;
9394
9495 nightly)
96+ need_toolchain " nightly"
9597 build_and_test
9698 ;;
9799
98100 msrv)
101+ need_toolchain " msrv"
99102 build_and_test
100103 ;;
101104
102105 lint)
106+ need_toolchain " nightly"
103107 do_lint_workspace
104108 do_lint_crates
105109 do_dup_deps
106110 ;;
107111
108112 docs)
113+ need_toolchain " stable"
109114 build_docs_with_stable_toolchain
110115 ;;
111116
112117 docsrs)
118+ need_toolchain " nightly"
113119 build_docs_with_nightly_toolchain
114120 ;;
115121
116122 bench)
123+ need_toolchain " nightly"
117124 do_bench
118125 ;;
119126
@@ -243,14 +250,12 @@ loop_features() {
243250
244251# Lint the workspace.
245252do_lint_workspace () {
246- need_nightly
247253 $cargo clippy --workspace --all-targets --all-features --keep-going -- -D warnings
248254 $cargo clippy --workspace --all-targets --keep-going -- -D warnings
249255}
250256
251257# Run extra crate specific lints, e.g. clippy with no-default-features.
252258do_lint_crates () {
253- need_nightly
254259 for crate in $CRATES ; do
255260 pushd " $REPO_DIR /$crate " > /dev/null
256261 if [ -e ./contrib/extra_lints.sh ]; then
@@ -307,7 +312,6 @@ do_dup_deps() {
307312# Build the docs with a nightly toolchain, in unison with the function
308313# below this checks that we feature guarded docs imports correctly.
309314build_docs_with_nightly_toolchain () {
310- need_nightly
311315 # -j1 is because docs build fails if multiple versions of `bitcoin_hashes` are present in dep tree.
312316 RUSTDOCFLAGS=" --cfg docsrs -D warnings -D rustdoc::broken-intra-doc-links" $cargo doc --all-features -j1
313317}
@@ -367,11 +371,41 @@ need_cmd() {
367371 fi
368372}
369373
370- need_nightly () {
371- cargo_ver=$( cargo --version)
372- if echo " $cargo_ver " | grep -q -v nightly; then
373- err " Need a nightly compiler; have $( cargo --version) "
374- fi
374+ # Check that we have the required toolchain.
375+ need_toolchain () {
376+ local required_toolchain=" $1 "
377+ local current_toolchain
378+ current_toolchain=$( rustc --version)
379+
380+ case " $required_toolchain " in
381+ nightly)
382+ if ! echo " $current_toolchain " | grep -q nightly; then
383+ err " Need a nightly compiler; have $current_toolchain "
384+ fi
385+ ;;
386+ stable)
387+ if echo " $current_toolchain " | grep -q nightly || echo " $current_toolchain " | grep -q beta; then
388+ err " Need a stable compiler; have $current_toolchain "
389+ fi
390+ ;;
391+ msrv)
392+ # Get MSRV from cargo metadata, assume a workspace has a consistent MSRV for all crates and just grab the first one.
393+ local msrv_version
394+ msrv_version=$( cargo metadata --format-version 1 --no-deps | jq -r ' .packages[] | .rust_version // empty' | grep -v ' ^$' | head -1)
395+ if [ -z " $msrv_version " ]; then
396+ err " No MSRV specified in Cargo.toml; cannot validate MSRV toolchain"
397+ fi
398+
399+ local current_version
400+ current_version=$( echo " $current_toolchain " | grep -o ' [0-9]\+\.[0-9]\+\.[0-9]\+' | head -1)
401+ if [ " $current_version " != " $msrv_version " ]; then
402+ err " Need Rust $msrv_version for MSRV testing; have $current_version "
403+ fi
404+ ;;
405+ * )
406+ err " Unknown toolchain requirement: $required_toolchain "
407+ ;;
408+ esac
375409}
376410
377411#
0 commit comments