Skip to content

Commit

Permalink
Add an experimental remote build execution config based on Angular's (#…
Browse files Browse the repository at this point in the history
…6576)

Add an experimental remote build execution config to run highly parallel builds on remote machines. Currently, only Linux is supported. Adding --config=rbe to any Bazel command (or any yarn command that uses Bazel) will make the build execute remotely. Note that this is only enabled for members of the TFJS team.
  • Loading branch information
mattsoulanille authored Jun 29, 2022
1 parent 70be562 commit 6c9ec9f
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 7 deletions.
29 changes: 27 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,36 @@ build --cxxopt="-fno-rtti"
build --cxxopt="-fno-exceptions"
build --cxxopt="-fomit-frame-pointer"

# The following --define=EXECUTOR=remote will be able to be removed
# once https://github.com/bazelbuild/bazel/issues/7254 is fixed
build:rbe --define=EXECUTOR=remote

build:rbe --jobs=100

# Remote cache config. Users can add credentials in their .bazelrc.user files.
build:remote --remote_cache=remotebuildexecution.googleapis.com --auth_enabled=true --google_default_credentials --remote_instance_name=projects/learnjs-174218/instances/default_instance --project_id=learnjs-174218 --remote_timeout=180s
build:remote --remote_cache=remotebuildexecution.googleapis.com
build:rbe --remote_executor=remotebuildexecution.googleapis.com

# Force remote exeuctions to consider the entire run as linux
build:rbe --cpu=k8
build:rbe --host_cpu=k8

# Toolchain and platform related flags
build:rbe --crosstool_top=@//remote-execution/cpp:cc_toolchain_suite
build:rbe --extra_toolchains=@//remote-execution/cpp:cc_toolchain
build:rbe --extra_execution_platforms=@//remote-execution:platform
build:rbe --host_platform=@//remote-execution:platform
build:rbe --platforms=@//remote-execution:platform

build:remote --remote_instance_name=projects/learnjs-174218/instances/default_instance
build:remote --project_id=learnjs-174218
build:remote --auth_enabled=true
build:remote --google_default_credentials
build:remote --remote_timeout=180s

# Stream build results to the results UI
build:bes --config=remote --bes_backend="buildeventservice.googleapis.com" --bes_timeout=60s --bes_results_url="https://source.cloud.google.com/results/invocations/"
build:rbe --config=remote

# Config for Google Cloud continuous integration that uses default credentials.
build:ci --config=bes
Expand All @@ -30,7 +55,7 @@ run --incompatible_strict_action_env

# Don't use a sandboxed build since it hurts performance.
# When sandboxed, the wasm backend takes hours to build on a 32 core machine.
build --spawn_strategy=worker,local
build --spawn_strategy=remote,worker,local

# Pass BrowserStack credentials
build --action_env=BROWSERSTACK_USERNAME --action_env=BROWSERSTACK_KEY
Expand Down
41 changes: 41 additions & 0 deletions remote-execution/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package(default_visibility = ["//visibility:public"])

platform(
name = "platform",
constraint_values = [
"@bazel_tools//platforms:linux",
"@bazel_tools//platforms:x86_64",
"@bazel_tools//tools/cpp:clang",
],
exec_properties = {
# We use the same docker image for remote builds as we use for CI testing.
"container-image": "docker://gcr.io/learnjs-174218/release@sha256:d85abab6146eaf1e01312bdb9e353a5efa0508b913dccf30fc5e505d009026ff",
# By default in Google Cloud Remote build execution, network access is disabled. We explicitly set the
# property in the platform again in case the default ever changes. Network access is not desirable in
# Bazel builds as it is potential source of flaky tests and therefore also breaks hermeticity.
"dockerNetwork": "off",
},
)

platform(
name = "platform_with_network",
exec_properties = {
# By default we have network access disabled with the `:platform` target. This is an
# additional platform that extends from the default one but enables network access.
# Network is generally not recommended, but for some exceptions, like integration tests
# running a Yarn install, network access is reasonable. In such special cases, Bazel can
# be invoked to run with this platform. It is recommended that exec platforms with network
# access are used in combination with `--sandbox_default_allow_network=false` as this allows
# specific targets to be granted network access, while others will not have access.
"dockerNetwork": "standard",
},
parents = [":platform"],
)

