blob: 6c7fa7bcd550970702299db269886b4cacbc5f1d [file] [log] [blame]
Chih-Hung Hsieh127364b2020-10-26 16:54:29 -07001#!/bin/bash
2
3# Check all public crates with minimal version dependencies.
4#
5# Usage:
6# bash scripts/check-minimal-versions.sh
7#
8# Note:
9# - This script modifies Cargo.toml and Cargo.lock while running
10# - This script exits with 1 if there are any unstaged changes
11# - This script requires nightly Rust and cargo-hack
12#
13# Refs: https://github.com/rust-lang/cargo/issues/5657
14
15set -euo pipefail
16
17cd "$(cd "$(dirname "${0}")" && pwd)"/..
18
19if [[ "${1:-none}" == "+"* ]]; then
20 toolchain="${1}"
21elif [[ "${CI:-false}" != "true" ]]; then
22 cargo +nightly -V >/dev/null || exit 1
23 toolchain="+nightly"
24fi
25
26if [[ "${toolchain:-+nightly}" != "+nightly"* ]] || ! cargo hack -V &>/dev/null; then
27 echo "error: check-minimal-versions.sh requires nightly Rust and cargo-hack"
28 exit 1
29fi
30
31# This script modifies Cargo.toml and Cargo.lock, so make sure there are no
32# unstaged changes.
33git diff --exit-code
34# Restore original Cargo.toml and Cargo.lock on exit.
35trap 'git checkout .' EXIT
36
37# Remove dev-dependencies from Cargo.toml to prevent the next `cargo update`
38# from determining minimal versions based on dev-dependencies.
39cargo hack --remove-dev-deps --workspace
40
41# Update Cargo.lock to minimal version dependencies.
42cargo ${toolchain:-} update -Zminimal-versions
43# Run check for all public members of the workspace.
44cargo ${toolchain:-} hack check --workspace --all-features --ignore-private -Zfeatures=all