feat(ci): parallelize fuzzing CI and add corpus support #373
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Rust CI | |
| on: | |
| push: | |
| pull_request: | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| msrv-check: | |
| name: Build with MSRV | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Install Rust MSRV | |
| uses: dtolnay/rust-toolchain@master | |
| with: | |
| # Set this to your MSRV as specified in Cargo.toml | |
| toolchain: 1.71.0 | |
| - name: Install Boost library | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libboost-all-dev | |
| - name: Cache dependencies | |
| uses: Swatinem/rust-cache@v2 | |
| - name: Build with MSRV | |
| run: | | |
| # Ensure we're using the right version | |
| rustc --version | |
| # Build the project | |
| cargo build --all-features | |
| - name: Run tests with MSRV | |
| run: cargo test --all-features | |
| build: | |
| name: Build and Test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Install Rust toolchain | |
| uses: actions-rs/toolchain@v1 | |
| with: | |
| profile: minimal | |
| toolchain: stable | |
| override: true | |
| components: rustfmt | |
| - name: Cache dependencies | |
| uses: Swatinem/rust-cache@v2 | |
| - name: Install Boost library | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libboost-all-dev | |
| - name: Build | |
| run: cargo build -vv | |
| - name: Build example binary | |
| run: | | |
| cd examples | |
| cargo build --verbose | |
| - name: Check formatting | |
| run: cargo fmt -- --check | |
| - name: Install llvm-tools for coverage | |
| run: rustup component add llvm-tools-preview | |
| - name: Install cargo-llvm-cov | |
| run: cargo install cargo-llvm-cov --locked --version 0.6.19 | |
| - name: Run tests with coverage | |
| run: cargo llvm-cov --all-features --workspace --html --verbose | |
| - name: Upload coverage report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-report | |
| path: target/llvm-cov/html/ | |
| - name: Install Valgrind | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y valgrind | |
| - name: Run tests with Valgrind | |
| run: | | |
| find target/debug/deps -type f -executable -name "test-*" -not -name "*.so" -not -name "*.d" | xargs -I {} valgrind --leak-check=full --show-leak-kinds=all --errors-for-leak-kinds=definite --suppressions=valgrind.supp --error-exitcode=1 {} | |
| windows-build: | |
| name: Build and Test on Windows | |
| runs-on: windows-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Install Rust toolchain | |
| uses: actions-rs/toolchain@v1 | |
| with: | |
| profile: minimal | |
| toolchain: stable | |
| override: true | |
| components: rustfmt | |
| - name: Cache dependencies | |
| uses: Swatinem/rust-cache@v2 | |
| - name: Install Boost library | |
| run: | | |
| git clone https://github.com/microsoft/vcpkg.git | |
| cd vcpkg | |
| .\bootstrap-vcpkg.bat | |
| .\vcpkg install boost-multi-index:x64-windows-static boost-headers:x64-windows-static | |
| echo "VCPKG_ROOT=$env:GITHUB_WORKSPACE\vcpkg" | Out-File -FilePath $env:GITHUB_ENV -Append | |
| echo "$env:GITHUB_WORKSPACE\vcpkg\installed\x64-windows-static\lib" | Out-File -FilePath $env:GITHUB_PATH -Append | |
| - name: Set environment variables for static linking | |
| run: | | |
| echo "BOOST_ROOT=$env:GITHUB_WORKSPACE\vcpkg\installed\x64-windows-static" | Out-File -FilePath $env:GITHUB_ENV -Append | |
| echo "BOOST_INCLUDEDIR=$env:GITHUB_WORKSPACE\vcpkg\installed\x64-windows-static\include" | Out-File -FilePath $env:GITHUB_ENV -Append | |
| echo "BOOST_LIBRARYDIR=$env:GITHUB_WORKSPACE\vcpkg\installed\x64-windows-static\lib" | Out-File -FilePath $env:GITHUB_ENV -Append | |
| - name: Run tests | |
| run: cargo test -vv | |
| linux-aarch64: | |
| name: Build and Test on Linux ARM64 | |
| runs-on: ubuntu-24.04-arm | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Install Rust toolchain | |
| uses: actions-rs/toolchain@v1 | |
| with: | |
| profile: minimal | |
| toolchain: stable | |
| override: true | |
| components: rustfmt | |
| - name: Cache dependencies | |
| uses: Swatinem/rust-cache@v2 | |
| - name: Install Boost library | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libboost-all-dev | |
| - name: Build and test | |
| run: cargo test -vv | |
| macos-build: | |
| name: Build and Test on macOS | |
| runs-on: macos-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Install Rust toolchain | |
| uses: actions-rs/toolchain@v1 | |
| with: | |
| profile: minimal | |
| toolchain: stable | |
| override: true | |
| components: rustfmt | |
| - name: Cache dependencies | |
| uses: Swatinem/rust-cache@v2 | |
| - name: Install Boost library | |
| run: | | |
| brew install boost | |
| - name: Build and test | |
| run: cargo test -vv | |
| fuzzing: | |
| name: Fuzz ${{ matrix.target.name }} | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false # Continue other fuzz tests even if one fails | |
| matrix: | |
| target: | |
| - name: fuzz_target_block | |
| corpus: block_deserialize | |
| - name: fuzz_target_verify | |
| corpus: "" | |
| - name: fuzz_target_chainman | |
| corpus: "" | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Install Rust toolchain | |
| uses: actions-rs/toolchain@v1 | |
| with: | |
| profile: minimal | |
| toolchain: nightly | |
| override: true | |
| targets: x86_64-unknown-linux-gnu | |
| - name: Install LLVM tools for sanitizers | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y llvm | |
| - name: Cache dependencies | |
| uses: Swatinem/rust-cache@v2 | |
| - name: Install Boost library | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libboost-all-dev | |
| - name: Install cargo-fuzz | |
| run: cargo install cargo-fuzz | |
| - name: Clone fuzzing corpus | |
| if: matrix.target.corpus != '' | |
| run: | | |
| git clone --depth=1 https://github.com/bitcoin-core/qa-assets /tmp/qa-assets | |
| echo "QA_ASSETS_DIR=/tmp/qa-assets" >> $GITHUB_ENV | |
| - name: Set up fuzzing directories | |
| run: | | |
| mkdir -p /tmp/rust_kernel_fuzz | |
| sudo mount -t tmpfs none /tmp/rust_kernel_fuzz || true | |
| - name: Build main crate with Address Sanitizer | |
| env: | |
| RUSTFLAGS: "-Zsanitizer=address" | |
| ASAN_OPTIONS: "detect_leaks=1" | |
| run: cargo build --verbose | |
| - name: Build fuzz target | |
| env: | |
| RUSTFLAGS: "-Zsanitizer=address" | |
| ASAN_OPTIONS: "detect_leaks=1" | |
| run: cargo fuzz build ${{ matrix.target.name }} | |
| - name: Run fuzz target with corpus | |
| if: matrix.target.corpus != '' | |
| env: | |
| RUSTFLAGS: "-Zsanitizer=address" | |
| ASAN_OPTIONS: "detect_leaks=1" | |
| run: | | |
| echo "Running ${{ matrix.target.name }} with corpus ${{ matrix.target.corpus }}" | |
| cargo fuzz run ${{ matrix.target.name }} "$QA_ASSETS_DIR/fuzz_corpora/${{ matrix.target.corpus }}" -- -max_total_time=20 | |
| - name: Run fuzz target without corpus | |
| if: matrix.target.corpus == '' | |
| env: | |
| RUSTFLAGS: "-Zsanitizer=address" | |
| ASAN_OPTIONS: "detect_leaks=1" | |
| run: | | |
| echo "Running ${{ matrix.target.name }} without corpus" | |
| cargo fuzz run ${{ matrix.target.name }} -- -max_total_time=20 | |