Skip to content

Commit a336ecf

Browse files
committed
Merge bitcoindevkit#371: Switch to cargo-llvm-cov for code coverage
527037c ci(coverage): Switch to cargo-llvm-cov for code coverage (copilot-swe-agent[bot]) Pull request description: ### Description Replaces `grcov` with `cargo-llvm-cov` for coverage generation. `grcov` lacks branch coverage support and has other limitations. **Workflow changes:** - Use nightly toolchain with `cargo-llvm-cov` - Set `RUSTFLAGS="--cfg coverage_nightly"` during coverage runs only - Remove `lcov` tools and old coverage environment variables - Enable branch coverage with `--branch` flag - Add `--quiet` flag to reduce output verbosity **Code changes:** - Enable `coverage_attribute` feature via `#[cfg_attr(coverage_nightly, feature(coverage_attribute))]` in `lib.rs` - Exclude test modules from coverage with `#[cfg_attr(coverage_nightly, coverage(off))]` on 13 test modules - Add `coverage_nightly` to `[lints.rust]` in `Cargo.toml` to declare the custom cfg Stable builds are unaffected. Coverage exclusions only activate when the cfg is set. ### Notes to the reviewers The `coverage_nightly` cfg is only set during coverage generation in CI. Regular builds and tests use stable toolchain without this cfg. Branch coverage is now explicitly enabled, providing more detailed coverage metrics than the previous grcov setup. ### Changelog notice - ci: Switch to `cargo-llvm-cov` for code coverage ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>[coverage] Consider using `cargo-llvm-cov`</issue_title> > <issue_description>**Describe the enhancement** > > Switch to using [`llvm-cov`](https://crates.io/crates/cargo-llvm-cov) in `.github/workflows/code_coverage.yml` for generating coverage data. For example see bitcoindevkit/bdk#1986. > > **Impact** > - [ ] Blocking production usage > - [ ] Nice-to-have / UX improvement > - [x] Developer experience / maintainability > > **Additional context** > > - `grcov` has some limitations including lacking support for branch coverage which makes it a less appealing option. > - bitcoindevkit/bdk#1984</issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes bitcoindevkit#366 <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. ACKs for top commit: ValuedMammal: ACK 527037c notmandatory: ACK 527037c luisschwab: ACK 527037c Tree-SHA512: c5dc740c3e5b90b12b92ccff0581f9ca21ae45f3b08b486b58d6f9bdcc54865999b48a1eeef1349a0fd81727bdba18b5de615e60cc9e0e41cdda6d96bc50cc13
2 parents ce8a31b + 527037c commit a336ecf

17 files changed

Lines changed: 33 additions & 19 deletions

File tree

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Code Coverage
22

3-
# Generates code coverage reports using grcov and uploads results to Codecov.
3+
# Generates code coverage reports using cargo-llvm-cov and uploads results to Codecov.
44
# Runs on every push and pull request to track test coverage metrics.
55
# Uploads coverage data to Codecov for tracking and produces an HTML report artifact for download.
66

@@ -14,38 +14,32 @@ jobs:
1414
Coverage:
1515
name: Code Coverage
1616
runs-on: ubuntu-latest
17-
env:
18-
RUSTFLAGS: "-Cinstrument-coverage"
19-
RUSTDOCFLAGS: "-Cinstrument-coverage"
20-
LLVM_PROFILE_FILE: "./target/coverage/%p-%m.profraw"
2117

