From 6b0243e97d94836767ea8b94a477d7d15ee3bb91 Mon Sep 17 00:00:00 2001 From: Zachary Anderson Date: Thu, 31 Aug 2023 09:34:39 -0700 Subject: [PATCH] RBE (#758) See instructions on https://github.com/flutter/engine/pull/45271 --- build/rbe.cfg | 9 +++++ build/toolchain/android/BUILD.gn | 31 ++++++++++++++-- build/toolchain/gcc_toolchain.gni | 19 ++++++++-- build/toolchain/linux/BUILD.gn | 59 ++++++++++++++++++++++++------- build/toolchain/rbe.gni | 33 +++++++++++++++++ build/toolchain/wasm.gni | 1 + 6 files changed, 134 insertions(+), 18 deletions(-) create mode 100644 build/rbe.cfg create mode 100644 build/toolchain/rbe.gni diff --git a/build/rbe.cfg b/build/rbe.cfg new file mode 100644 index 0000000000..9065cdd893 --- /dev/null +++ b/build/rbe.cfg @@ -0,0 +1,9 @@ +service=remotebuildexecution.googleapis.com:443 +instance=projects/flutter-rbe-prod/instances/default +use_application_default_credentials=true +enable_deps_cache=true +xattr_digest=user.flutter.rbe.digest.sha256 +server_address=unix:///tmp/reproxy.sock +log_dir=/tmp +proxy_log_dir=/tmp +log_format=reducedtext diff --git a/build/toolchain/android/BUILD.gn b/build/toolchain/android/BUILD.gn index eb1cce98f7..bf6f19bf23 100644 --- a/build/toolchain/android/BUILD.gn +++ b/build/toolchain/android/BUILD.gn @@ -7,6 +7,7 @@ import("//build/toolchain/ccache.gni") import("//build/toolchain/clang.gni") import("//build/toolchain/gcc_toolchain.gni") import("//build/toolchain/goma.gni") +import("//build/toolchain/rbe.gni") # The Android GCC toolchains share most of the same parameters, so we have this # wrapper around gcc_toolchain to avoid duplication of logic. @@ -35,10 +36,31 @@ template("android_gcc_toolchain") { if (use_goma) { assert(!use_ccache, "Goma and ccache can't be used together.") compiler_prefix = "$goma_dir/gomacc " + link_prefix = "$goma_dir/gomacc " + } else if (use_rbe) { + assert(!use_goma) + rewrapper_args = [ + "$rbe_dir/rewrapper", + "--server_address=$rbe_server_address", + "--exec_strategy=$rbe_exec_strategy", + "--dial_timeout=$rbe_dial_timeout", + "--exec_root=$rbe_exec_root", + "--platform=$rbe_platform", + ] + compiler_args = rewrapper_args + [ + "--labels=type=compile,compiler=clang,lang=cpp ", + ] + link_args = rewrapper_args + [ + "--labels=type=link,tool=clang ", + ] + compiler_prefix = string_join(" ", compiler_args) + link_prefix = string_join(" ", link_args) } else if (use_ccache) { compiler_prefix = "ccache " + link_prefix = "ccache " } else { compiler_prefix = "" + link_prefix = "" } is_clang = invoker.is_clang @@ -54,18 +76,21 @@ template("android_gcc_toolchain") { prefix = rebase_path("//buildtools/$host_dir/clang/bin", root_build_dir) + asm = prefix + "/clang" cc = compiler_prefix + prefix + "/clang" cxx = compiler_prefix + prefix + "/clang++" ar = prefix + "/llvm-ar" + ld = link_prefix + prefix + "/clang++" } else { + asm = tool_prefix + "gcc" cc = compiler_prefix + tool_prefix + "gcc" cxx = compiler_prefix + tool_prefix + "g++" ar = tool_prefix + "ar" + ld = link_prefix + tool_prefix + "g++" } - ld = cxx - readelf = compiler_prefix + tool_prefix + "readelf" - nm = compiler_prefix + tool_prefix + "nm" + readelf = tool_prefix + "readelf" + nm = tool_prefix + "nm" toolchain_os = "android" toolchain_cpu = invoker.toolchain_cpu diff --git a/build/toolchain/gcc_toolchain.gni b/build/toolchain/gcc_toolchain.gni index d0922eac68..d1fb2901b5 100644 --- a/build/toolchain/gcc_toolchain.gni +++ b/build/toolchain/gcc_toolchain.gni @@ -4,6 +4,7 @@ import("//build/toolchain/clang.gni") import("//build/toolchain/clang_static_analyzer.gni") +import("//build/toolchain/rbe.gni") # Path to the Clang static analysis wrapper script. analyzer_wrapper = @@ -14,6 +15,7 @@ analyzer_wrapper = # (including clang). # # It requires the following variables specifying the executables to run: +# - asm # - cc # - cxx # - ar @@ -50,6 +52,7 @@ analyzer_wrapper = # when specified. template("gcc_toolchain") { toolchain(target_name) { + assert(defined(invoker.asm), "gcc_toolchain() must specify a \"asm\" value") assert(defined(invoker.cc), "gcc_toolchain() must specify a \"cc\" value") assert(defined(invoker.cxx), "gcc_toolchain() must specify a \"cxx\" value") assert(defined(invoker.ar), "gcc_toolchain() must specify a \"ar\" value") @@ -76,6 +79,7 @@ template("gcc_toolchain") { # We can't do string interpolation ($ in strings) on things with dots in # them. To allow us to use $cc below, for example, we create copies of # these values in our scope. + asm = invoker.asm cc = compiler_prefix + invoker.cc cxx = compiler_prefix + invoker.cxx ar = invoker.ar @@ -120,6 +124,12 @@ template("gcc_toolchain") { tool("cc") { depfile = "{{output}}.d" command = "$cc -MD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} $coverage_flags -c {{source}} -o {{output}}" + if (use_rbe) { + # The depfile generated on an RBE worker can contain absolute paths. + # This sed command strips off the prefix, and rewrites to be + # relative to the buildroot. + command += " && sed -i 's@/b/f/w@../..@g' $depfile" + } depsformat = "gcc" description = "CC {{output}}" outputs = [ @@ -130,6 +140,9 @@ template("gcc_toolchain") { tool("cxx") { depfile = "{{output}}.d" command = "$cxx -MD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} $coverage_flags -c {{source}} -o {{output}}" + if (use_rbe) { + command += " && sed -i 's@/b/f/w@../..@g' $depfile" + } depsformat = "gcc" description = "CXX {{output}}" outputs = [ @@ -138,9 +151,11 @@ template("gcc_toolchain") { } tool("asm") { - # For GCC we can just use the C compiler to compile assembly. depfile = "{{output}}.d" - command = "$cc -MD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} {{cflags}} {{cflags_c}} $coverage_flags -c {{source}} -o {{output}}" + command = "$asm -MD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} {{cflags}} {{cflags_c}} $coverage_flags -c {{source}} -o {{output}}" + if (use_rbe) { + command += " && sed -i 's@/b/f/w@../..@g' $depfile" + } depsformat = "gcc" description = "ASM {{output}}" outputs = [ diff --git a/build/toolchain/linux/BUILD.gn b/build/toolchain/linux/BUILD.gn index 05630d01e7..dec1ab833d 100644 --- a/build/toolchain/linux/BUILD.gn +++ b/build/toolchain/linux/BUILD.gn @@ -6,19 +6,40 @@ import("//build/config/sysroot.gni") import("//build/toolchain/ccache.gni") import("//build/toolchain/gcc_toolchain.gni") import("//build/toolchain/goma.gni") +import("//build/toolchain/rbe.gni") declare_args() { toolchain_prefix = "" - # TODO(zra): Add an argument for overriding the host toolchain. } if (use_goma) { assert(!use_ccache, "Goma and ccache can't be used together.") compiler_prefix = "$goma_dir/gomacc " + link_prefix = "$goma_dir/gomacc " +} else if (use_rbe) { + assert(!use_goma) + rewrapper_args = [ + "$rbe_dir/rewrapper", + "--server_address=$rbe_server_address", + "--exec_strategy=$rbe_exec_strategy", + "--dial_timeout=$rbe_dial_timeout", + "--exec_root=$rbe_exec_root", + "--platform=$rbe_platform", + ] + compiler_args = rewrapper_args + [ + "--labels=type=compile,compiler=clang,lang=cpp ", + ] + link_args = rewrapper_args + [ + "--labels=type=link,tool=clang ", + ] + compiler_prefix = string_join(" ", compiler_args) + link_prefix = string_join(" ", link_args) } else if (use_ccache) { compiler_prefix = "ccache " + link_prefix = "ccache " } else { compiler_prefix = "" + link_prefix = "" } if (host_cpu == "arm64") { @@ -35,11 +56,12 @@ gcc_toolchain("arm") { prefix = toolchain_prefix } + asm = "${prefix}gcc" cc = "${compiler_prefix}${prefix}gcc" cxx = "${compiler_prefix}${prefix}g++" ar = "${prefix}ar" - ld = cxx + ld = "${link_prefix}${prefix}g++" readelf = "${prefix}readelf" nm = "${prefix}nm" strip = "${prefix}strip" @@ -51,13 +73,14 @@ gcc_toolchain("arm") { gcc_toolchain("clang_arm") { prefix = rebased_clang_dir + asm = "${prefix}/clang" cc = "${compiler_prefix}${prefix}/clang" cxx = "${compiler_prefix}${prefix}/clang++" readelf = "${prefix}/llvm-readelf" nm = "${prefix}/llvm-nm" ar = "${prefix}/llvm-ar" - ld = cxx + ld = "${link_prefix}${prefix}/clang++" llvm_objcopy = "${prefix}/llvm-objcopy" toolchain_cpu = "arm" @@ -71,11 +94,12 @@ gcc_toolchain("arm64") { prefix = toolchain_prefix } + asm = "${prefix}gcc" cc = "${compiler_prefix}${prefix}gcc" cxx = "${compiler_prefix}${prefix}g++" ar = "${prefix}ar" - ld = cxx + ld = "${link_prefix}${prefix}g++" readelf = "${prefix}readelf" nm = "${prefix}nm" strip = "${prefix}strip" @@ -87,13 +111,14 @@ gcc_toolchain("arm64") { gcc_toolchain("clang_arm64") { prefix = rebased_clang_dir + asm = "${prefix}/clang" cc = "${compiler_prefix}${prefix}/clang" cxx = "${compiler_prefix}${prefix}/clang++" readelf = "readelf" nm = "${prefix}/llvm-nm" ar = "${prefix}/llvm-ar" - ld = cxx + ld = "${link_prefix}${prefix}/clang++" llvm_objcopy = "${prefix}/llvm-objcopy" toolchain_cpu = "arm64" @@ -103,13 +128,14 @@ gcc_toolchain("clang_arm64") { gcc_toolchain("clang_x86") { prefix = rebased_clang_dir + asm = "${prefix}/clang" cc = "${compiler_prefix}${prefix}/clang" cxx = "${compiler_prefix}${prefix}/clang++" readelf = "${prefix}/llvm-readelf" nm = "${prefix}/llvm-nm" ar = "${prefix}/llvm-ar" - ld = cxx + ld = "${link_prefix}${prefix}/clang++" llvm_objcopy = "${prefix}/llvm-objcopy" toolchain_cpu = "x86" @@ -119,13 +145,14 @@ gcc_toolchain("clang_x86") { gcc_toolchain("x86") { prefix = "" + asm = "${prefix}gcc" cc = "${compiler_prefix}${prefix}gcc" cxx = "${compiler_prefix}${prefix}g++" readelf = "${prefix}readelf" nm = "${prefix}nm" ar = "${prefix}ar" - ld = cxx + ld = "${link_prefix}${prefix}g++" strip = "${prefix}strip" toolchain_cpu = "x86" @@ -135,13 +162,14 @@ gcc_toolchain("x86") { gcc_toolchain("clang_x64") { prefix = rebased_clang_dir + asm = "${prefix}/clang" cc = "${compiler_prefix}${prefix}/clang" cxx = "${compiler_prefix}${prefix}/clang++" readelf = "${prefix}/llvm-readelf" nm = "${prefix}/llvm-nm" ar = "${prefix}/llvm-ar" - ld = cxx + ld = "${link_prefix}${prefix}/clang++" llvm_objcopy = "${prefix}/llvm-objcopy" toolchain_cpu = "x64" @@ -151,13 +179,14 @@ gcc_toolchain("clang_x64") { gcc_toolchain("x64") { prefix = "" + asm = "${prefix}gcc" cc = "${compiler_prefix}${prefix}gcc" cxx = "${compiler_prefix}${prefix}g++" readelf = "${prefix}readelf" nm = "${prefix}nm" ar = "${prefix}ar" - ld = cxx + ld = "${link_prefix}${prefix}g++" strip = "${prefix}strip" toolchain_cpu = "x64" @@ -171,11 +200,12 @@ gcc_toolchain("riscv32") { prefix = toolchain_prefix } + asm = "${prefix}gcc" cc = "${compiler_prefix}${prefix}gcc" cxx = "${compiler_prefix}${prefix}g++" ar = "${prefix}ar" - ld = cxx + ld = "${link_prefix}${prefix}g++" readelf = "${prefix}readelf" nm = "${prefix}nm" strip = "${prefix}strip" @@ -187,13 +217,14 @@ gcc_toolchain("riscv32") { gcc_toolchain("clang_riscv32") { prefix = rebased_clang_dir + asm = "${prefix}/clang" cc = "${compiler_prefix}${prefix}/clang" cxx = "${compiler_prefix}${prefix}/clang++" readelf = "readelf" nm = "${prefix}/llvm-nm" ar = "${prefix}/llvm-ar" - ld = cxx + ld = "${link_prefix}${prefix}/clang++" llvm_objcopy = "${prefix}/llvm-objcopy" toolchain_cpu = "riscv32" @@ -207,11 +238,12 @@ gcc_toolchain("riscv64") { prefix = toolchain_prefix } + asm = "${prefix}gcc" cc = "${compiler_prefix}${prefix}gcc" cxx = "${compiler_prefix}${prefix}g++" ar = "${prefix}ar" - ld = cxx + ld = "${link_prefix}${prefix}g++" readelf = "${prefix}readelf" nm = "${prefix}nm" strip = "${prefix}strip" @@ -223,13 +255,14 @@ gcc_toolchain("riscv64") { gcc_toolchain("clang_riscv64") { prefix = rebased_clang_dir + asm = "${prefix}/clang" cc = "${compiler_prefix}${prefix}/clang" cxx = "${compiler_prefix}${prefix}/clang++" readelf = "readelf" nm = "${prefix}/llvm-nm" ar = "${prefix}/llvm-ar" - ld = cxx + ld = "${link_prefix}${prefix}/clang++" llvm_objcopy = "${prefix}/llvm-objcopy" toolchain_cpu = "riscv64" diff --git a/build/toolchain/rbe.gni b/build/toolchain/rbe.gni new file mode 100644 index 0000000000..0f29e52fd1 --- /dev/null +++ b/build/toolchain/rbe.gni @@ -0,0 +1,33 @@ +# Copyright (c) 2013 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# Defines the configuration of RBE. + +declare_args() { + # Set to true to enable distributed compilation using Goma. + use_rbe = false + + # Set to true to create symlinks to Xcode toolchain/SDK directories. + # + # RBE does not allow for include paths outside of the buildroot. Creating + # symlinks is a work around for that when using a local Xcode toolchain. + # This property should not be set to true on LUCI. + # + # If use_goma is false, this property is ignored. + # create_xcode_symlinks = false + + rbe_exec_root = rebase_path("//") + + rbe_server_address = "unix:///tmp/reproxy.sock" + + rbe_exec_strategy = "remote_local_fallback" + + rbe_dial_timeout = "30s" + + rbe_platform = "container-image=docker://gcr.io/cloud-marketplace/google/debian11@sha256:69e2789c9f3d28c6a0f13b25062c240ee7772be1f5e6d41bb4680b63eae6b304" + + # TODO(zanderso): In the gn script, set the default value based on the host + # platform. + rbe_dir = rebase_path("//buildtools/linux-x64/reclient") +} diff --git a/build/toolchain/wasm.gni b/build/toolchain/wasm.gni index 8fc0774ab3..859d063586 100644 --- a/build/toolchain/wasm.gni +++ b/build/toolchain/wasm.gni @@ -39,6 +39,7 @@ template("wasm_toolchain") { ar = "$compiler_prefix$emsdk_dir/upstream/emscripten/emar --em-config $em_config_path" cc = "$compiler_prefix$emsdk_dir/upstream/emscripten/emcc --em-config $em_config_path" cxx = "$compiler_prefix$emsdk_dir/upstream/emscripten/em++ --em-config $em_config_path" + asm = cc # emscripten emits this .worker.js file conditionally depending on whether # pthreads are on or not. Unfortunately, there is no way to conditionally