From 066c4cd160f6d4c70409b299a173f31f93728fae Mon Sep 17 00:00:00 2001 From: nymius <155548262+nymius@users.noreply.github.com> Date: Wed, 2 Jul 2025 11:10:20 -0300 Subject: [PATCH] ci: replace grcov by cargo-llvm-cov --- .github/workflows/code_coverage.yml | 17 +++++------------ Cargo.toml | 3 +++ crates/bitcoind_rpc/src/lib.rs | 2 ++ crates/chain/src/chain_data.rs | 1 + crates/chain/src/lib.rs | 1 + crates/chain/src/rusqlite_impl.rs | 1 + crates/chain/src/spk_iter.rs | 1 + crates/electrum/src/bdk_electrum_client.rs | 1 + crates/electrum/src/lib.rs | 2 +- crates/esplora/src/async_ext.rs | 1 + crates/esplora/src/blocking_ext.rs | 1 + crates/esplora/src/lib.rs | 1 + crates/file_store/src/lib.rs | 1 + crates/file_store/src/store.rs | 1 + crates/testenv/Cargo.toml | 2 +- crates/testenv/src/lib.rs | 3 +++ 16 files changed, 25 insertions(+), 14 deletions(-) diff --git a/.github/workflows/code_coverage.yml b/.github/workflows/code_coverage.yml index 618e5dc0..d6d8e9ac 100644 --- a/.github/workflows/code_coverage.yml +++ b/.github/workflows/code_coverage.yml @@ -8,11 +8,6 @@ jobs: Codecov: name: Code Coverage runs-on: ubuntu-latest - env: - RUSTFLAGS: "-Cinstrument-coverage" - RUSTDOCFLAGS: "-Cinstrument-coverage" - LLVM_PROFILE_FILE: "./target/coverage/%p-%m.profraw" - steps: - name: Checkout uses: actions/checkout@v4 @@ -23,20 +18,18 @@ jobs: - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: - toolchain: stable + toolchain: nightly override: true profile: minimal components: llvm-tools-preview - name: Rust Cache uses: Swatinem/rust-cache@v2.7.8 - - name: Install grcov - run: if [[ ! -e ~/.cargo/bin/grcov ]]; then cargo install grcov; fi - - name: Test - run: cargo test --all-features + - name: Install cargo-llvm-cov + run: if [[ ! -e ~/.cargo/bin/cargo-llvm-cov ]]; then cargo install cargo-llvm-cov; fi - name: Make coverage directory run: mkdir coverage - - name: Run grcov - run: grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing --keep-only '**/crates/**' --ignore '**/tests/**' --ignore '**/examples/**' -o ./coverage/lcov.info + - name: Test and report coverage + run: cargo +nightly llvm-cov -q --doctests --branch --all --ignore-filename-regex "(example*|crates/testenv/*)" --all-features --lcov --output-path ./coverage/lcov.info - name: Generate HTML coverage report run: genhtml -o coverage-report.html --ignore-errors unmapped ./coverage/lcov.info - name: Coveralls upload diff --git a/Cargo.toml b/Cargo.toml index 0a62ba43..d505c1a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,3 +20,6 @@ authors = ["Bitcoin Dev Kit Developers"] [workspace.lints.clippy] print_stdout = "deny" print_stderr = "deny" + +[workspace.lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage,coverage_nightly)'] } diff --git a/crates/bitcoind_rpc/src/lib.rs b/crates/bitcoind_rpc/src/lib.rs index 250ff430..8ab3a448 100644 --- a/crates/bitcoind_rpc/src/lib.rs +++ b/crates/bitcoind_rpc/src/lib.rs @@ -7,6 +7,7 @@ //! To only get block updates (exclude mempool transactions), the caller can use //! [`Emitter::next_block`] until it returns `Ok(None)` (which means the chain tip is reached). A //! separate method, [`Emitter::mempool`] can be used to emit the whole mempool. +#![cfg_attr(coverage_nightly, feature(coverage_attribute))] #![warn(missing_docs)] use bdk_core::{BlockId, CheckPoint}; @@ -444,6 +445,7 @@ impl BitcoindRpcErrorExt for bitcoincore_rpc::Error { } #[cfg(test)] +#[cfg_attr(coverage_nightly, coverage(off))] mod test { use crate::{bitcoincore_rpc::RpcApi, Emitter, NO_EXPECTED_MEMPOOL_TXIDS}; use bdk_chain::local_chain::LocalChain; diff --git a/crates/chain/src/chain_data.rs b/crates/chain/src/chain_data.rs index ea088934..b641f15e 100644 --- a/crates/chain/src/chain_data.rs +++ b/crates/chain/src/chain_data.rs @@ -164,6 +164,7 @@ impl FullTxOut { } #[cfg(test)] +#[cfg_attr(coverage_nightly, coverage(off))] mod test { use bdk_core::ConfirmationBlockTime; diff --git a/crates/chain/src/lib.rs b/crates/chain/src/lib.rs index 21ead159..0cb5b48d 100644 --- a/crates/chain/src/lib.rs +++ b/crates/chain/src/lib.rs @@ -25,6 +25,7 @@ )] #![no_std] #![warn(missing_docs)] +#![cfg_attr(coverage_nightly, feature(coverage_attribute))] pub use bitcoin; mod balance; diff --git a/crates/chain/src/rusqlite_impl.rs b/crates/chain/src/rusqlite_impl.rs index 38f76b12..7e9e2f6f 100644 --- a/crates/chain/src/rusqlite_impl.rs +++ b/crates/chain/src/rusqlite_impl.rs @@ -660,6 +660,7 @@ impl keychain_txout::ChangeSet { } #[cfg(test)] +#[cfg_attr(coverage_nightly, coverage(off))] mod test { use super::*; diff --git a/crates/chain/src/spk_iter.rs b/crates/chain/src/spk_iter.rs index 64f38c6d..2353807a 100644 --- a/crates/chain/src/spk_iter.rs +++ b/crates/chain/src/spk_iter.rs @@ -134,6 +134,7 @@ where } #[cfg(test)] +#[cfg_attr(coverage_nightly, coverage(off))] mod test { use crate::{ bitcoin::secp256k1::Secp256k1, diff --git a/crates/electrum/src/bdk_electrum_client.rs b/crates/electrum/src/bdk_electrum_client.rs index b0b30ea6..8358cae8 100644 --- a/crates/electrum/src/bdk_electrum_client.rs +++ b/crates/electrum/src/bdk_electrum_client.rs @@ -685,6 +685,7 @@ fn chain_update( } #[cfg(test)] +#[cfg_attr(coverage_nightly, coverage(off))] mod test { use crate::{bdk_electrum_client::TxUpdate, BdkElectrumClient}; use bdk_chain::bitcoin::{OutPoint, Transaction, TxIn}; diff --git a/crates/electrum/src/lib.rs b/crates/electrum/src/lib.rs index d791f962..9c1d9f45 100644 --- a/crates/electrum/src/lib.rs +++ b/crates/electrum/src/lib.rs @@ -16,7 +16,7 @@ //! [`example_electrum`]: https://github.com/bitcoindevkit/bdk/tree/master/examples/example_electrum //! [`SyncResponse`]: bdk_core::spk_client::SyncResponse //! [`FullScanResponse`]: bdk_core::spk_client::FullScanResponse - +#![cfg_attr(coverage_nightly, feature(coverage_attribute))] #![warn(missing_docs)] mod bdk_electrum_client; diff --git a/crates/esplora/src/async_ext.rs b/crates/esplora/src/async_ext.rs index dc82063b..c0e55ab5 100644 --- a/crates/esplora/src/async_ext.rs +++ b/crates/esplora/src/async_ext.rs @@ -550,6 +550,7 @@ where } #[cfg(test)] +#[cfg_attr(coverage_nightly, coverage(off))] mod test { use std::{collections::BTreeSet, time::Duration}; diff --git a/crates/esplora/src/blocking_ext.rs b/crates/esplora/src/blocking_ext.rs index 60588376..5a52b7a0 100644 --- a/crates/esplora/src/blocking_ext.rs +++ b/crates/esplora/src/blocking_ext.rs @@ -509,6 +509,7 @@ fn fetch_txs_with_outpoints>( } #[cfg(test)] +#[cfg_attr(coverage_nightly, coverage(off))] mod test { use crate::blocking_ext::{chain_update, fetch_latest_blocks}; use bdk_chain::bitcoin; diff --git a/crates/esplora/src/lib.rs b/crates/esplora/src/lib.rs index a88c266a..60b4f1eb 100644 --- a/crates/esplora/src/lib.rs +++ b/crates/esplora/src/lib.rs @@ -19,6 +19,7 @@ //! Just like how [`EsploraExt`] extends the functionality of an //! [`esplora_client::BlockingClient`], [`EsploraAsyncExt`] is the async version which extends //! [`esplora_client::AsyncClient`]. +#![cfg_attr(coverage_nightly, feature(coverage_attribute))] use bdk_core::bitcoin::{Amount, OutPoint, TxOut, Txid}; use bdk_core::{BlockId, ConfirmationBlockTime, TxUpdate}; diff --git a/crates/file_store/src/lib.rs b/crates/file_store/src/lib.rs index 8b76473d..d7dd35bf 100644 --- a/crates/file_store/src/lib.rs +++ b/crates/file_store/src/lib.rs @@ -1,4 +1,5 @@ #![doc = include_str!("../README.md")] +#![cfg_attr(coverage_nightly, feature(coverage_attribute))] mod entry_iter; mod store; use std::io; diff --git a/crates/file_store/src/store.rs b/crates/file_store/src/store.rs index da1fda0b..1bea6c83 100644 --- a/crates/file_store/src/store.rs +++ b/crates/file_store/src/store.rs @@ -281,6 +281,7 @@ impl std::fmt::Display for StoreErrorWithDump { impl std::error::Error for StoreErrorWithDump {} #[cfg(test)] +#[cfg_attr(coverage_nightly, coverage(off))] mod test { use super::*; diff --git a/crates/testenv/Cargo.toml b/crates/testenv/Cargo.toml index ad544e72..8c02bf64 100644 --- a/crates/testenv/Cargo.toml +++ b/crates/testenv/Cargo.toml @@ -29,4 +29,4 @@ std = ["bdk_chain/std"] serde = ["bdk_chain/serde"] [package.metadata.docs.rs] -no-default-features = true \ No newline at end of file +no-default-features = true diff --git a/crates/testenv/src/lib.rs b/crates/testenv/src/lib.rs index 2c0f15f6..9faf43bf 100644 --- a/crates/testenv/src/lib.rs +++ b/crates/testenv/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(coverage_nightly, feature(coverage_attribute))] + pub mod utils; use bdk_chain::{ @@ -311,6 +313,7 @@ impl TestEnv { } #[cfg(test)] +#[cfg_attr(coverage_nightly, coverage(off))] mod test { use crate::TestEnv; use core::time::Duration; -- 2.49.0