filegroup(
name = "files",
srcs = [
"BUILD.bazel",
"@npm//@angular/dev-infra-private/bazel/remote-execution/cpp:files",
],
)
58 changes: 58 additions & 0 deletions remote-execution/cpp/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
load("@bazel_tools//tools/cpp:cc_toolchain_config.bzl", "cc_toolchain_config")

package(default_visibility = ["//visibility:public"])

filegroup(
name = "files",
srcs = ["BUILD.bazel"],
)

cc_toolchain_suite(
name = "cc_toolchain_suite",
tags = ["manual"],
toolchains = {
"k8": ":cc_compiler_k8",
},
)

toolchain(
name = "cc_toolchain",
exec_compatible_with = [
"@bazel_tools//platforms:linux",
"@bazel_tools//platforms:x86_64",
"@bazel_tools//tools/cpp:clang",
],
target_compatible_with = [
"@bazel_tools//platforms:linux",
"@bazel_tools//platforms:x86_64",
],
toolchain = ":cc_compiler_k8",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

# Basic CC toolchain for k8 remote containers. Based on the default k8
# toolchain provided in Bazel (but unfortunately internal).
# https://github.com/bazelbuild/bazel/blob/c951753097b45cfb9be512c02199aa891b9646b8/tools/cpp/BUILD.tools#L298-L311
cc_toolchain(
name = "cc_compiler_k8",
all_files = ":empty",
ar_files = ":empty",
as_files = ":empty",
compiler_files = ":empty",
dwp_files = ":empty",
linker_files = ":empty",
objcopy_files = ":empty",
strip_files = ":empty",
supports_param_files = 1,
toolchain_config = ":k8_toolchain_config",
toolchain_identifier = "cc-k8-compiler",
)

cc_toolchain_config(
name = "k8_toolchain_config",
compiler = "compiler",
cpu = "local",
)

# Empty filegroup used for defining the CC toolchain.
filegroup(name = "empty")
7 changes: 6 additions & 1 deletion tfjs-converter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ nodejs_test(
],
entry_point = "//tfjs-converter/scripts:test_snippets.ts",
link_workspace_root = True,
tags = ["ci"],
tags = [
"ci",
# Run the test locally since it makes http requests.
"no-remote-exec",
"requires-network",
],
)

tfjs_bundle(
Expand Down
7 changes: 6 additions & 1 deletion tfjs-core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ nodejs_test(
],
entry_point = "//tfjs-core/scripts/test_snippets:test_snippets.ts",
link_workspace_root = True,
tags = ["ci"],
tags = [
"ci",
# Run the test locally since it makes http requests.
"no-remote-exec",
"requires-network",
],
)

nodejs_test(
Expand Down
8 changes: 7 additions & 1 deletion tfjs-core/src/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,14 @@ ts_library(
),
module_name = "@tensorflow/tfjs-core/dist",
deps = [
"@npm//@types",
"@npm//@types/jasmine",
"@npm//@types/long",
"@npm//@types/node",
"@npm//@types/seedrandom",
"@npm//@webgpu/types",
"@npm//jasmine",
"@npm//long",
"@npm//node-fetch",
"@npm//seedrandom",
],
)
Expand Down
1 change: 1 addition & 0 deletions tfjs-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
import './base_side_effects';
// All exports from this package should be in base.
export * from './base';
console.log('foo');
1 change: 1 addition & 0 deletions tfjs-tflite/wasm/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ genrule(
exec_tools = [
"//tfjs-tflite/scripts:download_tflite_web_api",
],
tags = ["no-remote-exec"],
)
4 changes: 2 additions & 2 deletions tools/tfjs_web_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def tfjs_web_test(name, ci = True, args = [], **kwargs):
name = name,
config_file = config_file,
configuration_env_vars = [] if headless else ["DISPLAY"],
tags = ["native"] + tags,
tags = ["native", "no-remote-exec"] + tags,
**kwargs
)

Expand All @@ -118,7 +118,7 @@ def tfjs_web_test(name, ci = True, args = [], **kwargs):
args = args,
)

additional_tags = []
additional_tags = ["no-remote-exec"]
if ci:
# Tag to be run in nightly.
additional_tags.append("nightly")
Expand Down

0 comments on commit 6c9ec9f

Please sign in to comment.