Harrison Xi
Harrison Xi

Reputation: 796

How to enable/disable attribute with config setting in bazel?

config_setting(
    name = "arm_cpu",
    values = {"cpu": "arm"},
)

objc_library(
    name = "a_lib",
    pch = "a.pch",
)

I want to make the "pch" attribute only take effect for arm cpu. But I don't know how to use select() function for label attributes easily. So I have to write an empty pch file and modify the BUILD file like this:

objc_library(
    name = "a_lib",
    pch = select({
        ":arm_cpu" : "a.pch",
        "//conditions:default" : "empty.pch",
    )},
)

Is there a better way to do this?

Upvotes: 1

Views: 283

Answers (1)

Benjamin Peterson
Benjamin Peterson

Reputation: 20580

Generally, one can obtain the default for an attribute by using None:

objc_library(
    name = "a_lib",
    pch = select({
        ":arm_cpu" : "a.pch",
        "//conditions:default": None,
    }),
)

Upvotes: 4

Related Questions