While configuring a toolchain, we were trying to override the legacy fully_static_link feature to always be enabled, except when the variable is_cc_test is true or if the target needs runtime libraries.
The documentation for requires_true (requires_false) says that the given variable will be checked for truthiness (falsiness). so we were trying to use them in the following setup:
cc_nested_args(
name = "if_not_cc_test",
args = ["-static"],
requires_false = "@rules_cc//cc/toolchains/variables:is_cc_test",
)
cc_args(
name = "fully_static_args",
actions = [
"@rules_cc//cc/toolchains/actions:link_actions",
],
nested = [":if_not_cc_test"],
requires_false = "@rules_cc//cc/toolchains/variables:runtime_library_search_directories",
)
cc_feature(
name = "fully_static_link",
args = [":fully_static_args"],
overrides = "@rules_cc//cc/toolchains/features/legacy:fully_static_link",
visibility = ["//visibility:public"],
)
We were expecting requires_false = "@rules_cc//cc/toolchains/variables:runtime_library_search_directories" to work, as Bazel's expand_if_true/expand_if_false evaluate an empty sequence to false, however we get an error as the current implementation restricts the allowed types to bool.
Patching nested_args.bzl to accept list as well makes our setup work.
We think either the documentation should be updated to reflect that only variables of type bool are accepted, or the implementation should match what expand_if_true/expand_if_false do.
While configuring a toolchain, we were trying to override the legacy
fully_static_linkfeature to always be enabled, except when the variableis_cc_testis true or if the target needs runtime libraries.The documentation for
requires_true(requires_false) says that the given variable will be checked for truthiness (falsiness). so we were trying to use them in the following setup:We were expecting
requires_false = "@rules_cc//cc/toolchains/variables:runtime_library_search_directories"to work, as Bazel'sexpand_if_true/expand_if_falseevaluate an empty sequence tofalse, however we get an error as the current implementation restricts the allowed types tobool.Patching
nested_args.bzlto acceptlistas well makes our setup work.We think either the documentation should be updated to reflect that only variables of type
boolare accepted, or the implementation should match whatexpand_if_true/expand_if_falsedo.