Skip to content

Commit a6ddf88

Browse files
committed
example/bzlmod: recommend extra_toolchains flag
In the latest Bazel versions, rules_cc toolchains will take priority over our own toolchains during automatic resolution. Recommend users to override the priority by using explicit toolchain registration, by either calling `register_toolchains` in their own MODULE.bazel file, or using `--extra_toolchains` flag in their `.bazelrc` file.
1 parent 66146a3 commit a6ddf88

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ Add the following to your `MODULE.bazel` file:
1414
bazel_dep(name = "toolchains_buildbuddy")
1515

1616
# Use the extension to create toolchain and platform targets
17-
buildbuddy = use_extension("@buildbuddy//:extensions.bzl", "buildbuddy")
17+
buildbuddy = use_extension("@toolchains_buildbuddy//:extensions.bzl", "buildbuddy")
18+
19+
# Register buildbuddy_toolchains
20+
register_toolchains(
21+
"@toolchains_buildbuddy//toolchains/cc:all",
22+
)
1823
```
1924

2025
The execution platforms and CC toolchains should be registered automatically under BzlMod.

examples/bzlmod/.bazelrc

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
common --enable_bzlmod
22
common --lockfile_mode=update
33

4-
54
# Use a minimal set of environment variables for action execution to improve
65
# build hermeticity and remote cache hits.
76
common --incompatible_strict_action_env
87

9-
108
# Enable BuildBuddy build event service
119
common --bes_results_url=https://app.buildbuddy.io/invocation/
1210
common --bes_backend=grpcs://remote.buildbuddy.io
1311
# Enable BuildBuddy Remote Execution
1412
common:remote --remote_timeout=3600
1513
common:remote --remote_executor=grpcs://remote.buildbuddy.io
1614

17-
1815
## Register "execution platforms" and "cc toolchains" using Bazel flag.
1916
#
2017
# Relevant toolchains are registered automatically inside "toolchains_buildbuddy" module's MODULE.bazel file.
@@ -25,7 +22,9 @@ common:remote --remote_executor=grpcs://remote.buildbuddy.io
2522
# These will take precedence over the default ones.
2623
#
2724
# The flags `--extra_execution_platforms` and `--extra_toolchains` are used to override the staticcally
28-
# registered toolchains and execution platforms.
25+
# registered toolchains and execution platforms. This is recommended as other Bazel Modules (i.e. rules_cc)
26+
# may register their cc toolchains earlier and take default priority.
27+
#
2928
# For example:
3029
#
3130
# common:remote-linux --extra_execution_platforms=@toolchains_buildbuddy//platforms:linux_x86_64
@@ -39,7 +38,6 @@ common:remote --remote_executor=grpcs://remote.buildbuddy.io
3938
# - https://bazel.build/rules/lib/globals/module#register_execution_platforms
4039
# - https://bazel.build/rules/lib/globals/module#register_toolchains
4140

42-
4341
## Target Linux platform when build remotely
4442
#
4543
# Usage:
@@ -49,17 +47,22 @@ common:remote --remote_executor=grpcs://remote.buildbuddy.io
4947
common:remote-linux --config=remote
5048
common:remote-linux --platforms=@toolchains_buildbuddy//platforms:linux_x86_64
5149
common:remote-linux --extra_execution_platforms=@toolchains_buildbuddy//platforms:linux_x86_64
50+
# (Optional) Explicitly tell Bazel to use this toolchain
51+
# common:remote-linux --extra_toolchains=@toolchains_buildbuddy//toolchains/cc:ubuntu_gcc_x86_64
5252

5353
common:remote-linux-arm64 --config=remote
5454
common:remote-linux-arm64 --platforms=@toolchains_buildbuddy//platforms:linux_arm64
5555
common:remote-linux-arm64 --extra_execution_platforms=@toolchains_buildbuddy//platforms:linux_arm64
56+
# (Optional) Explicitly tell Bazel to use this toolchain
57+
# common:remote-linux --extra_toolchains=@toolchains_buildbuddy//toolchains/cc:ubuntu_gcc_arm64
5658

5759
## Using custom Linux platform
58-
#
60+
#
5961
# This helps verify that user can extend our platform definitions via inheritence.
6062
common:custom-linux --config=remote
6163
common:custom-linux --platforms=//:my_linux_platform
6264
common:custom-linux --extra_execution_platforms=//:my_linux_platform
65+
common:remote-linux --extra_toolchains=@toolchains_buildbuddy//toolchains/cc:ubuntu_gcc_x86_64
6366

6467
## Target Windows platform when build remotely
6568
#
@@ -70,7 +73,8 @@ common:custom-linux --extra_execution_platforms=//:my_linux_platform
7073
common:remote-windows --config=remote
7174
common:remote-windows --platforms=@toolchains_buildbuddy//platforms:windows_x86_64
7275
common:remote-windows --extra_execution_platforms=@toolchains_buildbuddy//platforms:windows_x86_64
73-
76+
# (Optional) Explicitly tell Bazel to use this toolchain
77+
# common:remote-linux --extra_toolchains=@toolchains_buildbuddy//toolchains/cc:windows_msvc_x86_64
7478

7579
# Separate file to keep API Key that should have the follow flag
7680
#

examples/bzlmod/MODULE.bazel

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ buildbuddy = use_extension("@toolchains_buildbuddy//:extensions.bzl", "buildbudd
4747
#
4848
# (Optional) Use the repository directly instead.
4949
# use_repo(buildbuddy, "buildbuddy_toolchain")
50-
#
51-
# (Optional) Register the toolchains.
52-
# register_toolchains(
53-
# "@toolchains_buildbuddy//toolchains/cc:all",
54-
# )
50+
51+
# Register the toolchains explicitly
52+
register_toolchains(
53+
"@toolchains_buildbuddy//toolchains/cc:all",
54+
)

0 commit comments

Comments
 (0)