Skip to content

Commit 718558f

Browse files
author
Tamas Vajk
committed
Respect --instrumentation_filter for Rust coverage
Previously, all Rust targets were instrumented with -Cinstrument-coverage when running `bazel coverage`, regardless of --instrumentation_filter. This differs from how coverage works for Java and C++ targets, where only targets matching the filter are instrumented. Add ctx.coverage_instrumented() check so that Rust coverage respects the same filter, reducing unnecessary recompilation and keeping coverage reports focused on the code under test.
1 parent 2f07767 commit 718558f

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

rust/private/rustc.bzl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,8 +1220,10 @@ def construct_arguments(
12201220
rustc_flags.add("--extern")
12211221
rustc_flags.add("proc_macro")
12221222

1223-
if toolchain.coverage_supported and ctx.configuration.coverage_enabled:
1224-
# https://doc.rust-lang.org/rustc/instrument-coverage.html
1223+
# Use Bazel's standard instrumentation filter (--instrumentation_filter)
1224+
# so that only targets matching the filter get instrumented, consistent
1225+
# with how coverage works for other languages (Java, C++).
1226+
if toolchain.coverage_supported and ctx.configuration.coverage_enabled and ctx.coverage_instrumented():
12251227
rustc_flags.add("--codegen=instrument-coverage")
12261228

12271229
if toolchain._experimental_link_std_dylib:

0 commit comments

Comments
 (0)