2022-07-22 01:30:53 +00:00
#!/bin/sh
2020-11-10 23:36:07 +00:00
2022-07-22 01:30:53 +00:00
set -ex
2022-03-16 23:57:30 +00:00
2022-11-17 23:00:23 +00:00
FEATURES = "bitcoin-hashes global-context lowmemory rand recovery serde std alloc bitcoin-hashes-std rand-std"
2020-11-10 23:36:07 +00:00
cargo --version
rustc --version
2022-06-28 04:04:26 +00:00
# Work out if we are using a nightly toolchain.
NIGHTLY = false
if cargo --version | grep nightly; then
NIGHTLY = true
fi
2022-03-18 23:52:14 +00:00
# Test if panic in C code aborts the process (either with a real panic or with SIGILL)
cargo test -- --ignored --exact 'tests::test_panic_raw_ctx_should_terminate_abnormally' 2>& 1 | tee /dev/stderr | grep "SIGILL\\|panicked at '\[libsecp256k1\]"
2020-12-18 12:08:52 +00:00
# Make all cargo invocations verbose
export CARGO_TERM_VERBOSE = true
2020-11-10 23:36:07 +00:00
# Defaults / sanity checks
2020-12-18 12:08:52 +00:00
cargo build --all
cargo test --all
2020-11-10 23:36:07 +00:00
if [ " $DO_FEATURE_MATRIX " = true ] ; then
2020-12-18 12:08:52 +00:00
cargo build --all --no-default-features
2022-02-01 02:43:42 +00:00
cargo test --all --no-default-features
2020-11-10 23:36:07 +00:00
# All features
2020-12-18 12:08:52 +00:00
cargo build --all --no-default-features --features= " $FEATURES "
2022-02-01 02:43:42 +00:00
cargo test --all --no-default-features --features= " $FEATURES "
2020-11-10 23:36:07 +00:00
# Single features
for feature in ${ FEATURES }
do
2020-12-18 12:08:52 +00:00
cargo build --all --no-default-features --features= " $feature "
2022-02-01 02:43:42 +00:00
cargo test --all --no-default-features --features= " $feature "
2020-11-10 23:36:07 +00:00
done
2022-03-02 09:01:12 +00:00
# Features tested with 'std' feature enabled.
for feature in ${ FEATURES }
do
cargo build --all --no-default-features --features= " std, $feature "
cargo test --all --no-default-features --features= " std, $feature "
done
2020-12-23 18:00:34 +00:00
# Other combos
2023-04-26 15:16:26 +00:00
RUSTFLAGS = '--cfg=secp256k1_fuzz' RUSTDOCFLAGS = '--cfg=secp256k1_fuzz' cargo test --all
RUSTFLAGS = '--cfg=secp256k1_fuzz' RUSTDOCFLAGS = '--cfg=secp256k1_fuzz' cargo test --all --features= " $FEATURES "
2020-12-18 12:08:52 +00:00
cargo test --all --features= "rand serde"
2020-11-10 23:36:07 +00:00
2022-06-28 04:04:26 +00:00
if [ " $NIGHTLY " = true ] ; then
2020-12-23 18:00:34 +00:00
cargo test --all --all-features
2023-04-26 15:16:26 +00:00
RUSTFLAGS = '--cfg=secp256k1_fuzz' RUSTDOCFLAGS = '--cfg=secp256k1_fuzz' cargo test --all --all-features
2020-12-23 18:00:34 +00:00
fi
2020-11-10 23:36:07 +00:00
# Examples
2022-11-17 23:00:23 +00:00
cargo run --example sign_verify --features= bitcoin-hashes-std
cargo run --example sign_verify_recovery --features= recovery,bitcoin-hashes-std
cargo run --example generate_keys --features= rand-std
2020-11-10 23:36:07 +00:00
fi
2023-04-18 06:02:50 +00:00
if [ " $DO_LINT " = true ]
then
cargo clippy --all-features --all-targets -- -D warnings
cargo clippy --example sign_verify --features= bitcoin-hashes-std -- -D warnings
cargo clippy --example sign_verify_recovery --features= recovery,bitcoin-hashes-std -- -D warnings
cargo clippy --example generate_keys --features= rand-std -- -D warnings
fi
2022-03-08 21:00:18 +00:00
# Build the docs if told to (this only works with the nightly toolchain)
2023-04-18 06:02:50 +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.
2020-11-10 23:36:07 +00:00
if [ " $DO_DOCS " = true ] ; then
2023-04-18 06:02:50 +00:00
RUSTDOCFLAGS = "-D warnings" cargo +stable doc --all-features
2020-11-10 23:36:07 +00:00
fi
# Webassembly stuff
if [ " $DO_WASM " = true ] ; then
2022-11-02 23:29:23 +00:00
clang --version
2022-03-16 23:57:30 +00:00
CARGO_TARGET_DIR = wasm cargo install --force wasm-pack
printf '\n[lib]\ncrate-type = ["cdylib", "rlib"]\n' >> Cargo.toml
2022-11-02 23:29:23 +00:00
CC = clang wasm-pack build
CC = clang wasm-pack test --node
2020-11-10 23:36:07 +00:00
fi
# Address Sanitizer
if [ " $DO_ASAN " = true ] ; then
2022-03-21 23:12:30 +00:00
clang --version
2020-11-10 23:36:07 +00:00
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-03-16 23:57:30 +00:00
cargo test --lib --all --features= " $FEATURES " -Zbuild-std --target x86_64-unknown-linux-gnu
cargo clean
2023-01-22 22:46:48 +00:00
# The -Cllvm-args=-msan-eager-checks=0 flag was added to overcome this issue:
# https://github.com/rust-bitcoin/rust-secp256k1/pull/573#issuecomment-1399465995
CC = 'clang -fsanitize=memory -fno-omit-frame-pointer' \
RUSTFLAGS = '-Zsanitizer=memory -Zsanitizer-memory-track-origins -Cforce-frame-pointers=yes -Cllvm-args=-msan-eager-checks=0' \
2022-03-16 23:57:30 +00:00
cargo test --lib --all --features= " $FEATURES " -Zbuild-std --target x86_64-unknown-linux-gnu
2020-12-18 12:08:52 +00:00
cargo run --release --manifest-path= ./no_std_test/Cargo.toml | grep -q "Verified Successfully"
2021-05-17 12:37:36 +00:00
cargo run --release --features= alloc --manifest-path= ./no_std_test/Cargo.toml | grep -q "Verified alloc Successfully"
2020-11-10 23:36:07 +00:00
fi
2022-11-21 21:54:24 +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 || exit 1
fi
2022-07-13 04:40:49 +00:00
# Bench if told to, only works with non-stable toolchain (nightly, beta).
if [ " $DO_BENCH " = true ]
then
2022-11-17 23:00:23 +00:00
RUSTFLAGS = '--cfg=bench' cargo bench --features= recovery,rand-std
2020-11-10 23:36:07 +00:00
fi
2022-03-16 23:30:36 +00:00
exit 0