bazelbuild / bazelbuild/bazel

Expose compilation_outputs.gcno_files() and compilation_outputs.pic_gcno_files() as public starlark API

Open
#24,724 2 comments 2 reactions 0 assignees View on GitHub
P2 team-Rules-CPP type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the feature request:

When trying to access the second output (`compilation_outputs`) of `cc_common.compile`, some methods are private API and calling them from user-defined rules leads to the following error:

```
ERROR: /home/user/project/BUILD.bazel:119:37: in foo_library rule //REDACTED:
Traceback (most recent call last):
File "/home/user/...output-base.../external/rules_foo+/rule/cc/helper.bzl", line 222, column 56, in create_cc_providers_from_files
metadata_files = compilation_outputs.gcno_files() + compilation_outputs.pic_gcno_files(),
Error in gcno_files: file '@@rules_foo+//rule/cc:helper.bzl' cannot use private API
```

### Which category does this issue belong to?

_No response_

### What underlying problem are you trying to solve with this feature?

Use `cc_common.compile` and friends to build C++ code, then get valid coverage (including `gcno` files) forwarded to `coverage_common.instrumented_files_info`, just like what Bazel does [internally](https://cs.opensource.google/bazel/bazel/+/master:src/main/starlark/builtins_bzl/common/cc/cc_library.bzl;l=263-268;drc=17f3cbc33a1dc0b68479f1f1a25ab832f6322842).

I think this could be as simple as changing [this](https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CcCompilationOutputsApi.java;l=89-93;drc=9b30bf761a7526433c56251c49d7da3b8286bf8b).

Alternatively, `rules_cc` could maybe export `create_cc_instrumented_files_info`, but change the API so it takes `compilation_outputs` and extracts gcno files in that helper (which should be allowed to use private APIs). I implemented that [here](https://github.com/bazelbuild/rules_cc/pull/293).

### Which operating system are you running Bazel on?

Ubuntu 22.04

### What is the output of `bazel info release`?

release 8.0.0

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse HEAD` ?

```text
N/A
```

### Have you found anything relevant by searching the web?

_No response_

### Any other information, logs, or outputs that you want to share?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CcCompilationOutputsApi.java and compare its API visibility with the internal use in src/main/starlark/builtins_bzl/common/cc/cc_library.bzl. Verify that user-defined Starlark rules can access gcno_files() and pic_gcno_files() for coverage forwarding, while considering the alternative rules_cc helper described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, java
Domain
build-system
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.