• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2set -euo pipefail
3IFS=$'\n\t'
4
5# Run a simplified version of the checks done by CI.
6#
7# USAGE:
8#     ./tools/ci.sh [+toolchain]
9#
10# Note: This script requires nightly Rust, rustfmt, clippy, and cargo-expand
11
12bail() {
13    echo >&2 "error: $*"
14    exit 1
15}
16warn() {
17    echo >&2 "warning: $*"
18}
19
20# Decide Rust toolchain. Nightly is used by default.
21toolchain="+nightly"
22if [[ "${1:-}" == "+"* ]]; then
23    toolchain="$1"
24    shift
25fi
26# Make sure toolchain is installed.
27if ! cargo "${toolchain}" -V &>/dev/null; then
28    rustup toolchain install "${toolchain#+}" --no-self-update --profile minimal
29fi
30
31if [[ "${toolchain:-+nightly}" != "+nightly"* ]]; then
32    bail "ci.sh requires nightly Rust"
33fi
34if ! rustup "${toolchain}" component add rustfmt &>/dev/null \
35    || ! cargo expand -V &>/dev/null; then
36    warn "ci.sh requires rustfmt and cargo-expand to run all tests"
37fi
38
39# Run rustfmt.
40if ! rustup "${toolchain}" component add rustfmt &>/dev/null; then
41    warn "component 'rustfmt' is unavailable for toolchain '${toolchain#+}'"
42else
43    (
44        set -x
45        cargo "${toolchain}" fmt --all
46    )
47fi
48
49# Run clippy.
50if ! rustup "${toolchain}" component add clippy &>/dev/null; then
51    warn "component 'clippy' is unavailable for toolchain '${toolchain#+}'"
52else
53    (
54        set -x
55        cargo "${toolchain}" clippy --all --all-features --all-targets -Z unstable-options
56    )
57fi
58
59set -x
60
61# Build documentation.
62cargo "${toolchain}" doc --no-deps --all --all-features
63
64# Run tests.
65cargo "${toolchain}" test --all --all-features
66