Closed ecton closed 3 years ago
Same issue here. Solved it by not using the source-based approach from the readme (export RUSTFLAGS="-Zinstrument-coverage"
) but instead the second one:
export CARGO_INCREMENTAL=0
export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
export RUSTDOCFLAGS="-Cpanic=abort"
cargo test
grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing -o ./target/debug/coverage/
Thank you for the info! Unfortunately, I find the non-llvm based methods produce unreliable results on my codebases, so I'm hoping this can be fixed. I know I can also work around it by switching away from grcov to generating an llvm-cov report, but I prefer the output of grcov.
Do you use LLVM_PROFILE_FILE? I just tried it as recommended in the readme and it fixed the issue as well for the source-based approach.
rustup component add llvm-tools-preview
cargo install grcov
RUSTFLAGS='-Zinstrument-coverage' LLVM_PROFILE_FILE='coverage-%p-%m.profraw' cargo test
"$CARGO_HOME/.cargo/bin/grcov" . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing -o coverage
Setting RUSTUP_TOOLCHAIN
to nightly
before executing grcov
will also solve the issue 🙂
You may need the env var RUSTUP_TOOLCHAIN=nightly
, if that's not your default.
Otherwise, an older copy of the LLVM tools will be used, which don't support the version of rustc
you're compiling with (it can only work by accident due to LLVM remaining unchanged between the two versions).
(Oops, @slurps-mad-rips was faster than me)
Setting
RUSTUP_TOOLCHAIN
tonightly
before executinggrcov
will also solve the issue slightly_smiling_face
That was it, thank you so much. I had tracked my suspicion down to cargo-bintools but I couldn't figure out how to get grcov to pass the toolchain through.
Maybe we should add this as a suggestion to the README.
@marco-c I was looking for a place to try to add something, but the README does have a note that I overlooked.
My issue stemmed from me manually executing cargo +nightly
rather than setting the rustup default toolchain like the examples do. Until recently, executing grcov
without RUSTUP_TOOLCHAIN
worked (somehow, no idea why). In my mind, I assumed that since grcov was being downloaded pre-built on my CI servers, that the only thing that truly mattered was generating the coverage data, which needs nightly.
But, now that it seems like it can't work in that configuration anymore, I'm not sure that this is as important to point out. In theory, it only might affect a few other people like me who weren't just setting rustup to nightly for the CI run.
worked (somehow, no idea why)
Like I said, it's a coincidence: the LLVM used by two different Rust versions happened to be identical (and/or had no changes in the profraw/profdata format).
When running locally or on CI, I receive repeated error messages for each of my profraw files:
At the end, grcov bails:
This happened between two CI runs, one was on nightly 2021-08-20 and the other was on nightly 2021-08-21. I can reproduce the issue locally, but all of my attempts to force using the old nightly version still yield the same error message. It is happening across all of my projects.
Has anyone else run into this?
Edit: This is tested against the released version of grcov, 0.8.2.