bazelbuild / bazelbuild/rules_cc

Document preferred way to add opt only compile flags with rules based toolchain

Open
#325 11 comments 0 reactions 1 assignee Claimed by @armandomontanez View on GitHub
category: toolchains untriaged
Dominant language
Starlark
Stars
247
Forks
196
PR merge metrics
No merged PRs in 30d

Description

A common pattern in the previous CC toolchain was to have some compile flags split on dbg/fastbuild/opt. I don't see any docs or examples of how to do that with the rule based toolchain. My first attempt was this:

```bzl
cc_feature_constraint(
name = "opt_cfg",
all_of = ["@rules_cc//cc/toolchains/features:opt"],
)

cc_args(
name = "opt_compile_flags",
actions = ["@rules_cc//cc/toolchains/actions:compile_actions"],
args = [
"-DNDEBUG",
"-D_FORTIFY_SOURCE=1",
"-O2",
],
requires_any_of = [":opt_cfg"],
)
```

But the flags aren't added, so I assume that's not the right move. I found another example where the user just overrode the feature instead:

https://github.com/lowRISC/opentitan/blob/7704c7a75d9fff2fdfb42e40d5bd311ac9f94f9b/toolchain/BUILD#L193-L202

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.