As @errordeveloper answered in a comment, I found very helpful the tutorial documentation here Configure C++ Toolchains. The point is that cross compilation in Bazel works at several levels, iiuc to let developers maximum flexibility.
Platforms describe the execution architecture of "something". That could intentionally mean different things, like the host, execution, and target machine. It is mainly a collection of constraints.
Toolchains describe the set of programs to use to perform the build actions, and they are coupled with the platforms, meaning that some toolchains can be used for certain platforms. For instance, you can tell Bazel to use the toolchain X for all ARM targets, independently from the specific ARM version.
In Bazel's cc_*
rules, the toolchains are generally not downloaded automatically for every target, except some few cases, like iiuc the host machine one. While specifying new platforms is generally easy, specifying new toolchains requires touching multiple files, but it's not terrible. Usually you have to specify the toolchain in a BUILD
file, coupled with a .bzl
one to provide the implementation, and register the toolchain in the MODULE
file. Follow the linked documentation, and if you want this blog post covers basically the same.