Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grcov doesn't work with proc macros #494

Open
zbraniecki opened this issue Oct 13, 2020 · 7 comments
Open

grcov doesn't work with proc macros #494

zbraniecki opened this issue Oct 13, 2020 · 7 comments

Comments

@zbraniecki
Copy link

In unicode-org/icu4x#331 we faced an issue where grcov failed because we have a proc macro crate.

It shows as:

error: the linked panic runtime `panic_unwind` is not compiled with this crate's panic strategy `abort`
@marco-c
Copy link
Collaborator

marco-c commented Oct 14, 2020

@zbraniecki I assume you have -Cpanic=abort -Zpanic_abort_tests in RUSTFLAGS?

@zbraniecki
Copy link
Author

I did, and had to remove them to make the grcov work with proc macros.

@dunnock
Copy link

dunnock commented Oct 17, 2020

Faced similar issue and after suggestion rust-lang/rust#78011 following has worked for me:

Extending my workspace's Cargo.toml has helped:

cargo-features = ["named-profiles"]

[profile.coverage]
panic = "abort"
opt-level = 0
overflow-checks = false
incremental = false
codegen-units = 1
inherits = "test"

Then I am able to collect code coverage metrics with a following command:

export RUSTFLAGS="-Zprofile"
cargo test -p $pkg --lib --all-features --profile=coverage -Z unstable-options
# and collect coverage metrics respectively
grcov ./target/coverage/ -s . -t lcov --llvm --branch --ignore-not-existing --ignore "cli*" --ignore "*test*"  --ignore "target/*"  --ignore "*migrations*" --excl-start '#\[cfg\(test\)\]' --excl-stop '^}' -o $coverage_report

Note: we have to comment out above lines in Cargo.toml when compiling on rust-stable.

@gilescope
Copy link
Contributor

We should mention this on the readme as proc-macros are not uncommon!

@marco-c
Copy link
Collaborator

marco-c commented Nov 24, 2020

I think proc-macros are supported by source-based coverage, I've recently added support for it in grcov (version 0.6.0). Short explanation at https://marco-c.github.io/2020/11/24/rust-source-based-code-coverage.html, docs at https://github.com/mozilla/grcov#example-how-to-generate-source-based-coverage-for-a-rust-project, full example at https://github.com/marco-c/rust-code-coverage-sample.

@DanielJoyce
Copy link

Yeah, I know the code is called by the test, grcov flags the macro as having been called, but then the body of the function the macro is used on is listed as not called.

eduidl added a commit to rclrust/rclrust that referenced this issue Aug 31, 2021
Proc-macros and `-Cpanic=abort` is not compatible
(see mozilla/grcov#494)
@MichaelScofield
Copy link

Running into the same problems, too. Had to use -Cpanic=unwind. Is there another walk around?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants