How should one include a platform-specific flag in bazel?
Say we have a cross-platform library that we want to change defines on.
Can we do something like:
defines = ["FEATURE_A"]
if somehow_detect_the_platform == 'ios':
defines.extend("FEATURE_B")
cc_library(
name = "foo",
srcs = ["foo.cc"],
defines = defines,
hdrs = ["foo.h"],
)
Also note that this concept can apply to other things like includes, cflags, sources, headers, etc.
There are 2 options. First is using select function. With select you can conditionally set the value of an attribute depending on the current configuration.
Second option is to tweak the CROSSTOOL configuration file, put a specific feature that would emit different flags depending on the toolchain. Then you can enable that feature in your cc_library in features attribute.
First option is simpler, the second one is more robust and more encapsulated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With