Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ buildbuddy = use_extension("//:extensions.bzl", "buildbuddy")
use_repo(buildbuddy, "buildbuddy_toolchain")

register_toolchains(
"//toolchains/cc:all",
# Do not use :all because aliases are not picked up by wildcard registration
"//toolchains/cc:ubuntu_gcc_x86_64",
"//toolchains/cc:ubuntu_gcc_arm64",
"//toolchains/cc:windows_msvc_x86_64",
)
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ Add the following to your `MODULE.bazel` file:
bazel_dep(name = "toolchains_buildbuddy")

# Use the extension to create toolchain and platform targets
buildbuddy = use_extension("@buildbuddy//:extensions.bzl", "buildbuddy")
buildbuddy = use_extension("@toolchains_buildbuddy//:extensions.bzl", "buildbuddy")

# Register buildbuddy_toolchains
register_toolchains(
"@toolchains_buildbuddy//toolchains/cc:all",
)
```

The execution platforms and CC toolchains should be registered automatically under BzlMod.
Expand Down
18 changes: 11 additions & 7 deletions examples/bzlmod/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
common --enable_bzlmod
common --lockfile_mode=update


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


# Enable BuildBuddy build event service
common --bes_results_url=https://app.buildbuddy.io/invocation/
common --bes_backend=grpcs://remote.buildbuddy.io
# Enable BuildBuddy Remote Execution
common:remote --remote_timeout=3600
common:remote --remote_executor=grpcs://remote.buildbuddy.io


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


## Target Linux platform when build remotely
#
# Usage:
Expand All @@ -49,17 +47,22 @@ common:remote --remote_executor=grpcs://remote.buildbuddy.io
common:remote-linux --config=remote
common:remote-linux --platforms=@toolchains_buildbuddy//platforms:linux_x86_64
common:remote-linux --extra_execution_platforms=@toolchains_buildbuddy//platforms:linux_x86_64
# (Optional) Explicitly tell Bazel to use this toolchain
# common:remote-linux --extra_toolchains=@toolchains_buildbuddy//toolchains/cc:ubuntu_gcc_x86_64

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

## Using custom Linux platform
#
#
# This helps verify that user can extend our platform definitions via inheritence.
common:custom-linux --config=remote
common:custom-linux --platforms=//:my_linux_platform
common:custom-linux --extra_execution_platforms=//:my_linux_platform
# common:custom-linux --extra_toolchains=@toolchains_buildbuddy//toolchains/cc:ubuntu_gcc_x86_64

## Target Windows platform when build remotely
#
Expand All @@ -70,7 +73,8 @@ common:custom-linux --extra_execution_platforms=//:my_linux_platform
common:remote-windows --config=remote
common:remote-windows --platforms=@toolchains_buildbuddy//platforms:windows_x86_64
common:remote-windows --extra_execution_platforms=@toolchains_buildbuddy//platforms:windows_x86_64

# (Optional) Explicitly tell Bazel to use this toolchain
# common:remote-linux --extra_toolchains=@toolchains_buildbuddy//toolchains/cc:windows_msvc_x86_64

# Separate file to keep API Key that should have the follow flag
#
Expand Down
13 changes: 9 additions & 4 deletions examples/bzlmod/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@ buildbuddy = use_extension("@toolchains_buildbuddy//:extensions.bzl", "buildbudd
#
# (Optional) Use the repository directly instead.
# use_repo(buildbuddy, "buildbuddy_toolchain")

# Register the toolchains with higher priority than dependent modules (i.e. rules_cc)
#
# (Optional) Register the toolchains.
# register_toolchains(
# "@toolchains_buildbuddy//toolchains/cc:all",
# )
# User may explicitly choose a specific toolchain using the `--extra_toolchains=` flag.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still misleading: The individual toolchains we register don't compete with each other since their target constraints differ, so users never have to order them explicitly. Instead, they could just drop some of the arguments to this call.

The case in which users need --extra_toolchains is if they only want our toolchain(s) to win sometimes. I guess we don't have to tell them about --extra_toolchains in that case since there is nothing special about this case (no ordering issues, nothing specific to Bzlmod or BuildBuddy).

We could still call out the flag as an alternative to the call, but not for the purpose mentioned in the comment.

# See 'examples/bzlmod/.bazelrc' file for more details.
register_toolchains(
"@toolchains_buildbuddy//toolchains/cc:ubuntu_gcc_x86_64",
"@toolchains_buildbuddy//toolchains/cc:ubuntu_gcc_arm64",
"@toolchains_buildbuddy//toolchains/cc:windows_msvc_x86_64",
)