Split coverage features into coverage_enabled and coverage_instrumented - #842
Open
fmeum wants to merge 2 commits into
Open
Split coverage features into coverage_enabled and coverage_instrumented#842fmeum wants to merge 2 commits into
coverage_enabled and coverage_instrumented#842fmeum wants to merge 2 commits into
Conversation
Collaborator
Author
|
The coverage failure is preexisting, will send a fix to Bazel. |
Collaborator
Author
|
I pushed a new commit with further cleanup enabled by this change. |
…ented` `cc_common.configure_features` only requested a single `coverage` feature when building with coverage, which doesn't allow toolchains to distinguish between targets that are instrumented for coverage and those that aren't. The default toolchains thus end up instrumenting everything even with a narrow `--instrumentation_filter`, which is wasteful. `coverage_enabled` is now requested whenever coverage is generally enabled (matching `coverage`), whereas `coverage_instrumented` is only requested if the current target is instrumented. This gives toolchains a clean way to only instrument the targets that require it, see bazelbuild#424 for an example. Along the way, `implementation_deps` is added to the check for an instrumented dependency, which apparently wasn't updated when this attribute was added. This is a port of bazelbuild/bazel#26355, with the coverage feature computation kept in `configure_features` instead of moved into the individual rules: unlike Bazel's Java implementation, the Starlark one has access to `ctx`, so every rule calling `cc_common.configure_features` benefits without losing the existing `coverage` and `*_coverage_map_format` features.
Derive coverage outputs and build variables directly from the coverage_instrumented feature. Inject legacy coverage marker features independently to avoid partial-definition conflicts.
fmeum
force-pushed
the
cc-coverage-features
branch
from
August 12, 2026 09:44
66eaf86 to
c2c13a3
Compare
Collaborator
Author
|
CI is green now @pzembrod |
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.
Before this change, rules_cc only enabled a single coverage feature when building with coverage, which doesn't directly allow toolchains to distinguish between targets that are instrumented for coverage and those which are not. The default toolchain thus ends up instrumenting everything even with a narrow
--instrumentation_filter, which is wasteful. Blaze relies on the presence of thegcov_gcno_filevariable to avoid this, but that's really more of a hack and undocumented (and also undocumentable).This change lets rules_cc request two new coverage-related features:
coverage_enabledis requested whenever coverage is generally enabled (matchingcoverage), whereascoverage_instrumentedis only requested when the current target is instrumented. This provides a clean way for toolchains to instrument only those targets that require it (see #424 for an example of such a toolchain).Along the way, implementation_deps is added to the check for an instrumented dependency, which apparently wasn't updated when this attribute was added.
Older versions of rules_cc only request
coverage, so toolchains that want to support them as well can keep their existingcoverageflag sets and guard them withwith_feature_set(not_features = ["coverage_enabled"]).Fixes bazelbuild/bazel#15627
Fixes bazelbuild/bazel#21911