This guide assumes you’re using BuildBuddy Cloud or BuildBuddy Enterprise on-prem.
The basics
To execute a build remotely on BuildBuddy, pass the--remote_executor flag to your bazel build command:
Projects that build native libraries or binaries or depend on platform-specific tools will need more configuration to take advantage of RBE. We do this with platforms and toolchains. Adding the BuildBuddy Toolchain to your project will let you build and test targets remotely.
Using the BuildBuddy Toolchain with Bazel modules
If your project uses Bazel modules, you can add the BuildBuddy Toolchain as a dependency for your module:MODULE.bazel
Using the BuildBuddy Toolchain with a WORKSPACE file
If your project still uses aWORKSPACE file, you can add the BuildBuddy Toolchain with this snippet:
WORKSPACE
Platforms
The first thing you’ll want to do is tell BuildBuddy RBE in what environment you’ll want to run your build actions. This is where tools can be found in different locations on different platforms. This is done with the--host_platform, --platforms, and --extra_execution_platforms flags.
BuildBuddy’s default platform is Ubuntu 16.04 with Java 8 installed. We can specify this platform with the --host_platform, --platforms, and --extra_execution_platforms flags:
Toolchains
Toolchains sound complicated (and they can be) - but the concept is simple. We’re telling our remote executors where to find tools that are needed to build our code.C toolchain
The first toolchain you’ll likely run into the need for is a C/C++ compiler. Even if your code isn’t written in one of these languages, it’s likely that one of your dependencies is - or calls some C code with something like cgo. You’ll know you need a C toolchain when you see an error for a missing gcc or clang that looks like:--crosstool_top and --extra_toolchains flag:
If you’re looking for an llvm based toolchain instead, take a look at this project.
Java toolchain
If your project depends on Java code, you’ll need to set the following flags:If you need a custom Java toolchain, see Bazel’s docs on Java toolchain configuration.
Java toolchain for older Bazel versions
Java toolchain for older Bazel versions
If your project is using a Bazel version before 6.0.0, you will need the following 4 flags instead. They will tell the executors where to look for Java tools.Using BuildBuddy’s default Java 8 config:If you need a different version of Java, we recommend using bazel-toolchains for now.
Attributes
Some tools like Bazel’s zipper (@bazel_tools//tools/zip:zipper) use an attribute to determine whether or not they’re being run remotely or not. For tools like these to work properly, you’ll need to define an attribute calledEXECUTOR and set it to the value remote.
Putting it all together
This can be a lot of flags to tack onto each bazel build, so instead you can move these to your.bazelrc file under the remote config block:
.bazelrc
Authentication
You’ll want to authenticate your RBE builds with either API key or certificate based auth. For more info on how to set this up, see our authentication guide.Configuration options
—jobs
This determines the number of parallel actions Bazel will remotely execute at once. If this flag is not set, Bazel will use a heuristic based on the number of cores on your local machine. Your builds & tests can likely be parallelized much more aggressively when executing remotely. We recommend starting with50 and working your way up.
—remote_timeout
This determines the maximum time Bazel will spend on any single remote call, including cache writes. The default value is 60s. We recommend setting this high to avoid timeouts when uploading large cache artifacts.—remote_download_minimal
By default, bazel will download intermediate results of remote executions - so in case an artifact isn’t found in the remote cache, it can be re-uploaded. This can slow down builds in network-constrained environments. This can be turned off with the flag:—remote_instance_name
If you’d like separate remote caches, whether it’s for CI builds vs local builds or other reasons, you can use theremote_instance_name flag to namespace your cache artifacts:
—disk_cache
While setting a local disk cache can speed up your builds, when used in conjunction with remote execution - your local and remote state has the opportunity to get out of sync. If you suspect you’re running into this problem, you can disable your local disk cache by setting this to an empty value.—incompatible_strict_action_env
Some rules (like protobuf) are particularly sensitive to changes in environment variables and will frequently be rebuilt due to resulting cache misses. To mitigate this, you can use theincompatible_strict_action_env which sets a static value for PATH.
—action_env, —test_env
You can set environment variables that are available to actions with the--action_env flag. If you want to set environment variables that are only available to test actions, you can use the --test_env flag.
This is commonly used to set environment variables such as GO_TEST_WRAP_TESTV=1, which modifies how the go_test rule handles the XML reports.
--action_env Bazel docs
--test_env Bazel docs
—repo_env
This flag sets additional environment variables that are available to repository rules executions. It’s commonly used to set environment variables that are used to augment how toolchains and external repositories are prepared.—define
Define allows you to assign build variables. This is commonly use to setEXECUTOR to compile singlejar and ijar from source.
—spawn_strategy
Sets the list of strategies in priority order from highest to lowest. Each action picks the highest priority strategy that it can execute. The default value isremote,worker,sandboxed,local.
—strategy
Explicitly setting strategies should no longer be needed for Bazel versions post 0.27.0. It can be used to force certain bazel mnemonics to be build remotely.—remote_execution_priority
Sets the priority of remotely executed actions within a build, relative to other builds within your BuildBuddy organization. The default value is 0, and BuildBuddy accepts values between -1000 and 1000 (inclusive). Lower priority values cause actions to be executed before actions with larger priority values.Remote execution priority is applied on a best-effort basis. Setting this flag doesn’t provide a strong guarantee of execution ordering.
—experimental_inmemory_dotd_files
If enabled, C++ .d files will be passed through in memory directly from the remote build nodes instead of being written to disk. This flag is automatically set when using--remote_download_minimal.
—experimental_inmemory_jdeps_files
If enabled, .jdeps files generated from Java compilations will be passed through in memory directly from the remote build nodes instead of being written to disk. This flag is automatically set when using--remote_download_minimal.
Examples
BuildBuddy
buildbuddy-io/buildbuddy .bazelrc —config=remote
Grakn
graknlabs/grakn .bazelrc —config=rbe
Exodus
wix/exodus .bazlerc.remote
Advanced configuration
If you need a more advanced configuration than provided by the basic BuildBuddy toolchain, we recommend exploring Bazel’s bazel-toolchains repo. Itsrbe_autoconfig rule is highly configurable and works nicely with BuildBuddy.
Advanced configuration example
Advanced configuration example
Here’s a quick snippet you can add to your And to your And then run:
WORKSPACE file if using bazel 3.6.0:WORKSPACE
.bazelrc:.bazelrc