This example demonstrates use of EngFlow RE for a simple Rust project built with Buck2 using the prelude.
It is based on two existing samples in the Buck2 upstream repo:
- Simple rust project with prelude - https://github.com/facebook/buck2/tree/main/examples/with_prelude/rust
- Buck2 remote execution integration with EngFlow - https://github.com/facebook/buck2/tree/main/examples/remote_execution/engflow
In the platforms cell we specify:
In the platforms cell we specify:
- The platform used for remote execution in this project
root//platforms:remote_platform, which includes the definition of the Docker image used for remote execution, and that defines constraints for targets to run in the remote execution environment. This platform provides anExecutionPlatformRegistrationInfoaConfigurationInfoand aPlatformInfoto be able to be used in the.buckconfig. - The action keys
root//platforms:remote_execution_action_keys, which provides a defaultBuildModeInfothat is needed for RE of tests to function properly. - The platform
imageconfigured inplatforms/defs.bzl, notably, uses a different image than other Buck2 samples in this repo. Specifically, it uses a public AWS image that hasrustpreinstalled. This is because Buck2 rust rules do not include a hermetic rust toolchain. We use a bookworm image with rust pre-installed. Image details can be found in https://gallery.ecr.aws/docker/library/rust. The Dockerfile can be found in https://github.com/rust-lang/docker-rust/blob/700c4f146427808cfb1e07a646e4afabbe99da4f/stable/bullseye/Dockerfile. If a different version ofrustor other tools is needed you should create your own image and publish it to a repo that is accessible from the cluster.
In the toolchains cell we specify:
- The remote rust toolchain
root//toolchains:remote_rust_toolchainwhich is compatible with the remote execution environment. This toolchain is configured with therustc_target_tripleto match the remote execution environment, and thecompiler,clippy_driverandrustdocattrs are set to point to the location of therustcbinary in the image used for remote execution. - The c++ toolchain
root//toolchains:cxx_tools_info_toolchainthat is compatible with the remote execution environment. - The clang tools,
root//toolchains:path_clang_tools, which is used by the c++ toolchain, and specifies the tools installed in the Docker image. - The remote test execution toolchain,
root//toolchains:remote_test_execution_toolchain. This toolchain defines platform options in the form ofcapabilities. Critically these include thecontainer-image. This toolchain is identical to the one in thebuck2/cppsample in this repo.
The src, bin and test cells:
-
Contain a copied version of https://github.com/facebook/buck2/tree/main/examples/with_prelude/rust that works with Buck2 and RE as configured in this sample project.
-
Key changes for remote execution in the top level
BUCKfile include setting environment variables to select the pre-installed rust toolchain in the container and set a custom value forHOME. This custom value is needed asrustpattempts to create a directory in theHOMElocation and we prefer this happen inside thebuck-out/directory to guarantee actions do not modify any content outside of their scratch directory.
To test the project with RE run (after setting up .buckconfig as indicated below):
buck2 test --remote-only //:test
You can also build the main for this sample by running:
buck2 build --remote-only //:main
Note the use of --remote-only to indicate remote execution should be used for the build / test command.
The EngFlow endpoint and certificate should be configured as the following:
[buck2_re_client]
engine_address = <CLUSTER_NAME>.cluster.engflow.com
action_cache_address = <CLUSTER_NAME>.cluster.engflow.com
cas_address = <CLUSTER_NAME>.cluster.engflow.com
http_headers = <AUTH_HTTP_HEADERS>To obtain the value of <AUTH_HTTP_HEADERS>, log into https://<CLUSTER_NAME>.cluster.engflow.com/gettingstarted and obtain the value of x-engflow-auth-token in section Method 2: JWT, take note of this value. Then set AUTH_HTTP_HEADERS with the value `x-engflow-auth-method:jwt-v0,x-engflow-auth-token:<JWT_TOKEN_FROM_GETTINGSTARTED_PAGE>.
Note for CI runs, the auth method used is Github Tokens.