bazel-skylib icon indicating copy to clipboard operation
bazel-skylib copied to clipboard

Provide `TRUE`/`FALSE` config_setting(s) for use in negating configs

Open trybka opened this issue 3 years ago • 0 comments

A pattern I have used (and seen elsewhere) is to "negate" a config through the use of a pre-defined bool_setting.

It might be nice to provide this in Skylib.

This could be provided with either (or both):

  • a predefined "always true" :true_setting
  • a function in selects which negates a given config_setting or constraint_value

Here's an example usage:

# Define a toolchain viable for ~anything but arm64:
toolchain(
  ...
  target_settings = [":not_arm64"],
  ...
)

alias(
    name = "not_arm64",
    actual = select({
        "@platforms//cpu:arm64": ":FALSE",
        "//conditions:default": ":TRUE",
    }),
)

bool_setting(
    name = "true_setting",
    build_setting_default = True,
    visibility = ["//visibility:private"],
)

config_setting(
    name = "TRUE",
    flag_values = {
        ":true_setting": "True",
    },
)

config_setting(
    name = "FALSE",
    flag_values = {
        ":true_setting": "False",
    },
)

trybka avatar Oct 24 '22 14:10 trybka