Is there some annotation or usage of select that will allow me to mark a rule to not build (or only build) on a certain platform?
My project has parts that build on Linux, parts that build on Windows, and parts that build on both. I am looking for a way to ignore Windows-only targets when building on Linux and vice-versa. I have a config_setting for each platform, so to pass different compiler options or have different srcs I can simply use a select. I can make Bazel ignore cc_library rules by wrapping all srcs, hdrs, and deps in select statements so that on the unsupported platform they are all blank. However, when I try it for cc_binary rules it fails during linking with an error about main.
Is there some annotation or usage of select that will allow me to mark a rule to not build (or only build) on a certain platform?
--
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/1ea1febd-9d67-4191-8078-584453e6f90f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/a518d3d4-104d-4ff8-bbaf-cb49bba5ba32%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/a518d3d4-104d-4ff8-bbaf-cb49bba5ba32%40googlegroups.com.
Thanks for all the replies!
Greg, I think I see what you mean by investment. It seems like in order to make a rule "restricted_to" a cpu, I'd need to mark every rule it depends on as "compatible_with" that cpu. I'm excited about the platform semantics effort, though.
Austin, are you using scripts to automatically change the build_tag_filters based on the platform you're building on? How do you do that?
Full integration with the platform semantics would be awesome - it would let us be as specific as we want, without the clunky tag filters. I went ahead and opened https://github.com/bazelbuild/bazel/issues/3780 to capture that request.
What this feature does is mix Bazel's (somewhat undocumented) constraint system with the target CPU. There are three steps:
- Define a set of environment rules defining the CPUs you care about:
cpus/BUILD:
environment(name = "x86")
environment(name = "arm")
environment_group(
name = "cpus",
environments = [":x86", ":arm"],
defaults = [":x86"]
)- Tag your binaries you want to be CPU-specific:
//myproject/BUILD:
cc_binary(
name = "x86only",
srcs = ["x86main.cc"],
restricted_to = ["//cpus:x86"])- Add CPU skipping to your command line or .bazelrc:
$ bazel build //myproject:all --experimental_auto_cpu_environment_group=//cpus:cpusAs I mentioned above, this was built specifically for tests. I'm not sure offhand if it works for binaries. Also, this checking is restricted just to CPU, which may or may not be what you want to filter on. Ultimately we should integrate this with Bazel's upcoming platform semantics (which builds on the concepts above) to provide as much granularity and flexibility as you want.If you find this useful but it doesn't quite work, feel free to file issues and assign them to me.