Bazel First-Time Setup

Steps to Configure Bazel to Connect to a Cluster

This document describes how to configure Bazel to connect to an EngFlow Remote Execution cluster.

1. Modify your WORKSPACE file by adding the following statements:

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
    name = "bazel_toolchains",
    commit = "810ac3490df9113cfaa50a4ee3d204a29c81a24c",
    remote = "https://github.com/bazelbuild/bazel-toolchains.git",
)

# Perform auto-detection of the C++ and Java toolchains, which can take about
# a minute.
load("@bazel_toolchains//rules:rbe_repo.bzl", "rbe_autoconfig")
rbe_autoconfig(
    name = "engflow_remote_config",
    detect_java_home = True,
    registry = "<DOCKER_REGISTRY>",  # TODO: use actual registry address
    repository = "<REPOSITORY>",     # TODO: use actual repository name
    digest = "sha256:<DIGEST>",      # TODO: use the actual digest; or use tag="latest"
)

Note: rbe_autoconfig will fail if it cannot pull the container from the registry. If you don’t have a container registry to push to, you can run a local Docker registry and push there.

2. Set up your ~/.bazelrc.

Add all of these entries to ~/.bazelrc. You can change any flag to your liking.

  1. Add common flags:

    build:engflow --define=EXECUTOR=remote
    build:engflow --disk_cache=
    build:engflow --experimental_inmemory_dotd_files
    build:engflow --experimental_inmemory_jdeps_files
    build:engflow --incompatible_strict_action_env=true
    build:engflow --remote_timeout=600
    build:engflow --spawn_strategy=remote,local
    
  2. Add platform and toolchain flags.

    build:engflow --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
    build:engflow --crosstool_top=@engflow_remote_config//cc:toolchain
    build:engflow --extra_execution_platforms=@engflow_remote_config//config:platform
    build:engflow --extra_toolchains=@engflow_remote_config//config:cc-toolchain
    build:engflow --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_java11
    build:engflow --host_javabase=@engflow_remote_config//java:jdk
    build:engflow --host_platform=@engflow_remote_config//config:platform
    build:engflow --java_toolchain=@bazel_tools//tools/jdk:toolchain_java11
    build:engflow --javabase=@engflow_remote_config//java:jdk
    build:engflow --platforms=@engflow_remote_config//config:platform
    
  3. Add the remote executor flags. Use the host name or IP address of the Load Balancer.

    • If you use TLS with our certificate (engflow-ca.crt):

      build:engflow --remote_executor=grpcs://demo.engflow.com:<PORT>
      build:engflow --tls_certificate=<PATH>/engflow-remote-execution/engflow-ca.crt
      
    • If you don’t use TLS:

      build:engflow --remote_executor=grpc://<LOAD_BALANCER_IP>:<PORT>
      

Usage

We recommend using the latest available Bazel version.

bazel build --config=engflow //foo:bar
2021-09-21