Accept config_settings in target_compatible_with
See original GitHub issueDescription of the feature request:
bazel 4.0 adds a target_compatible_with
common attribute that accepts a list constraint_value
s. It would be great if it could also accept config_setting
s.
What underlying problem are you trying to solve with this feature?
I would like to mark a target to be compatible only if :my_config_setting
is true, so that the target itself and all inverse dependencies don’t build otherwise.
I can currently work around this by translating a config_setting
into a constraint_value
by select()
ing the constraint_setting
’s default_constraint_value
. But apparently constraint_settings are supposed to be configuration independent, so that workaround is bad style:
config_setting(
name = "my_config",
...
)
constraint_setting(
name = "my_constraint",
default_constraint_value = select({
":my_config": ":my_value",
"//conditions_default": None,
}),
)
constraint_value(
name = "my_value",
constraint_setting = ":my_constraint",
)
cc_binary(
...
target_compatible_with = [
# feature request: allow ":my_config" here instead
":my_value",
],
)
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ha! Thanks a lot for thinking of this Philipp.
Yes,
select
ing on the target_compatible_with would be a perfectly fine alternative. I don’t mind the helper function.In fact, that’s what I used before I realized that you can (currently, and I hear it might go away)
select
on thedefault_constraint_value
. But by the time I wrote this issue I had already forgotten 😦I’m happy with Philipp’s approach and as far as I’m concerned you can close this issue.
Thanks for your help!
Closing as acknowledged.
To be clear, my preference is to try to limit built-in Bazel support to
constraint_value
and the mentioned to-be-implemented toolchain properties.I like that a reasonable user-space approach was identified here, so you can get what you need without stretching Bazel’s core API complexity.