2022-09-07 23:32:08 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -ex
|
|
|
|
|
|
|
|
FEATURES="base64 bitcoinconsensus serde rand secp-recovery"
|
|
|
|
|
|
|
|
if [ "$DO_COV" = true ]
|
|
|
|
then
|
|
|
|
export RUSTFLAGS="-C link-dead-code"
|
|
|
|
fi
|
|
|
|
|
|
|
|
cargo --version
|
|
|
|
rustc --version
|
|
|
|
|
2022-09-30 01:53:09 +00:00
|
|
|
# Some tests require certain toolchain types.
|
2022-09-07 23:32:08 +00:00
|
|
|
NIGHTLY=false
|
2022-09-30 01:53:09 +00:00
|
|
|
STABLE=true
|
2022-09-07 23:32:08 +00:00
|
|
|
if cargo --version | grep nightly; then
|
2022-09-30 01:53:09 +00:00
|
|
|
STABLE=false
|
2022-09-07 23:32:08 +00:00
|
|
|
NIGHTLY=true
|
|
|
|
fi
|
2022-09-30 01:53:09 +00:00
|
|
|
if cargo --version | grep beta; then
|
|
|
|
STABLE=false
|
|
|
|
fi
|
2022-09-07 23:32:08 +00:00
|
|
|
|
2023-02-23 21:26:11 +00:00
|
|
|
# Pin dependencies as required if we are using MSRV toolchain.
|
2023-03-22 02:52:20 +00:00
|
|
|
if cargo --version | grep "1\.48"; then
|
2023-06-20 03:34:38 +00:00
|
|
|
# 1.0.157 uses syn 2.0 which requires edition 2021
|
2023-03-18 22:10:18 +00:00
|
|
|
cargo update -p serde --precise 1.0.156
|
2023-02-23 21:26:11 +00:00
|
|
|
fi
|
|
|
|
|
2022-09-07 23:32:08 +00:00
|
|
|
if [ "$DO_LINT" = true ]
|
|
|
|
then
|
2022-09-14 11:09:57 +00:00
|
|
|
cargo clippy --locked --all-features --all-targets -- -D warnings
|
|
|
|
cargo clippy --locked --example bip32 -- -D warnings
|
|
|
|
cargo clippy --locked --example handshake --features=rand-std -- -D warnings
|
|
|
|
cargo clippy --locked --example ecdsa-psbt --features=bitcoinconsensus -- -D warnings
|
|
|
|
cargo clippy --locked --example taproot-psbt --features=rand-std,bitcoinconsensus -- -D warnings
|
|
|
|
|
|
|
|
# We should not have any duplicate dependencies. This catches mistakes made upgrading dependencies
|
|
|
|
# in one crate and not in another (e.g. upgrade bitcoin_hashes in bitcoin but not in secp).
|
|
|
|
duplicate_dependencies=$(
|
|
|
|
# Only show the actual duplicated deps, not their reverse tree, then
|
|
|
|
# whitelist the 'syn' crate which is duplicated but it's not our fault.
|
|
|
|
cargo tree --target=all --all-features --duplicates \
|
|
|
|
| grep '^[0-9A-Za-z]' \
|
|
|
|
| grep -v 'syn' \
|
|
|
|
| wc -l
|
|
|
|
)
|
|
|
|
if [ "$duplicate_dependencies" -ne 0 ]; then
|
|
|
|
echo "Dependency tree is broken, contains duplicates"
|
|
|
|
cargo tree --target=all --all-features --duplicates
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-09-07 23:32:08 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "********* Testing std *************"
|
|
|
|
# Test without any features other than std first
|
2022-09-14 11:09:57 +00:00
|
|
|
cargo test --locked --verbose --no-default-features --features="std"
|
2022-09-07 23:32:08 +00:00
|
|
|
|
|
|
|
echo "********* Testing default *************"
|
|
|
|
# Then test with the default features
|
|
|
|
cargo test --verbose
|
|
|
|
|
|
|
|
if [ "$DO_NO_STD" = true ]
|
|
|
|
then
|
|
|
|
echo "********* Testing no-std build *************"
|
|
|
|
# Build no_std, to make sure that cfg(test) doesn't hide any issues
|
2022-09-14 11:09:57 +00:00
|
|
|
cargo build --locked --verbose --features="no-std" --no-default-features
|
2022-09-07 23:32:08 +00:00
|
|
|
|
|
|
|
# Build std + no_std, to make sure they are not incompatible
|
2022-09-14 11:09:57 +00:00
|
|
|
cargo build --locked --verbose --features="no-std"
|
2022-09-07 23:32:08 +00:00
|
|
|
|
|
|
|
# Test no_std
|
2022-09-14 11:09:57 +00:00
|
|
|
cargo test --locked --verbose --features="no-std" --no-default-features
|
2022-09-07 23:32:08 +00:00
|
|
|
|
|
|
|
# Build all features
|
2022-09-14 11:09:57 +00:00
|
|
|
cargo build --locked --verbose --features="no-std $FEATURES" --no-default-features
|
2022-09-07 23:32:08 +00:00
|
|
|
|
|
|
|
# Build specific features
|
|
|
|
for feature in ${FEATURES}
|
|
|
|
do
|
2022-09-14 11:09:57 +00:00
|
|
|
cargo build --locked --verbose --features="no-std $feature" --no-default-features
|
2022-09-07 23:32:08 +00:00
|
|
|
done
|
|
|
|
|
2022-09-14 11:09:57 +00:00
|
|
|
cargo run --locked --example bip32 7934c09359b234e076b9fa5a1abfd38e3dc2a9939745b7cc3c22a48d831d14bd
|
|
|
|
cargo run --locked --no-default-features --features no-std --example bip32 7934c09359b234e076b9fa5a1abfd38e3dc2a9939745b7cc3c22a48d831d14bd
|
2022-09-07 23:32:08 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Test each feature
|
|
|
|
for feature in ${FEATURES}
|
|
|
|
do
|
|
|
|
echo "********* Testing $feature *************"
|
2022-09-14 11:09:57 +00:00
|
|
|
cargo test --locked --verbose --features="$feature"
|
2022-09-07 23:32:08 +00:00
|
|
|
done
|
|
|
|
|
2022-09-14 11:09:57 +00:00
|
|
|
cargo run --locked --example ecdsa-psbt --features=bitcoinconsensus
|
|
|
|
cargo run --locked --example taproot-psbt --features=rand-std,bitcoinconsensus
|
2022-09-07 23:32:08 +00:00
|
|
|
|
|
|
|
# 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-07 23:32:08 +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-07 23:32:08 +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-07 23:32:08 +00:00
|
|
|
# Bench if told to, only works with non-stable toolchain (nightly, beta).
|
|
|
|
if [ "$DO_BENCH" = true ]
|
|
|
|
then
|
2022-09-30 01:53:09 +00:00
|
|
|
if [ "$STABLE" = true ]; then
|
|
|
|
if [ -n "$RUSTUP_TOOLCHAIN" ]; then
|
|
|
|
echo "RUSTUP_TOOLCHAIN is set to a stable toolchain but DO_BENCH requires a non-stable (beta, nightly) toolchain"
|
2022-09-07 23:32:08 +00:00
|
|
|
else
|
2022-09-30 01:53:09 +00:00
|
|
|
echo "DO_BENCH requires a non-stable (beta, nightly) toolchain"
|
2022-09-07 23:32:08 +00:00
|
|
|
fi
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
RUSTFLAGS='--cfg=bench' cargo bench
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Use as dependency if told to
|
|
|
|
if [ "$AS_DEPENDENCY" = true ]
|
|
|
|
then
|
|
|
|
cargo new dep_test 2> /dev/null # Mute warning about workspace, fixed below.
|
|
|
|
cd dep_test
|
|
|
|
echo 'bitcoin = { path = "..", features = ["serde"] }\n\n' >> Cargo.toml
|
|
|
|
# Adding an empty workspace section excludes this crate from the rust-bitcoin workspace.
|
|
|
|
echo '[workspace]\n\n' >> Cargo.toml
|
|
|
|
|
|
|
|
cargo test --verbose
|
|
|
|
fi
|