55# Define the fuzz directory relative to the project root
66FUZZ_DIR=" fuzz"
77
8- TOOLCHAIN=" nightly"
98FEATURES=" libfuzzer_fuzz"
109
1110# --- Dependencies ---
12- echo " Checking/installing dependencies..."
13- # cargo-llvm-cov implicitly uses/installs necessary LLVM tools
14- rustup +${TOOLCHAIN} component add llvm-tools-preview
15- # Check if cargo-llvm-cov is installed, install if not
16- if ! cargo +${TOOLCHAIN} --list | grep -q " llvm-cov" ; then
17- echo " Installing cargo-llvm-cov..."
18- cargo +${TOOLCHAIN} install cargo-llvm-cov
11+ echo " Checking dependencies..."
12+ # Check if llvm-tools is installed for the toolchain
13+ if ! rustup component list | grep -q " llvm-tools.*(installed)" ; then
14+ echo " Error: Required component 'llvm-tools' is not installed for the default toolchain."
15+ echo " Please install it using: rustup component add llvm-tools"
16+ exit 1
17+ fi
18+
19+ # Check if cargo-llvm-cov is installed
20+ if ! cargo --list | grep -q " llvm-cov" ; then
21+ echo " Error: Required cargo subcommand 'llvm-cov' is not installed for the default toolchain."
22+ echo " Please install it using: cargo install cargo-llvm-cov"
23+ exit 1
1924fi
2025
2126# Clean previous builds and coverage artifacts relative to project root
2227echo " Cleaning previous build and coverage artifacts..."
23- cargo + ${TOOLCHAIN} clean
28+ cargo clean
2429rm -rf target/llvm-cov-target
2530rm -rf target/coverage
2631
2732echo " Running fuzz targets with cargo-llvm-cov to collect coverage..."
2833export RUSTFLAGS=" --cfg=fuzzing --cfg=secp256k1_fuzz --cfg=hashes_fuzz"
2934
3035# Determine host triple dynamically for the --target flag
31- HOST_TRIPLE=$( rustc + ${TOOLCHAIN} --version --verbose | grep host | cut -d' ' -f2)
36+ HOST_TRIPLE=$( rustc --version --verbose | grep host | cut -d' ' -f2)
3237if [ -z " $HOST_TRIPLE " ]; then
3338 echo " Error: Could not determine host triple."
3439 exit 1
@@ -45,7 +50,7 @@ for TARGET_PATH in "$FUZZ_DIR"/src/bin/*_target.rs; do
4550
4651 if [ -d " $TARGET_CORPUS_DIR " ]; then
4752 echo " Running cargo llvm-cov for target: $TARGET_NAME with corpus $TARGET_CORPUS_DIR "
48- if ! CARGO_TARGET_DIR=./target cargo + ${TOOLCHAIN} llvm-cov run --no-report --manifest-path " $FUZZ_DIR /Cargo.toml" --target " $HOST_TRIPLE " --features " $COMBINED_FEATURES " --bin " $TARGET_NAME " -- " $TARGET_CORPUS_DIR " -runs=1; then
53+ if ! CARGO_TARGET_DIR=./target cargo llvm-cov run --no-report --manifest-path " $FUZZ_DIR /Cargo.toml" --target " $HOST_TRIPLE " --features " $COMBINED_FEATURES " --bin " $TARGET_NAME " -- " $TARGET_CORPUS_DIR " -runs=1; then
4954 echo " Warning: Execution of $TARGET_NAME with cargo-llvm-cov finished with non-zero status."
5055 fi
5156 else
0 commit comments