Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between cc_toolchain_suite and register_toolchains?

Tags:

bazel

In the context of C++ toolchain, I am trying to understand the difference of the concept between cc_toolchain_suite and register_toolchains, to me it seems they achieve the same purpose: select a toolchain based on command line parameters.

See https://docs.bazel.build/versions/master/toolchains.html for register_toolchains See https://docs.bazel.build/versions/master/cc-toolchain-config-reference.html for cc_toolchain_suite

Can someone please help understand the subtlety behind these 2 concepts?

like image 987
blaizard Avatar asked Jan 22 '26 18:01

blaizard


1 Answers

TL;DR The cc_toolchain_suite is part of the legacy toolchain configuration system. It still exists in Bazel because the migration to the new API is not complete. The register_toolchains is part of the newer, unified toolchain API. When possible use register_toolchains instead of cc_toolchain_suite/--*crosstool_top

Originally the concept of a 'toolchain' was not standardised in Bazel, so a Java toolchain would be implemented very differently than a cc toolchain.

Before the unified starlark toolchain API, cc toolchains were specified in proto-text formatted 'CROSSTOOL' files. With the introduction of the platforms API and the unified toolchains API, the concepts in the CROSSTOOL files were converted almost 1:1 to the new unified platforms/toolchains starlark API. This was mostly to ensure that there was compatibility between the old/new API's.

One of the concepts in the older 'CROSSTOOL' configuration system was a 'toolchain suite', that allowed you to define a group of toolchains targeting different CPU's (This was before the platforms API was introduced).

As far as I understand the only reason that cc_toolchain_suite is still a part of Bazel's starlark API is that some of the apple/android toolchains have not yet been completely migrated across.

Here are a few examples of where I've opted to using the newer register_toolchains approach. Note that these toolchains do not use cc_toolchain_suite anymore.

like image 115
silvergasp Avatar answered Jan 27 '26 00:01

silvergasp