Using config_setting and select for multiple combinations of parameters

1,713 views
Skip to first unread message

silves...@gmail.com

unread,
Oct 10, 2017, 9:46:02 AM10/10/17
to bazel-discuss
Hi,

In my project I have multiple combinations of parameters that should result in the same select decision. However I have not been able to find a way to combine this. Is it somehow possible to either combine multiple config labels in one select option or to combine multiple combinations of command line parameters in config_setting?

An example:
config_setting(
name = "macos",
values = { "cpu": "darwin" },
)
config_setting(
name = "ios_arm",
values = { "cpu": "ios_arm64" },
)
config_setting(
name = "ios_x86",
values = { "cpu": "ios_x86_64" },
)
config_setting(
name = "linux",
values = { "cpu": "K8" },
)
config_setting(
name = "android",
values = < some android values >,
)

cc_library(
name = "MyLib",
srcs = select({
":macos": [ "darwin sources" ],
":ios_arm": [ "darwin sources" ],
":ios_x86": [ "darwin sources" ],
":linux": [ "linux sources" ],
":android": [ "android sources" ],
)

For the darwin sources there can be a lot of repetition (5 in my project). Similar for linux for both 32 and 64 bits, etc. The only way I currently know how to fix this is by using define_value and put these on the command-line.

Is there another way to combine this?

Kind regards,
Rob

Austin Schuh

unread,
Oct 10, 2017, 1:43:43 PM10/10/17
to silves...@gmail.com, bazel-discuss
We've been solving a slightly different problem, but I think the same idea applies.  We've been doing CPU and/or compiler selects, and have been putting the logic for those in a macro.  That has let us enforce that all the compilers we care about are handled, for example.

You could do a similar thing here by writing some sort of os_select macro that takes a map from OS to sources.  That would let you duplicate your labels inside the macro rather than out in the BUILD files.  It'll achieve the same effect, but will let you stop repeating yourself in BUILD files which is the important part.

Austin

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/1c3dbbd6-63eb-481c-93ad-cec2b8f4ee74%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

silves...@gmail.com

unread,
Oct 11, 2017, 1:32:53 AM10/11/17
to bazel-discuss
That indeed seems like an approach that works. I'll give it a try. Maybe I can even make a generic macro that takes a dict that allows a list of configs as keys and expands it as required for the select. Thank you for the inspiration!

Rob


Op dinsdag 10 oktober 2017 19:43:43 UTC+2 schreef Austin Schuh:

Greg Estren

unread,
Feb 15, 2018, 4:50:09 PM2/15/18
to bazel-discuss
Check out the Skylib selects._with_or macro, intended as a standardized version of exactly this:

Reply all
Reply to author
Forward
0 new messages