2218
steps:
2319
- name: Checkout
2420
uses: actions/checkout@v6
2521
with:
2622
persist-credentials: false
27-
- name: Install lcov tools
28-
run: sudo apt-get install lcov -y
29-
# This action automatically reads and applies rust-toolchain.toml
3023
- name: Install Rust toolchain
3124
uses: actions-rust-lang/setup-rust-toolchain@v1
3225
with:
26+
toolchain: nightly
3327
components: llvm-tools-preview
3428
cache: true
35-
- name: Install grcov
36-
run: if [[ ! -e ~/.cargo/bin/grcov ]]; then cargo install grcov; fi
37-
- name: Test
38-
run: cargo test --all-features
39-
- name: Make coverage directory
40-
run: mkdir coverage
41-
- name: Run grcov
42-
run: grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing --keep-only 'src/**' --ignore 'tests/**' --ignore 'examples/**' -o ./coverage/lcov.info
29+
- name: Install cargo-llvm-cov
30+
run: cargo install cargo-llvm-cov
31+
- name: Generate coverage data
32+
run: cargo llvm-cov --all-features --branch --quiet --ignore-filename-regex "test_utils" --lcov --output-path lcov.info
33+
env:
34+
RUSTFLAGS: "--cfg coverage_nightly"
4335
- name: Generate HTML coverage report
44-
run: genhtml -o coverage-report.html --ignore-errors unmapped ./coverage/lcov.info
36+
run: cargo llvm-cov --all-features --branch --quiet --ignore-filename-regex "test_utils" --html
37+
env:
38+
RUSTFLAGS: "--cfg coverage_nightly"
4539
- name: Codecov upload
4640
uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
4741
with:
48-
files: ./coverage/lcov.info
42+
files: ./lcov.info
4943
flags: rust
5044
name: codecov-bdk-wallet
5145
token: ${{ secrets.CODECOV_TOKEN }}
@@ -54,4 +48,4 @@ jobs:
5448
uses: actions/upload-artifact@v6
5549
with:
5650
name: coverage-report
57-
path: coverage-report.html
51+
path: target/llvm-cov/html

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ Cargo.lock
99
*.db
1010
*.sqlite*
1111
examples/test_data
12+
13+
# Coverage reports
14+
lcov.info

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ rust-version = "1.85.0"
1616
all-features = true
1717
rustdoc-args = ["--cfg", "docsrs"]
1818

19+
[lints.rust]
20+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage_nightly)'] }
21+
1922
[dependencies]
2023
bdk_chain = { version = "0.23.1", features = ["miniscript", "serde"], default-features = false }
2124
bitcoin = { version = "0.32.7", features = ["serde", "base64"], default-features = false }

src/descriptor/checksum.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub fn calc_checksum(desc: &str) -> Result<String, DescriptorError> {
3434
}
3535
}
3636

37+
#[cfg_attr(coverage_nightly, coverage(off))]
3738
#[cfg(test)]
3839
mod test {
3940
use super::*;

src/descriptor/dsl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ macro_rules! fragment {
823823
});
824824
}
825825

826+
#[cfg_attr(coverage_nightly, coverage(off))]
826827
#[cfg(test)]
827828
mod test {
828829
use alloc::string::ToString;

src/descriptor/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ impl DescriptorMeta for ExtendedDescriptor {
609609
}
610610
}
611611

612+
#[cfg_attr(coverage_nightly, coverage(off))]
612613
#[cfg(test)]
613614
mod test {
614615
use alloc::string::ToString;

src/descriptor/policy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,7 @@ impl ExtractPolicy for Descriptor<DescriptorPublicKey> {
11731173
}
11741174
}
11751175

1176+
#[cfg_attr(coverage_nightly, coverage(off))]
11761177
#[cfg(test)]
11771178
mod test {
11781179
use super::*;

src/descriptor/template.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ expand_make_bipxx!(legacy, Legacy);
632632
expand_make_bipxx!(segwit_v0, Segwitv0);
633633
expand_make_bipxx!(segwit_v1, Tap);
634634

635+
#[cfg_attr(coverage_nightly, coverage(off))]
635636
#[cfg(test)]
636637
mod test {
637638
// Test existing descriptor templates to make sure they are expanded to the right descriptors.

src/keys/bip39.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ impl<Ctx: ScriptContext> GeneratableKey<Ctx> for Mnemonic {
149149
}
150150
}
151151

152+
#[cfg_attr(coverage_nightly, coverage(off))]
152153
#[cfg(test)]
153154
mod test {
154155
use super::WordCount;

src/keys/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,7 @@ impl fmt::Display for KeyError {
10411041
#[cfg(feature = "std")]
10421042
impl std::error::Error for KeyError {}
10431043

1044+
#[cfg_attr(coverage_nightly, coverage(off))]
10441045
#[cfg(test)]
10451046
mod test {
10461047
use super::*;

0 commit comments

Comments
 (0)