Document why `config_setting()` doesn't support `--config`
#11,531 opened on 2020年6月2日
Repository metrics
- Stars
- (25,384 stars)
- PR merge metrics
- (平均マージ 22d 20h) (30d で 77 merged PRs)
説明
Description of the problem / feature request:
The documentation on configuration attributes suggests that config_setting() should be able to match on any Bazel flag, e.g., --copt or --cpu. However, it fails to match on --config.
My use case: I am contributing to a project with several existing --config options, and I want to set build rules based on what --config options are set.
Example
Put the following in a BUILD file:
config_setting(
name = "my_config",
values = {"config" : "foo"},
)
cc_binary(
name = "my_binary",
srcs = select({
":my_config": ["a.cc"],
"//conditions:default": ["b.cc"],
}),
)
Then run bazel build :my_binary (or bazel build :my_binary --config=foo). The following error results:
ERROR: /home/ubuntu/scratch/BUILD:1:15: in values attribute of config_setting rule //:my_config: error while parsing configuration settings: unknown option: 'config'
Workaround
This is a minor issue because there's a workaround with an additional step of indirection. Add something like this to the .bazelrc:
build:foo --define foo=yes
and change the config_setting in the BUILD to
config_setting(
name = "my_config",
define_values = {"foo" : "yes"},
)
I wasted some time mucking around in documentation for defining custom flags, however, before a colleague suggested this workaround. Hence it may be appropriate to either add support for matching on --config or to explicitly mention in the documentation that config_setting() will not match on --config.
What operating system are you running Bazel on?
Ubuntu 18.04
What's the output of bazel info release?
release 3.2.0
Have you found anything relevant by searching the web?
Didn't see anything related on StackOverflow, GitHub issues, or on bazel-discuss.