What are the best practices of the platform and cc_toolchain?

123 views
Skip to first unread message

刘宾

unread,
Apr 16, 2023, 11:41:34 PM4/16/23
to bazel-discuss
I'm moving a huge project which constains 100+ modules(cmake/autoconf/GNU make/java/go) from conan to bazel.

I have built the bazel 6.1.0.

I found there are two ways to build with different building flavour
1. build --cpu.. --crosstool_top...
2. build --platforms ...

I search in google for help, but the documents are 2020/2019 ...
I think they may be too old
What are the best practices of the platform and cc_toolchain under bazel 6.1.0?

Tobias Werth

unread,
Apr 17, 2023, 5:54:31 AM4/17/23
to 刘宾, John Cater, bazel-discuss
--
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/4dbfac10-e191-46b8-9ce6-732dc9302b3an%40googlegroups.com.


--

Google Germany GmbH

Erika-Mann-Straße 33

80636 München


Geschäftsführer: Paul Manicle, Liana Sebastian

Registergericht und -nummer: Hamburg, HRB 86891

Sitz der Gesellschaft: Hamburg


Diese E-Mail ist vertraulich. Falls Sie diese fälschlicherweise erhalten haben sollten, leiten Sie diese bitte nicht an jemand anderes weiter, löschen Sie alle Kopien und Anhänge davon und lassen Sie mich bitte wissen, dass die E-Mail an die falsche Person gesendet wurde. 

     

This e-mail is confidential. If you received this communication by mistake, please don't forward it to anyone else, please erase all copies and attachments, and please let me know that it has gone to the wrong person.

John Cater

unread,
Apr 18, 2023, 8:42:46 AM4/18/23
to Tobias Werth, Ivo Ristovski List, 刘宾, bazel-discuss
+Ivo Ristovski List, who has the most updated planning.

As of the Bazel 6.0 series, C++ rules do not use toolchain resolution by default. That means that the canonical flags to control cross-compilation are `--cpu` and `--crosstool_top`.

However, the platform-based system is very mature as long as you are not building for Apple (Objective-C and/or iOS) or Android.

If you want to experiment with the new system you can specify `--incompatible_enable_cc_toolchain_resolution` and use the `--platforms` flag, after defining your platform as discussed in https://bazel.build/extending/platforms.

My understanding is that +Ivo Ristovski List plans to make this flag the default for all C++ builds in the next Bazel LTS release (but he can confirm that).

The canonical source of information for which rules support platforms (and to what extent) is https://bazel.build/concepts/platforms.

I hope this helps clarify the situation.

John Cater

Fredrik Medley

unread,
Apr 18, 2023, 10:44:31 AM4/18/23
to bazel-discuss
I copy my post from a different thread, it might be helpful: https://groups.google.com/g/bazel-discuss/c/ysTeeYsszL0/m/EFmLw8E9AQAJ

The way I think about using the platforms is that the number of (remote) execution platforms are finite and you should be able to define all of them explicitly in Bazel. It is then up to the toolchain resolution to choose a specific execution platform, so `some_rule` needs to define a dependency on at least one toolchain (https://bazel.build/extending/toolchains#writing-rules-toolchains).

I highly recommend watching https://www.youtube.com/watch?v=5Y2WiUafVs0&list=PLxNYxgaZ8RsdH4GCIZ69dzxQCOPyuNlpF&index=18 from BazelCon 2022 where Susan Steinman and John Cater walks through the whole toolchain, platform and exec_group handling. For example, I didn't know that `--toolchain_resolution_debug` can take a target label as argument. Another feature I recently picked up is the `target_settings` attribute of the toolchain rule (https://bazel.build/reference/be/platform#toolchain).

/Fredrik

刘宾

unread,
Apr 18, 2023, 9:28:26 PM4/18/23
to bazel-discuss
Thanks a lot, it's very helpfull
Reply all
Reply to author
Forward
0 new messages