Bazel: Add RBE support

The Bazel build can be used with Google's Remote Build Execution.

This needs the following setup steps:

  $ gcloud auth application-default login
  $ gcloud services enable remotebuildexecution.googleapis.com  --project=${PROJECT}

Create a worker pool. The instances should have at least 4 CPUs each
for adequate performance.

  $ gcloud alpha remote-build-execution worker-pools create default \
    --project=${PROJECT} \
    --instance=default_instance \
    --worker-count=50 \
    --machine-type=e2-standard-4 \
    --disk-size=200

To use RBE, execute

  $ bazel test --config=remote \
    --remote_instance_name=projects/${PROJECT}/instances/default_instance \
    //...

Change-Id: I988f61e342dab2136d8752ace945a4ed91a4189a
This commit is contained in:
David Ostrovsky 2022-01-19 19:26:54 +01:00 committed by David Ostrovsky
parent be732c16ab
commit 969601c742
3 changed files with 89 additions and 0 deletions

View File

@ -10,12 +10,24 @@ build --java_runtime_version=remotejdk_11
build --tool_java_language_version=11
build --tool_java_runtime_version=remotejdk_11
# Builds and executes on RBE using remotejdk_11
build:remote --java_language_version=11
build:remote --java_runtime_version=remotejdk_11
build:remote --tool_java_language_version=11
build:remote --tool_java_runtime_version=remotejdk_11
# Builds using remote_jdk17, executes using remote_jdk11 or local_jdk
build:java17 --java_language_version=17
build:java17 --java_runtime_version=remotejdk_17
build:java17 --tool_java_language_version=17
build:java17 --tool_java_runtime_version=remotejdk_17
# Builds and executes on RBE using remotejdk_17
build:remote17 --java_language_version=17
build:remote17 --java_runtime_version=remotejdk_17
build:remote17 --tool_java_language_version=17
build:remote17 --tool_java_runtime_version=remotejdk_17
test --build_tests_only
test --test_output=errors

View File

@ -10,6 +10,16 @@ load(
"maven_jar",
)
http_archive(
name = "rbe_jdk11",
sha256 = "766796de71916118e528b9f4334c29c9c9b4e926227bf3264dee555e6a4306c8",
strip_prefix = "rbe_autoconfig-2.0.0",
urls = [
"https://gerrit-bazel.storage.googleapis.com/rbe_autoconfig/v2.0.0.tar.gz",
"https://github.com/davido/rbe_autoconfig/archive/v2.0.0.tar.gz",
],
)
register_toolchains("//tools:error_prone_warnings_toolchain_java11_definition")
register_toolchains("//tools:error_prone_warnings_toolchain_java17_definition")

67
tools/remote-bazelrc Normal file
View File

@ -0,0 +1,67 @@
# Copyright 2022 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This file is auto-generated from release/bazelrc.tpl and should not be
# modified directly.
# This .bazelrc file contains all of the flags required for the provided
# toolchain with Remote Build Execution.
#
# This .bazelrc file also contains all of the flags required for the local
# docker sandboxing.
# Depending on how many machines are in the remote execution instance, setting
# this higher can make builds faster by allowing more jobs to run in parallel.
# Setting it too high can result in jobs that timeout, however, while waiting
# for a remote machine to execute them.
build:remote --jobs=200
build:remote --disk_cache=
# Set several flags related to specifying the platform, toolchain and java
# properties.
build:remote --host_javabase=@rbe_jdk11//java:jdk
build:remote --javabase=@rbe_jdk11//java:jdk
build:remote --crosstool_top=@rbe_jdk11//cc:toolchain
build:remote --extra_toolchains=@rbe_jdk11//config:cc-toolchain
build:remote --extra_execution_platforms=@rbe_jdk11//config:platform
build:remote --host_platform=@rbe_jdk11//config:platform
build:remote --platforms=@rbe_jdk11//config:platform
build:remote --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
# Set various strategies so that all actions execute remotely. Mixing remote
# and local execution will lead to errors unless the toolchain and remote
# machine exactly match the host machine.
build:remote --define=EXECUTOR=remote
# Enable the remote cache so action results can be shared across machines,
# developers, and workspaces.
build:remote --remote_cache=remotebuildexecution.googleapis.com
# Enable remote execution so actions are performed on the remote systems.
build:remote --remote_executor=remotebuildexecution.googleapis.com
# Set a higher timeout value, just in case.
build:remote --remote_timeout=3600
# Enable authentication. This will pick up application default credentials by
# default. You can use --auth_credentials=some_file.json to use a service
# account credential instead.
build:remote --google_default_credentials
# The following flags enable the remote cache so action results can be shared
# across machines, developers, and workspaces.
build:remote-cache --remote_cache=remotebuildexecution.googleapis.com
build:remote-cache --tls_enabled=true
build:remote-cache --remote_timeout=3600
build:remote-cache --auth_enabled=true