diff --git a/engine/src/flutter/lib/snapshot/BUILD.gn b/engine/src/flutter/lib/snapshot/BUILD.gn index 144518e217..8606ba3a5b 100644 --- a/engine/src/flutter/lib/snapshot/BUILD.gn +++ b/engine/src/flutter/lib/snapshot/BUILD.gn @@ -6,6 +6,7 @@ import("//build/compiled_action.gni") import("//flutter/build/bin_to_obj.gni") import("//flutter/common/config.gni") import("//flutter/impeller/tools/impeller.gni") +import("//flutter/lib/snapshot/gen_snapshot.gni") import("//flutter/lib/ui/dart_ui.gni") import("$dart_src/utils/compile_platform.gni") @@ -31,7 +32,8 @@ group("generate_snapshot_bins") { public_deps = [] # Build gen_snapshot for the currently specified target_cpu. - if (host_os == "mac" && (target_os == "mac" || target_os == "ios")) { + if (host_os == "mac" && + (target_os == "mac" || target_os == "ios" || target_os == "android")) { # For macOS target builds: needed for both target CPUs (arm64, x64). public_deps += [ ":create_macos_gen_snapshots" ] } else if (host_os == "mac" && @@ -169,14 +171,8 @@ if (host_os == "mac" && target_os != "mac" && get_label_info("$dart_src/runtime/bin:gen_snapshot($host_toolchain)", "root_out_dir") - # Determine suffixed output gen_snapshot name. - target_cpu_suffix = target_cpu - if (target_cpu == "arm") { - target_cpu_suffix = "armv7" - } - sources = [ "${host_output_dir}/gen_snapshot" ] - outputs = [ "${host_output_dir}/gen_snapshot_${target_cpu_suffix}" ] + outputs = [ "${host_output_dir}/gen_snapshot${gen_snapshot_suffix}" ] public_deps = [ "$dart_src/runtime/bin:gen_snapshot($host_toolchain)" ] visibility = [ ":*" ] } @@ -188,8 +184,9 @@ if (host_os == "mac" && target_os != "mac" && # to `gen_snapshot_arm64` or `gen_snapshot_x64` depending on the target # platform. # -# This target is used for builds targeting iOS and macOS. -if (host_os == "mac" && (target_os == "mac" || target_os == "ios")) { +# This target is used for builds targeting iOS, macOS, and Android. +if (host_os == "mac" && + (target_os == "mac" || target_os == "ios" || target_os == "android")) { template("build_mac_gen_snapshot") { assert(defined(invoker.host_arch)) host_cpu = invoker.host_arch @@ -212,36 +209,42 @@ if (host_os == "mac" && (target_os == "mac" || target_os == "ios")) { args = [ rebase_path("${output_dir}/${gen_snapshot_target_name}"), rebase_path( - "${root_out_dir}/artifacts_$host_cpu/gen_snapshot_${target_cpu}"), + "${root_out_dir}/artifacts_$host_cpu/gen_snapshot${gen_snapshot_suffix}"), ] - outputs = - [ "${root_out_dir}/artifacts_$host_cpu/gen_snapshot_${target_cpu}" ] + outputs = [ "${root_out_dir}/artifacts_$host_cpu/gen_snapshot${gen_snapshot_suffix}" ] deps = [ gen_snapshot_target ] } } - build_mac_gen_snapshot("create_macos_gen_snapshot_arm64_${target_cpu}") { + # Build gen_snapshot for arm64 macOS hosts. + build_mac_gen_snapshot( + "create_macos_gen_snapshot_arm64${gen_snapshot_suffix}") { host_arch = "arm64" } - build_mac_gen_snapshot("create_macos_gen_snapshot_x64_${target_cpu}") { + # Build gen_snapshot for x64 macOS hosts. + build_mac_gen_snapshot( + "create_macos_gen_snapshot_x64${gen_snapshot_suffix}") { host_arch = "x64" } + # Create a universal binary from the two architecture-specific gen_snapshots. action("create_macos_gen_snapshots") { script = "//flutter/sky/tools/create_macos_binary.py" - outputs = [ "${root_out_dir}/gen_snapshot_${target_cpu}" ] + outputs = [ "${root_out_dir}/gen_snapshot${gen_snapshot_suffix}" ] args = [ "--in-arm64", - rebase_path("${root_out_dir}/artifacts_arm64/gen_snapshot_${target_cpu}"), + rebase_path( + "${root_out_dir}/artifacts_arm64/gen_snapshot${gen_snapshot_suffix}"), "--in-x64", - rebase_path("${root_out_dir}/artifacts_x64/gen_snapshot_${target_cpu}"), + rebase_path( + "${root_out_dir}/artifacts_x64/gen_snapshot${gen_snapshot_suffix}"), "--out", - rebase_path("${root_out_dir}/gen_snapshot_${target_cpu}"), + rebase_path("${root_out_dir}/gen_snapshot${gen_snapshot_suffix}"), ] deps = [ - ":create_macos_gen_snapshot_arm64_${target_cpu}", - ":create_macos_gen_snapshot_x64_${target_cpu}", + ":create_macos_gen_snapshot_arm64${gen_snapshot_suffix}", + ":create_macos_gen_snapshot_x64${gen_snapshot_suffix}", ] } } diff --git a/engine/src/flutter/lib/snapshot/gen_snapshot.gni b/engine/src/flutter/lib/snapshot/gen_snapshot.gni new file mode 100644 index 0000000000..54b2b93b2e --- /dev/null +++ b/engine/src/flutter/lib/snapshot/gen_snapshot.gni @@ -0,0 +1,22 @@ +# Copyright 2015 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. + +declare_args() { + # For macOS hosts, we produce a suffixed gen_snapshot indicating the target + # CPU architecture (e.g. gen_snapshot_x64 targets x64 devices). This serves + # two purposes: + # 1. Clearly indicates which architecture gen_snapshot targets. + # 2. Avoid build output conflicts -- we produce two gen-snapshot binaries, + # one for each supported macOS host architecture (x64, arm64), then merge + # them to a universal binary. Each of these build outputs must be + # uniquely named. + gen_snapshot_suffix = "" + if (host_os == "mac") { + # Determine suffixed output gen_snapshot name. + gen_snapshot_suffix = "_${target_cpu}" + if (target_cpu == "arm") { + gen_snapshot_suffix = "_armv7" + } + } +} diff --git a/engine/src/flutter/shell/platform/android/BUILD.gn b/engine/src/flutter/shell/platform/android/BUILD.gn index 011c3369aa..f3b972a054 100644 --- a/engine/src/flutter/shell/platform/android/BUILD.gn +++ b/engine/src/flutter/shell/platform/android/BUILD.gn @@ -8,6 +8,7 @@ import("//flutter/build/bin_to_obj.gni") import("//flutter/build/zip_bundle.gni") import("//flutter/common/config.gni") import("//flutter/impeller/tools/impeller.gni") +import("//flutter/lib/snapshot/gen_snapshot.gni") import("//flutter/shell/config.gni") import("//flutter/shell/gpu/gpu.gni") import("//flutter/shell/version/version.gni") @@ -691,7 +692,10 @@ if (target_cpu != "x86") { # The output gen_snapshot binary name in the archive. gen_snapshot_dest = "gen_snapshot" - if (host_os == "win") { + if (host_os == "mac") { + gen_snapshot_src = + rebase_path("$root_out_dir/gen_snapshot${gen_snapshot_suffix}") + } else if (host_os == "win") { gen_snapshot_src = rebase_path("$root_out_dir/gen_snapshot.exe") gen_snapshot_dest = "gen_snapshot.exe" }