Classic remote execution examples
Debugging remote builds can be tricky. These examples provide builds that you can use to test the remote execution capabilities of your worker image.
Getting the test sources
All examples are in a single Bazel module at nativelink/toolchain-examples
.
If you haven’t set up Nix yet, consider consulting the local development setup guide
guide. Then move to the toolchain-examples
directory:
If you running outside of Nix, install bazelisk. Then move to the toolchain-examples
directory:
Preparing the remote execution infrastructure
Port-forward your NativeLink cas/scheduler service to localhost:50051
:
Likely the most straightforward way to test a remote execution image is by creating a custom “test image” that you debug locally. If you have an existing Dockerfile, here is what you need to adjust to test remote execution against a locally running worker:
Then build your image and push it to your localhost:
You can now run the remote execution image locally and run builds against it:
All future invocations may now use the --remote_cache=grpc://localhost:50051
and --remote_executor=grpc://localhost:50051
flags to send builds to the
running container.
Available toolchain configurations
This Bazel module comes with some commonly used toolchains that you can enable
via --config
flags. See the .bazelrc
file in the toolchain-examples
directory for details. Here are your options:
Config | Hermetic | Size | Description |
---|---|---|---|
zig-cc | yes | ~100Mb | Hermetic, but slow. The intended use for this toolchain are projects that need a baseline C++ toolchain, but aren’t “real” C++ projects, such as Go projects with a limited number of C FFIs. |
llvm | no | ~1.5Gb | Not hermetic, but fast and standardized. This toolchain tends to be safe to use for C++ projects as long as you don’t require full hermeticity. Your remote execution image needs to bundle glibc <= 2.34 for this toolchain to work. |
java | yes | ? | This sets the JDK to use a remote JDK. Use this one for Java. |
Notes on how to register your toolchains
Toolchains tend to be complex dependencies and you’ll almost always have bugs in
your toolchain that are build-breaking for some users. If you register your
toolchain in your MODULE.bazel
it’ll turn such bugs into hard errors that
might require deep incisions into your toolchain configuration to fix them.
Instead, register platforms and toolchains in your .bazelrc
file. This way you
give your users the option to opt out of your default toolchain and provide
their own. For instance:
Now --config=sometoolchain
is your happy path, but you keep the ability to
omit the flag so that if your happy path doesn’t work you still have the ability
to build with “unsupported” toolchains.
All examples below require some sort of --config
flag to work with remote
execution.
Minimal example targets
Examples to test whether your worker can function at all.
Since the toolchains used here tend to focus on ease of use rather than performance, expect build times of several minutes even for a small “Hello World” program.
Keep in mind that some remote toolchains first fetch tools to the executor. This can take several minutes and might look like a slow compile action.
C and C++
Python
Go
Rust
Java
All at once
Larger builds
These builds can help fine-tune larger deployments.