Respect --instrumentation_filter for Rust coverage#4013
Open
tamasvajk wants to merge 2 commits intobazelbuild:mainfrom
Open
Respect --instrumentation_filter for Rust coverage#4013tamasvajk wants to merge 2 commits intobazelbuild:mainfrom
--instrumentation_filter for Rust coverage#4013tamasvajk wants to merge 2 commits intobazelbuild:mainfrom
Conversation
34d9c2e to
5d59fe5
Compare
Add ctx.coverage_instrumented() check so that only targets matching --instrumentation_filter get -Cinstrument-coverage, consistent with Bazel's recommended approach for rules. For rust_test targets with a crate attribute, also check if the underlying crate should be instrumented. Rust compiles the crate sources directly into the test binary, so the test must be built with -Cinstrument-coverage for the crate's code to produce coverage. Add --instrumentation_filter=^// and --instrument_test_targets to CI coverage tasks so all workspace targets (including tests) are instrumented while excluding external dependencies.
5d59fe5 to
f3693b6
Compare
Remove --instrument_test_targets from recommended settings since it is not needed for the common case of rust_test with a crate attribute. Document the inconsistency where #[cfg(test)] code gets instrumented even without the flag.
80de598 to
76c0787
Compare
--instrumentation_filter for Rust coverage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Respect
--instrumentation_filterwhen instrumenting Rust targets for coverage, consistent with Bazel's recommended approach for rules.Problem
Previously, all Rust targets were instrumented with
-Cinstrument-coveragewhen runningbazel coverage, regardless of--instrumentation_filter. This causes:Changes
rustc.bzl: Addctx.coverage_instrumented()check, the standard Bazel API for respecting--instrumentation_filter. Only targets matching the filter get-Cinstrument-coverage. Forrust_testtargets with acrateattribute, also check whether the underlying crate should be instrumented — Rust compiles the crate sources directly into the test binary, so the test must be built with-Cinstrument-coveragefor the crate's code to produce coverage data.coverage.md: Add documentation for coverage usage, explaining--instrumentation_filter, therust_testwithcrateattribute behavior, and--instrument_test_targets..bazelci/presubmit.yml: Add--instrumentation_filter=^//and--instrument_test_targetsto CI coverage tasks so that all workspace targets (including tests) are instrumented while excluding external dependencies.