Hi folks.Suppose I have the following:```cc_library(
name = "hello",
srcs = ["hello.cc"],
target_compatible_with = [
"@platforms//cpu:foo", # imagine here that :foo exists
"@platforms//os:bar", # imagine here that :bar exists
],
)```Is it possible for the correct compiler to be chosen automatically by bazel if I do `bazel build //:hello`? (that is, no added .bazelrc or flag magic)
On Fri, Mar 10, 2023 at 10:52 AM Filip Filmar <fil...@gmail.com> wrote:
[...] the simulator itself is written in C++ for the host and compiled by bazel; another program I want to compile is written in C++, but needs to be compiled for the target. But then, I need to feed the target's binary into the host's simulator.
You want a configuration transition.
https://bazel.build/extending/config That will let you switch
platforms, which will trigger Bazel to pick a new compiler/toolchain
suitable for the new platform.
Check out https://github.com/aspect-build/bazel-lib/blob/main/lib/transitions.bzl.
You need a rule which does the transition, and you point it to your
binary. And then depend on the transition rule to pick up the
transioned binary.
We ended up hacking that target up a bit to do what we want, but you
might be able to use it as is. There's some good stuff in that repo.