Repository navigation
cargo_build_script: don't configure cc coverage features for build scripts - #4433
Open
TrapsterDK wants to merge 1 commit into
Open
TrapsterDK wants to merge 1 commit into
TrapsterDK wants to merge 1 commit into
Conversation
…ripts
Whenever coverage is enabled, Bazel requests the `coverage` feature and a
coverage map format (`gcc_coverage_map_format` by default,
`llvm_coverage_map_format` with `--experimental_use_llvm_covmap`) when
configuring cc features; newer rules_cc also requests `coverage_enabled`
and `coverage_instrumented`. This doesn't depend on
`--instrumentation_filter`. `cargo_build_script` used that feature
configuration to compute CC/CFLAGS/CXXFLAGS/LDFLAGS and the linker env, so
every build script with `use_cc_toolchain` picked up the toolchain's
coverage flags, and so did the C code it compiles through cc-rs.
On macOS this breaks `bazel coverage`: apple_support's
`gcc_coverage_map_format` feature sets `GCOV_GCNO_FILE=%{gcov_gcno_file}`
on compile actions, and a build script action has no gcno path, so
analysis fails on the unexpanded variable.
The build script now passes these five features as extra unsupported
features to `find_cc_toolchain`.
Test: new `coverage_features_disabled_test` in
`cargo/tests/cargo_build_script/cc_args_and_env`. It gives the test cc
toolchain coverage features, analyzes the build script with
`--collect_code_coverage`, and checks CFLAGS, CXXFLAGS and LDFLAGS carry
no coverage flags. It fails without the change.
`coverage_features_disabled_test_control` checks that in the same
configuration a plain feature configuration for the same toolchain does
get `--coverage`, so the first test can't pass just because coverage was
never requested.
Assisted-by: Claude
This was referenced Nov 18, 2026
TrapsterDK
added a commit
to devhusdk/rules_dx
that referenced
this pull request
Nov 18, 2026
…#13481) Point the Upstream headers of cargo_build_script_no_coverage, crate_universe_module_labels, crate_universe_lazy_host_tools and cargo_toml_env_vars_flag at bazelbuild/rules_rust#4433, #4436, #4438/#4331 and #4437, so the weekly patch-upstream check tracks them. Claude-Session: https://claude.ai/code/session_01Xut2hvgPbKqbuDgsTasg7K Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Fixes #4432
cargo_build_scriptnow passescoverage,coverage_enabled,coverage_instrumented,gcc_coverage_map_formatandllvm_coverage_map_formatasextra_unsupported_featureswhen it callsfind_cc_toolchain. Bazel requestscoverageand one of the map formats whenever coverage is enabled, whatever--instrumentation_filtersays, and newer rules_cc also requestscoverage_enabled/coverage_instrumented. So today every build script that uses the cc toolchain gets coverage flags underbazel coverage.That feature configuration is only used to build the build script's cc environment (
CC/CXX/AR,CFLAGS,CXXFLAGS,LDFLAGS, the linker env andINCLUDE). Turning the features off there keeps coverage flags out of the build script and out of whatever it compiles through cc-rs. It also means variables those features expect, such asgcov_gcno_file, are never needed. That variable should breakbazel coverageon macOS with apple_support >= 2.10.0 and the default gcc covmap: itsgcc_coverage_map_formatfeature setsGCOV_GCNO_FILE=%{gcov_gcno_file}, and a build script action has no gcno path. I haven't reproduced that on a Mac; it follows from reading the apple_support toolchain config. The companion apple_support PR, bazelbuild/apple_support#693, guards that env entry on its side.find_cc_toolchainalready tookextra_unsupported_features, so the change is one call site. Coverage of Rust code itself is unaffected: that goes through rustc's-Cinstrument-coverageand doesn't use this feature configuration.Tests, in
cargo/tests/cargo_build_script/cc_args_and_env:coverage,gcc_coverage_map_formatandllvm_coverage_map_formatfeatures that add flags to compile and link actions. They're off unless requested, so the existing tests don't change. The transition used by those tests can now also set--collect_code_coverage.coverage_features_disabled_testanalyzes a build script with--collect_code_coverageand checks that no coverage flags show up inCFLAGS,CXXFLAGSorLDFLAGS. Without the fix it fails:CFLAGSandCXXFLAGScontain--coverage -fprofile-arcs -ftest-coverage, andLDFLAGScontains--coverage.coverage_features_disabled_test_controlis a check on the test itself. In the same configuration with the same toolchain, a plain feature configuration does get--coverage. That way the first test can't pass just because coverage was never requested. I checked that it fails when the transition doesn't turn coverage on.bazel test //cargo/tests/cargo_build_script/...passes (72 tests).Assisted by Claude.