2023-03-06 22:39:20 +00:00
|
|
|
#!/usr/bin/env bash
|
2023-01-12 20:32:30 +00:00
|
|
|
|
|
|
|
set -ex
|
2022-09-16 01:52:57 +00:00
|
|
|
|
2024-01-24 01:48:07 +00:00
|
|
|
FEATURES="serde std io alloc"
|
2022-09-16 01:52:57 +00:00
|
|
|
|
|
|
|
cargo --version
|
|
|
|
rustc --version
|
|
|
|
|
|
|
|
# Work out if we are using a nightly toolchain.
|
|
|
|
NIGHTLY=false
|
|
|
|
if cargo --version | grep nightly >/dev/null; then
|
|
|
|
NIGHTLY=true
|
|
|
|
fi
|
|
|
|
|
2023-03-06 22:39:20 +00:00
|
|
|
# Pin dependencies as required if we are using MSRV toolchain.
|
|
|
|
if cargo --version | grep "1\.48"; then
|
|
|
|
# 1.0.157 uses syn 2.0 which requires edition 2021
|
2023-07-12 05:50:18 +00:00
|
|
|
cargo update -p serde_json --precise 1.0.99
|
2023-03-06 22:39:20 +00:00
|
|
|
cargo update -p serde --precise 1.0.156
|
|
|
|
fi
|
|
|
|
|
2022-09-16 01:52:57 +00:00
|
|
|
# Make all cargo invocations verbose
|
|
|
|
export CARGO_TERM_VERBOSE=true
|
|
|
|
|
|
|
|
# Defaults / sanity checks
|
2022-12-13 21:24:59 +00:00
|
|
|
cargo build
|
|
|
|
cargo test
|
2022-09-16 01:52:57 +00:00
|
|
|
|
2022-11-30 03:43:56 +00:00
|
|
|
if [ "$DO_LINT" = true ]
|
|
|
|
then
|
2022-09-14 11:09:57 +00:00
|
|
|
cargo clippy --locked --all-features --all-targets -- -D warnings
|
2022-11-30 03:43:56 +00:00
|
|
|
fi
|
|
|
|
|
2022-09-16 01:52:57 +00:00
|
|
|
if [ "$DO_FEATURE_MATRIX" = true ]; then
|
2022-09-14 11:09:57 +00:00
|
|
|
cargo build --locked --no-default-features
|
|
|
|
cargo test --locked --no-default-features
|
2022-09-16 01:52:57 +00:00
|
|
|
|
|
|
|
# All features
|
2022-09-14 11:09:57 +00:00
|
|
|
cargo build --locked --no-default-features --features="$FEATURES"
|
|
|
|
cargo test --locked --no-default-features --features="$FEATURES"
|
2022-09-16 01:52:57 +00:00
|
|
|
# Single features
|
|
|
|
for feature in ${FEATURES}
|
|
|
|
do
|
2022-09-14 11:09:57 +00:00
|
|
|
cargo build --locked --no-default-features --features="$feature"
|
|
|
|
cargo test --locked --no-default-features --features="$feature"
|
2022-09-16 01:52:57 +00:00
|
|
|
# All combos of two features
|
|
|
|
for featuretwo in ${FEATURES}; do
|
2022-09-14 11:09:57 +00:00
|
|
|
cargo build --locked --no-default-features --features="$feature $featuretwo"
|
|
|
|
cargo test --locked --no-default-features --features="$feature $featuretwo"
|
2022-09-16 01:52:57 +00:00
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
# Other combos
|
2022-09-14 11:09:57 +00:00
|
|
|
cargo test --locked --no-default-features --features="std,schemars"
|
2022-09-16 01:52:57 +00:00
|
|
|
fi
|
|
|
|
|
2023-03-06 22:39:20 +00:00
|
|
|
REPO_DIR=$(git rev-parse --show-toplevel)
|
|
|
|
|
2022-09-16 01:52:57 +00:00
|
|
|
if [ "$DO_SCHEMARS_TESTS" = true ]; then
|
2023-03-06 22:39:20 +00:00
|
|
|
pushd "$REPO_DIR/hashes/extended_tests/schemars" > /dev/null
|
|
|
|
cargo test
|
|
|
|
popd > /dev/null
|
2022-09-16 01:52:57 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Build the docs if told to (this only works with the nightly toolchain)
|
2022-12-23 22:50:41 +00:00
|
|
|
if [ "$DO_DOCSRS" = true ]; then
|
|
|
|
RUSTDOCFLAGS="--cfg docsrs -D warnings -D rustdoc::broken-intra-doc-links" cargo +nightly doc --all-features
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Build the docs with a stable toolchain, in unison with the DO_DOCSRS command
|
|
|
|
# above this checks that we feature guarded docs imports correctly.
|
2022-09-16 01:52:57 +00:00
|
|
|
if [ "$DO_DOCS" = true ]; then
|
2022-12-23 22:50:41 +00:00
|
|
|
RUSTDOCFLAGS="-D warnings" cargo +stable doc --all-features
|
2022-09-16 01:52:57 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Webassembly stuff
|
|
|
|
if [ "$DO_WASM" = true ]; then
|
|
|
|
clang --version &&
|
|
|
|
CARGO_TARGET_DIR=wasm cargo install --force wasm-pack &&
|
2023-10-04 00:06:50 +00:00
|
|
|
printf '\n[target.wasm32-unknown-unknown.dev-dependencies]\nwasm-bindgen-test = "0.3"\n' >> Cargo.toml &&
|
2022-09-16 01:52:57 +00:00
|
|
|
printf '\n[lib]\ncrate-type = ["cdylib", "rlib"]\n' >> Cargo.toml &&
|
|
|
|
CC=clang-9 wasm-pack build &&
|
|
|
|
CC=clang-9 wasm-pack test --node;
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Address Sanitizer
|
|
|
|
if [ "$DO_ASAN" = true ]; then
|
|
|
|
cargo clean
|
|
|
|
CC='clang -fsanitize=address -fno-omit-frame-pointer' \
|
|
|
|
RUSTFLAGS='-Zsanitizer=address -Clinker=clang -Cforce-frame-pointers=yes' \
|
|
|
|
ASAN_OPTIONS='detect_leaks=1 detect_invalid_pointer_pairs=1 detect_stack_use_after_return=1' \
|
2022-12-13 21:24:59 +00:00
|
|
|
cargo test --lib --no-default-features --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu
|
2022-09-16 01:52:57 +00:00
|
|
|
cargo clean
|
|
|
|
CC='clang -fsanitize=memory -fno-omit-frame-pointer' \
|
|
|
|
RUSTFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins -Cforce-frame-pointers=yes' \
|
2022-12-13 21:24:59 +00:00
|
|
|
cargo test --lib --no-default-features --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu
|
2022-09-16 01:52:57 +00:00
|
|
|
fi
|
|
|
|
|
2022-09-30 01:56:12 +00:00
|
|
|
# Run formatter if told to.
|
|
|
|
if [ "$DO_FMT" = true ]; then
|
|
|
|
if [ "$NIGHTLY" = false ]; then
|
|
|
|
echo "DO_FMT requires a nightly toolchain (consider using RUSTUP_TOOLCHAIN)"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
rustup component add rustfmt
|
|
|
|
cargo fmt --check
|
|
|
|
fi
|
|
|
|
|
2022-09-16 01:52:57 +00:00
|
|
|
# Bench if told to, only works with non-stable toolchain (nightly, beta).
|
|
|
|
if [ "$DO_BENCH" = true ]
|
|
|
|
then
|
|
|
|
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
|