diff --git a/ci/run_task.sh b/ci/run_task.sh index c05c157..f7b169e 100755 --- a/ci/run_task.sh +++ b/ci/run_task.sh @@ -30,7 +30,7 @@ usage() { cat < /dev/null + need_toolchain "$toolchain" do_test do_feature_matrix @@ -243,14 +264,14 @@ loop_features() { # Lint the workspace. do_lint_workspace() { - need_nightly + need_toolchain "nightly" $cargo clippy --workspace --all-targets --all-features --keep-going -- -D warnings $cargo clippy --workspace --all-targets --keep-going -- -D warnings } # Run extra crate specific lints, e.g. clippy with no-default-features. do_lint_crates() { - need_nightly + need_toolchain "nightly" for crate in $CRATES; do pushd "$REPO_DIR/$crate" > /dev/null if [ -e ./contrib/extra_lints.sh ]; then @@ -307,7 +328,7 @@ do_dup_deps() { # Build the docs with a nightly toolchain, in unison with the function # below this checks that we feature guarded docs imports correctly. build_docs_with_nightly_toolchain() { - need_nightly + need_toolchain "nightly" # -j1 is because docs build fails if multiple versions of `bitcoin_hashes` are present in dep tree. RUSTDOCFLAGS="--cfg docsrs -D warnings -D rustdoc::broken-intra-doc-links" $cargo doc --all-features -j1 } @@ -315,12 +336,14 @@ build_docs_with_nightly_toolchain() { # Build the docs with a stable toolchain, in unison with the function # above this checks that we feature guarded docs imports correctly. build_docs_with_stable_toolchain() { + need_toolchain "stable" local cargo="cargo +stable --locked" # Can't use global because of `+stable`. RUSTDOCFLAGS="-D warnings" $cargo doc --all-features -j1 } # Bench only works with a non-stable toolchain (nightly, beta). do_bench() { + need_toolchain "nightly" verbose_say "Running bench tests for: $CRATES" for crate in $CRATES; do @@ -367,11 +390,44 @@ need_cmd() { fi } -need_nightly() { - cargo_ver=$(cargo --version) - if echo "$cargo_ver" | grep -q -v nightly; then - err "Need a nightly compiler; have $(cargo --version)" - fi +# Check that we have the required toolchain. +need_toolchain() { + local required_toolchain="$1" + local current_toolchain + current_toolchain=$(rustc --version) + + case "$required_toolchain" in + nightly) + if ! echo "$current_toolchain" | grep -q nightly; then + err "Need a nightly compiler; have $current_toolchain" + fi + ;; + stable) + if echo "$current_toolchain" | grep -q nightly || echo "$current_toolchain" | grep -q beta; then + err "Need a stable compiler; have $current_toolchain" + fi + ;; + msrv) + # This check must be run in a crate directory + # since it is possible for crates in a workspace to have different MSRVs. + local manifest_path + manifest_path="$(pwd)/Cargo.toml" + local msrv_version + msrv_version=$(cargo metadata --format-version 1 --no-deps | jq -r ".packages[] | select(.manifest_path == \"$manifest_path\") | .rust_version // empty") + if [ -z "$msrv_version" ]; then + err "No MSRV specified in $manifest_path or not in a crate directory" + fi + + local current_version + current_version=$(echo "$current_toolchain" | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' | head -1) + if [ "$current_version" != "$msrv_version" ]; then + err "Need Rust $msrv_version for MSRV testing in $manifest_path; have $current_version" + fi + ;; + *) + err "Unknown toolchain requirement: $required_toolchain" + ;; + esac } # @@ -379,4 +435,3 @@ need_nightly() { # main "$@" exit 0 -