bazelbuild / bazelbuild/rules_cc

cc_binary can't be passed to inherit_attrs

Open
#505 9 comments 1 reaction 0 assignees View on GitHub
P4
Dominant language
Starlark
Stars
247
Forks
196
PR merge metrics
No merged PRs in 30d

Description

I want to wrap cc_binary in macros to select a different compiler for multiple binaries. I came up with this which works perfectly with native cc_binary.

```starlark
def _wrap_impl(name, **kwargs):
cc_binary(
name = name,
**kwargs,
)

_transition_to_clang(
name = name + "_transition",
binary = name,
)

cc_wrap = macro(
inherit_attrs = native.cc_binary,
implementation = _wrap_impl,
)
```

When I change native.cc_binary to cc_binary from rules_cc, I get an error since the latter is exported as a function instead of a rule, contrary to what the cc_binary docstring in `rules_cc/cc/cc_binary.bzl` states.

Contributor guide

Open the contributing guide

Research direction

Start by reading the cc_binary docstring and export in rules_cc/cc/cc_binary.bzl, then reproduce the shown macro with native.cc_binary and rules_cc's cc_binary. Investigate why inherit_attrs rejects the rules_cc export. Done means the documented rule/function behavior and the macro example agree, with the discrepancy addressed or clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
build-system, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.