diff --git a/build/config/android/BUILD.gn b/build/config/android/BUILD.gn index 43b761e7c1..1aaccde17e 100644 --- a/build/config/android/BUILD.gn +++ b/build/config/android/BUILD.gn @@ -8,7 +8,7 @@ import("//build/config/sysroot.gni") config("sdk") { if (sysroot != "") { cflags = [ "--sysroot=" + sysroot ] - ldflags = [ "-L" + rebase_path("$android_lib") ] + ldflags = [ "-L" + rebase_path("$android_lib", root_build_dir) ] # Need to get some linker flags out of the sysroot. sysroot_ld_path = rebase_path("//build/config/linux/sysroot_ld_path.py") diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn index e22ac440d8..16f5ccb7ef 100644 --- a/build/config/compiler/BUILD.gn +++ b/build/config/compiler/BUILD.gn @@ -164,17 +164,28 @@ config("compiler") { # These flags are shared between the C compiler and linker. common_mac_flags = [] + if (is_mac) { + if (current_cpu == "arm64") { + common_mac_flags += [ "--target=arm64-apple-macos" ] + } else if (current_cpu == "x64") { + common_mac_flags += [ "--target=x86_64-apple-macos" ] + } + } + + if (is_ios) { + if (current_cpu == "arm64") { + common_mac_flags += [ "--target=arm64-apple-darwin" ] + } else if (current_cpu == "x64") { + common_mac_flags += [ "--target=x86_64-apple-darwin" ] + } + } + # CPU architecture. if (current_cpu == "x64") { common_mac_flags += [ "-arch", "x86_64", ] - } else if (current_cpu == "x86") { - common_mac_flags += [ - "-arch", - "i386", - ] } else if (current_cpu == "arm64") { common_mac_flags += [ "-arch", diff --git a/build/config/ios/ios_sdk.gni b/build/config/ios/ios_sdk.gni index 06b91a5e05..1d71239752 100644 --- a/build/config/ios/ios_sdk.gni +++ b/build/config/ios/ios_sdk.gni @@ -3,6 +3,7 @@ # found in the LICENSE file. import("//build/toolchain/goma.gni") +import("//build/toolchain/rbe.gni") declare_args() { # SDK path to use. When empty this will use the default SDK based on the @@ -30,10 +31,10 @@ declare_args() { if (ios_sdk_path == "") { ios_sdk_args = [] - if (use_goma && create_xcode_symlinks) { + if ((use_goma || use_rbe) && create_xcode_symlinks) { ios_sdk_args += [ "--symlink", - rebase_path(root_gen_dir), + rebase_path("//flutter/prebuilts"), ] } if (!use_ios_simulator && ios_device_sdk_path == "") { diff --git a/build/config/mac/mac_sdk.gni b/build/config/mac/mac_sdk.gni index c9ffa59229..ed23dd5c04 100644 --- a/build/config/mac/mac_sdk.gni +++ b/build/config/mac/mac_sdk.gni @@ -3,6 +3,7 @@ # found in the LICENSE file. import("//build/toolchain/goma.gni") +import("//build/toolchain/rbe.gni") declare_args() { # Minimum supported version of the Mac SDK. @@ -20,11 +21,11 @@ declare_args() { if (mac_sdk_path == "") { find_sdk_args = [] - if (use_goma && create_xcode_symlinks) { + if ((use_goma || use_rbe) && create_xcode_symlinks) { # RBE has a restriction that paths cannot come from outside the build root. find_sdk_args += [ "--symlink", - rebase_path(root_gen_dir), + rebase_path("//flutter/prebuilts"), ] } find_sdk_args += [ diff --git a/build/rbe.cfg b/build/rbe.cfg deleted file mode 100644 index 9065cdd893..0000000000 --- a/build/rbe.cfg +++ /dev/null @@ -1,9 +0,0 @@ -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 2deb10c949..8be0aa8602 100644 --- a/build/toolchain/android/BUILD.gn +++ b/build/toolchain/android/BUILD.gn @@ -40,22 +40,14 @@ template("android_gcc_toolchain") { tool_prefix = rebase_path(invoker.tool_prefix, root_build_dir) if (use_goma) { + assert(!use_rbe, "Goma and RBE can't be used together.") 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 " ] + rewrapper_command + [ "--labels=type=compile,compiler=clang,lang=cpp " ] + link_args = rewrapper_command + [ "--labels=type=link,tool=clang " ] compiler_prefix = string_join(" ", compiler_args) link_prefix = string_join(" ", link_args) } else if (use_ccache) { diff --git a/build/toolchain/linux/BUILD.gn b/build/toolchain/linux/BUILD.gn index 8b20ea386a..282b524474 100644 --- a/build/toolchain/linux/BUILD.gn +++ b/build/toolchain/linux/BUILD.gn @@ -13,22 +13,14 @@ declare_args() { } if (use_goma) { + assert(!use_rbe, "Goma and RBE can't be used together.") 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 " ] + rewrapper_command + [ "--labels=type=compile,compiler=clang,lang=cpp " ] + link_args = rewrapper_command + [ "--labels=type=link,tool=clang " ] compiler_prefix = string_join(" ", compiler_args) link_prefix = string_join(" ", link_args) } else if (use_ccache) { diff --git a/build/toolchain/mac/BUILD.gn b/build/toolchain/mac/BUILD.gn index 643bb42d46..a5712ed64c 100644 --- a/build/toolchain/mac/BUILD.gn +++ b/build/toolchain/mac/BUILD.gn @@ -2,26 +2,15 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# TODO(brettw) Use "gcc_toolchain.gni" like the Linux toolchains. This requires -# some enhancements since the commands on Mac are slightly different than on -# Linux. +assert(host_os == "mac") import("//build/config/ios/ios_sdk.gni") import("//build/config/mac/mac_sdk.gni") -import("../goma.gni") - -assert(host_os == "mac") - import("//build/config/sysroot.gni") import("//build/toolchain/clang.gni") import("//build/toolchain/clang_static_analyzer.gni") import("//build/toolchain/goma.gni") - -if (use_goma) { - goma_prefix = "$goma_dir/gomacc " -} else { - goma_prefix = "" -} +import("//build/toolchain/rbe.gni") # Goma doesn't support the host-arm64 toolchain, so continue using Rosetta. if (host_cpu == "arm64" && !use_goma) { @@ -32,12 +21,37 @@ if (host_cpu == "arm64" && !use_goma) { rebase_path("//buildtools/mac-x64/clang/bin", root_build_dir) } +if (use_goma) { + assert(!use_rbe, "Goma and RBE can't be used together.") + cxx_prefix = "$goma_dir/gomacc " + objc_prefix = "$goma_dir/gomacc " + link_prefix = "$goma_dir/gomacc " +} else if (use_rbe) { + compiler_args = rewrapper_command + [ + "--labels=type=compile,compiler=clang,lang=cpp ", + ] + link_args = rewrapper_command + [ + "--labels=type=link,tool=clang ", + ] + cxx_prefix = string_join(" ", compiler_args) + # RBE does not support objc out of the box. + objc_prefix = "" + # Remote links time out without reporting an actionable error. + link_prefix = "" +} else { + cxx_prefix = "" + objc_prefix = "" + link_prefix = "" +} + # Shared toolchain definition. Invocations should set toolchain_os to set the # build args in this definition. template("mac_toolchain") { toolchain(target_name) { + assert(defined(invoker.asm), "mac_toolchain() must specify a \"asm\" value") assert(defined(invoker.cc), "mac_toolchain() must specify a \"cc\" value") assert(defined(invoker.cxx), "mac_toolchain() must specify a \"cxx\" value") + assert(defined(invoker.objc), "mac_toolchain() must specify a \"objc\" value") assert(defined(invoker.ld), "mac_toolchain() must specify a \"ld\" value") assert(defined(invoker.ar), "mac_toolchain() must specify a \"ar\" value") assert(defined(invoker.toolchain_cpu), @@ -48,10 +62,12 @@ template("mac_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. + ar = invoker.ar + asm = invoker.asm cc = invoker.cc cxx = invoker.cxx + objc = invoker.objc ld = invoker.ld - ar = invoker.ar if (use_clang_static_analyzer) { analyzer_wrapper = @@ -78,7 +94,10 @@ template("mac_toolchain") { tool("cc") { depfile = "{{output}}.d" - command = "$goma_prefix $cc -MD -MF $depfile {{defines}} {{include_dirs}} $sysroot_flags {{cflags}} {{cflags_c}} $coverage_flags -c {{source}} -o {{output}}" + command = "$cc -MD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} $sysroot_flags $coverage_flags -c {{source}} -o {{output}}" + if (use_rbe || use_goma) { + command += " && sed -i '' -e 's@/b/f/w@../..@g' $depfile" + } depsformat = "gcc" description = "CC {{output}}" outputs = @@ -87,7 +106,10 @@ template("mac_toolchain") { tool("cxx") { depfile = "{{output}}.d" - command = "$goma_prefix $cxx -MD -MF $depfile {{defines}} {{include_dirs}} $sysroot_flags {{cflags}} {{cflags_cc}} $coverage_flags -c {{source}} -o {{output}}" + command = "$cxx -MD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} $sysroot_flags $coverage_flags -c {{source}} -o {{output}}" + if (use_rbe || use_goma) { + command += " && sed -i '' -e 's@/b/f/w@../..@g' $depfile" + } depsformat = "gcc" description = "CXX {{output}}" outputs = @@ -95,9 +117,11 @@ template("mac_toolchain") { } tool("asm") { - # For GCC we can just use the C compiler to compile assembly. depfile = "{{output}}.d" - command = "$goma_prefix $cc -MD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} $sysroot_flags {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}" + command = "$asm -MD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} {{cflags}} {{cflags_c}} $sysroot_flags -c {{source}} -o {{output}}" + if (use_rbe || use_goma) { + command += " && sed -i '' -e 's@/b/f/w@../..@g' $depfile" + } depsformat = "gcc" description = "ASM {{output}}" outputs = @@ -106,7 +130,10 @@ template("mac_toolchain") { tool("objc") { depfile = "{{output}}.d" - command = "$goma_prefix $cxx -MD -MF $depfile {{defines}} {{include_dirs}} $sysroot_flags {{cflags}} {{cflags_c}} {{cflags_objc}} $coverage_flags -c {{source}} -o {{output}}" + command = "$objc -MD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} {{cflags_objc}} $sysroot_flags $coverage_flags -c {{source}} -o {{output}}" + if (use_rbe || use_goma) { + command += " && sed -i '' -e 's@/b/f/w@../..@g' $depfile" + } depsformat = "gcc" description = "OBJC {{output}}" outputs = @@ -115,7 +142,10 @@ template("mac_toolchain") { tool("objcxx") { depfile = "{{output}}.d" - command = "$goma_prefix $cxx -MD -MF $depfile {{defines}} {{include_dirs}} $sysroot_flags {{cflags}} {{cflags_cc}} {{cflags_objcc}} $coverage_flags -c {{source}} -o {{output}}" + command = "$objc -MD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objcc}} $sysroot_flags $coverage_flags -c {{source}} -o {{output}}" + if (use_rbe || use_goma) { + command += " && sed -i '' -e 's@/b/f/w@../..@g' $depfile" + } depsformat = "gcc" description = "OBJCXX {{output}}" outputs = @@ -222,12 +252,16 @@ mac_toolchain("ios_clang_arm") { toolchain_cpu = "arm" toolchain_os = "mac" prefix = rebased_clang_dir - ar = "$prefix/llvm-ar" - cc = "$prefix/clang" - cxx = "$prefix/clang++" - ld = cxx + ar = "${prefix}/llvm-ar" + asm = "${prefix}/clang" + cc = "${cxx_prefix}${prefix}/clang" + cxx = "${cxx_prefix}${prefix}/clang++" + objc = "${objc_prefix}${prefix}/clang++" + ld = "${link_prefix}${prefix}/clang++" is_clang = true - sysroot_flags = "-isysroot $ios_device_sdk_path -miphoneos-version-min=$ios_deployment_target" + + sysroot_rel = rebase_path(ios_sdk_path, root_build_dir) + sysroot_flags = "-isysroot $sysroot_rel -miphoneos-version-min=$ios_deployment_target" } # Toolchain used for iOS simulator targets (arm64). @@ -235,12 +269,16 @@ mac_toolchain("ios_clang_arm_sim") { toolchain_cpu = "arm" toolchain_os = "mac" prefix = rebased_clang_dir - ar = "$prefix/llvm-ar" - cc = "$prefix/clang" - cxx = "$prefix/clang++" - ld = cxx + ar = "${prefix}/llvm-ar" + asm = "${prefix}/clang" + cc = "${cxx_prefix}${prefix}/clang" + cxx = "${cxx_prefix}${prefix}/clang++" + objc = "${objc_prefix}${prefix}/clang++" + ld = "${link_prefix}${prefix}/clang++" is_clang = true - sysroot_flags = "-isysroot $ios_simulator_sdk_path -mios-simulator-version-min=$ios_deployment_target" + + sysroot_rel = rebase_path(ios_sdk_path, root_build_dir) + sysroot_flags = "-isysroot $sysroot_rel -mios-simulator-version-min=$ios_deployment_target" } # Toolchain used for iOS simulator targets (x64). @@ -248,12 +286,16 @@ mac_toolchain("ios_clang_x64_sim") { toolchain_cpu = "x64" toolchain_os = "mac" prefix = rebased_clang_dir - ar = "$prefix/llvm-ar" - cc = "$prefix/clang" - cxx = "$prefix/clang++" - ld = cxx + ar = "${prefix}/llvm-ar" + asm = "${prefix}/clang" + cc = "${cxx_prefix}${prefix}/clang" + cxx = "${cxx_prefix}${prefix}/clang++" + objc = "${objc_prefix}${prefix}/clang++" + ld = "${link_prefix}${prefix}/clang++" is_clang = true - sysroot_flags = "-isysroot $ios_simulator_sdk_path -mios-simulator-version-min=$ios_deployment_target" + + sysroot_rel = rebase_path(ios_sdk_path, root_build_dir) + sysroot_flags = "-isysroot $sysroot_rel -mios-simulator-version-min=$ios_deployment_target" } # Toolchain used for Mac X64 host targets. @@ -261,13 +303,17 @@ mac_toolchain("clang_x64") { toolchain_cpu = "x64" toolchain_os = "mac" prefix = rebased_clang_dir - ar = "$prefix/llvm-ar" - cc = "$prefix/clang" - cxx = "$prefix/clang++" - ld = cxx + ar = "${prefix}/llvm-ar" + asm = "${prefix}/clang" + cc = "${cxx_prefix}${prefix}/clang" + cxx = "${cxx_prefix}${prefix}/clang++" + objc = "${objc_prefix}${prefix}/clang++" + ld = "${link_prefix}${prefix}/clang++" is_clang = true + + sysroot_rel = rebase_path(mac_sdk_path, root_build_dir) sysroot_flags = - "-isysroot $mac_sdk_path -mmacosx-version-min=$mac_deployment_target" + "-isysroot $sysroot_rel -mmacosx-version-min=$mac_deployment_target" } # Toolchain used for Mac ARM64 host targets. @@ -275,11 +321,15 @@ mac_toolchain("clang_arm64") { toolchain_cpu = "arm64" toolchain_os = "mac" prefix = rebased_clang_dir - ar = "$prefix/llvm-ar" - cc = "$prefix/clang" - cxx = "$prefix/clang++" - ld = cxx + ar = "${prefix}/llvm-ar" + asm = "${prefix}/clang" + cc = "${cxx_prefix}${prefix}/clang" + cxx = "${cxx_prefix}${prefix}/clang++" + objc = "${objc_prefix}${prefix}/clang++" + ld = "${link_prefix}${prefix}/clang++" is_clang = true + + sysroot_rel = rebase_path(mac_sdk_path, root_build_dir) sysroot_flags = - "-isysroot $mac_sdk_path -mmacosx-version-min=$mac_deployment_target" + "-isysroot $sysroot_rel -mmacosx-version-min=$mac_deployment_target" } diff --git a/build/toolchain/rbe.gni b/build/toolchain/rbe.gni index 0f29e52fd1..23905e86ee 100644 --- a/build/toolchain/rbe.gni +++ b/build/toolchain/rbe.gni @@ -19,15 +19,55 @@ declare_args() { rbe_exec_root = rebase_path("//") - rbe_server_address = "unix:///tmp/reproxy.sock" + rbe_server_address = "" - rbe_exec_strategy = "remote_local_fallback" + rbe_exec_strategy = "" - rbe_dial_timeout = "30s" + rbe_dial_timeout = "" - rbe_platform = "container-image=docker://gcr.io/cloud-marketplace/google/debian11@sha256:69e2789c9f3d28c6a0f13b25062c240ee7772be1f5e6d41bb4680b63eae6b304" + rbe_exec_timeout = "" + + rbe_reclient_timeout = "" + + rbe_platform = "" - # TODO(zanderso): In the gn script, set the default value based on the host - # platform. rbe_dir = rebase_path("//buildtools/linux-x64/reclient") + + rbe_cfg = rebase_path("//flutter/build/rbe/rewrapper-linux.cfg") +} + +rewrapper_command = [ + "$rbe_dir/rewrapper", + "--cfg=$rbe_cfg", + "--exec_root=$rbe_exec_root", +] +if (rbe_server_address != "") { + rewrapper_command += [ + "--server_address=$rbe_server_address", + ] +} +if (rbe_exec_strategy != "") { + rewrapper_command += [ + "--exec_strategy=$rbe_exec_strategy", + ] +} +if (rbe_dial_timeout != "") { + rewrapper_command += [ + "--dial_timeout=$rbe_dial_timeout", + ] +} +if (rbe_exec_timeout != "") { + rewrapper_command += [ + "--exec_timeout=$rbe_exec_timeout", + ] +} +if (rbe_reclient_timeout != "") { + rewrapper_command += [ + "--reclient_timeout=$rbe_reclient_timeout", + ] +} +if (rbe_platform != "") { + rewrapper_command += [ + "--platform=$rbe_platform", + ] }