Allow reading from constraints and config settings via providers
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the feature request:
I'd like `config_setting` and `constraint_value` rules to output a provider corresponding to whether they evaluate to true or false. This would allow us to read them directly in rules.
```py
SelectMatchInfo = provider(
fields = {"value": "(bool) Whether or not this counts as matching a select"}
)
```
As a follow-on from this, we could potentially have `select` read from the provider itself, thus allowing us to make any rule `select`'able. This would be extremely useful for a few particular rules:
* bazel-skylib's `bool_flag` could be chained
* bazel-skylib's `selects.config_settings_group` is currently implemented in a very hacky manner. This would allow us to clean that up
It would also allow us to implement arbitrarily complex resolution of config settings. For example, you could have a string_flag, and have a bool setting that checks if it starts with `"linux-"`.
This would allow us to write:
```py
bool_flag(
name = "foo",
build_setting_default = False,
)
alias(
name = "bar",
actual = select({
":foo": ":something",
"//conditions:default": ":something_else",
})
)
```
### Which category does this issue belong to?
Core
### What underlying problem are you trying to solve with this feature?
At the moment, if I write:
```py
selects.config_settings_group(
name = "foo_and_bar",
match_all = [":foo", ":bar"]
)
```
```py
def _my_rule_impl(ctx):
...
my_rule = rule(
implementation = _my_rule_impl,
attrs = {
"_foo_and_bar": attr.label(default = ":foo_and_bar"),
"_constraint": attr.label(default = "@platforms//os:linux"),
}
)
```
Then in the rule implementation, I have no way of determining whether the config setting resolves to true or to false, and the same goes for the constraint value.
### Which operating system are you running Bazel on?
linux
### What is the output of `bazel info release`?
7.1.1
### 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` ?
_No response_
### 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
Research direction
No files, tests, or entry points are named. Start by reviewing the issue's examples for config_setting, constraint_value, providers, and select, then trace their existing rule evaluation behavior. Done means agreeing on and implementing a supported way for rules to read whether these values evaluate true or false, with coverage for the described use cases.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100