Syntactic sugar for `target_compatible_with` a `bool_flag`, `config_setting`
Description of the feature request:
I would like to mark a target as target_compatible_with a config_setting. I hoped I could do,
target_compatible_with = [":my_config_setting"]
It turns out this is not supported. Instead, I must express this as,
target_compatible_with = select({
":my_config_setting": [],
"//conditions:default": ["@platforms//:incompatible"],
})
That's a little verbose, and a little obscure!
Actually, things are even worse than this, because the config_setting is used only to detect that a Skylib bool_flag is true. What I'd really love to say is,
bool_flag(
name = "my_flag",
build_setting_default = False,
)
cc_library(
target_compatible_with = [":my_flag"],
)
But instead I write,
bool_flag(
name = "my_flag",
build_setting_default = False,
)
config_setting(
name = "my_flag_true",
flag_values = {
":my_flag": "True",
},
)
cc_library(
target_compatible_with = select({
":my_flag_true": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
)
@katre
Which category does this issue belong to?
Configurability
What underlying problem are you trying to solve with this feature?
No response
Which operating system are you running Bazel on?
No response
What is the output of bazel info release?
No response
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
To clarify, the underlying problem is that:
target_compatible_withexpects to receiveconstraint_valuetargets- You are instead passing it a
config_setting, and - The special value
@platforms//:incompatibleisn't actually special to bazel at all, it's just defined in a way that no platform will ever match it.
We can certainly take a look at supporting this, but I don't actually think it's going to be a clean change to the current support.
Yeah, that's right. I just wanted to report that this user journey is a bit awkward for me. But I understand it may not be easy to smooth out!