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

Code coverage support #690

Open
sgammon opened this issue Apr 17, 2021 · 15 comments
Open

Code coverage support #690

sgammon opened this issue Apr 17, 2021 · 15 comments

Comments

@sgammon
Copy link

sgammon commented Apr 17, 2021

Hey authors of rules_rust,

Has there been any consideration yet regarding source coverage with rules_rust? Using projects like cargo-cov, or cargo-tarpaulin, it looks pretty easy from the outside but perhaps not from within Bazel.

IIRC, instrumented_files= would need to be provided for Rust targets, but that part is relatively easy if there is already a tool that can produce lcov-compatible outputs.

@sgammon
Copy link
Author

sgammon commented Apr 17, 2021

forget i said anything about crates: https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/source-based-code-coverage.html

i've got a sample working locally outside of Bazel, which uses -Zinstrument-coverage/grcov/lcov to generate coverage data and merge with our canonical LCOV report, which already existed. it would be absolutely amazing if this was rolled into rules_rust, though.

i'm happy to contribute if lib maintainers can help me with a direction?

@UebelAndre
Copy link
Collaborator

UebelAndre commented Apr 19, 2021

Hey, I'm not super familiar with how coverage works but do think it should be something the rules support.

I'm wondering if other maintainers might be able to shine some light on this?

@hlopko @dfreese pinging you two because you seem to be pretty knowledgeable about some subtle details of Bazel and rustc. Hoping you'll have some thoughts 😄

@sluongng
Copy link

Good references should be from rules_go:

Generally Bazel's coverage is not yet complete.
If your code coverage tooling does not follow the Java's convention, you gona have a bad time.

@hlopko
Copy link
Member

hlopko commented Jul 27, 2021

CC @c-mita (I hear they're looking into coverage these days :)

@UebelAndre
Copy link
Collaborator

#1077 seems relates

@keith
Copy link
Member

keith commented May 7, 2022

I've been looking into this a bit, and it's definitely possible today by using the C++ related coverage script attribute. It feels a bit like a hack but afaict there still no real movement in bazel around this.

@UebelAndre
Copy link
Collaborator

I've been looking into this a bit, and it's definitely possible today by using the C++ related coverage script attribute. It feels a bit like a hack but afaict there still no real movement in bazel around this.

@keith What's this coverage script attribute?

@keith
Copy link
Member

keith commented May 7, 2022

Here's a super WIP version #1324

@hlopko
Copy link
Member

hlopko commented May 9, 2022

FWIW I think that's our best shot at having working coverage for Rust anytime soon. Took a super-quick look and the PR looks reasonable. Thanks for working on it @keith!

@keith
Copy link
Member

keith commented May 9, 2022

Thanks @hlopko !

@c-mita
Copy link
Member

c-mita commented May 9, 2022

I've been looking into this a bit, and it's definitely possible today by using the C++ related coverage script attribute. It feels a bit like a hack but afaict there still no real movement in bazel around this.

I have a personal desire to fix this; to create a general interface for rules to use to support coverage collection (along with cross-language support). But other things have stolen my time.

The _lcov_merger and _collect_cc_coverage attributes are your best bet for now.
I suppose technically those form something of an API, but they're completely undocumented.

@keith
Copy link
Member

keith commented May 9, 2022

Yea I haven't addressed _lcov_merger, but am using _collect_cc_coverage in #1324, should work fine for now

@UebelAndre
Copy link
Collaborator

Does #1324 address the concerns here?

@rbtcollins
Copy link

I've been poking at our bazel setup to see why we don't get coverage, and it seems the rules_rust coverage data is incompatible with --experimental_split_coverage_postprocessing - I'm not sure why this should be.

Should I file a separate bug for that, or is this bug being used as a tracking bug for coverage for rust in general?

@cristifalcas
Copy link

same for me, it looks like coverage is not created when I have the flag experimental_split_coverage_postprocessing enabled

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

No branches or pull requests

8 participants