bazelbuild / bazelbuild/rules_cc
[rule based toolchain] files from feature-gated cc_args are unconditionally added as action inputs
- Dominant language
- Starlark
- Stars
- 247
- Forks
- 196
- PR merge metrics
- No merged PRs in 30d
Description
In rule based toolchains, cc_args can carry data files needed by the arguments it expands. When those args are guarded by requires_any_of or are attached to a feature that is not enabled, the flags are correctly omitted from the command line, but their data files can still be added to the action inputs.
This means mutually exclusive or disabled toolchain features may both contribute files to the same action input set. For link actions, this can accidentally place both static and dynamic runtime search directories in the sandbox even though only one link mode is active.
## Expected behavior
cc_args(data=...) should follow the same feature/action selection as the args themselves. If the args do not expand for an action, their data files should not be required inputs for that action.
## Repro
A minimal repro is a rule based toolchain with two link-mode features:
```starlark
cc_feature_constraint(
name = "static_linking_mode_enabled",
all_of = ["//cc/toolchains/features:static_linking_mode"],
)
cc_feature_constraint(
name = "dynamic_linking_mode_enabled",
all_of = ["//cc/toolchains/features:dynamic_linking_mode"],
)
cc_args(
name = "static_runtime_search_dir",
actions = ["//cc/toolchains/actions:link_actions"],
args = ["-L{static_dir}"],
data = [":static_dir"],
format = {"static_dir": ":static_dir"},
requires_any_of = [":static_linking_mode_enabled"],
)
cc_args(
name = "dynamic_runtime_search_dir",
actions = ["//cc/toolchains/actions:link_actions"],
args = ["-L{dynamic_dir}"],
data = [":dynamic_dir"],
format = {"dynamic_dir": ":dynamic_dir"},
requires_any_of = [":dynamic_linking_mode_enabled"],
)
```
When linking dynamically, only dynamic_dir should be an input. Today the disabled static args’ data may still be present.
Contributor guide
Research direction
Start with the minimal rule-based toolchain repro and inspect the action inputs for a dynamic link action with mutually exclusive static and dynamic features. Trace how cc_args data is selected alongside its args; done means only the enabled feature's data directory is an input, while disabled args contribute no files.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100