android: Build universal gen_snapshot for Android (#164453)

This adopts the macOS/iOS rules for creating the `gen_snapshot_arm64`
and `gen_snapshot_armv7` for both arm64 targets (`gen_snapshot_arm64`)
and armv7 targets (`gen_snapshot_armv7`) on both arm64 and x64 macOS
hosts. The macOS and iOS rules have already been updated to generate
universal binaries for each of these that can be run on both Apple
Silicon and Intel Mac hosts.

The `create_arm_gen_snapshot` rule remains until I'm 100% convinced it's
not used for anything else. Will send a follow-up patch removing it so
as not to conflate the two.

No test changes since this is covered by existing build/integration
tests.

Fixes: https://github.com/flutter/flutter/issues/152281
Issue: https://github.com/flutter/flutter/issues/69157

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [X] I signed the [CLA].
- [X] I listed at least one issue that this PR fixes in the description
above.
- [X] I updated/added relevant documentation (doc comments with `///`).
- [X] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [X] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [X] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This commit is contained in:
Chris Bracken 2025-03-03 13:50:31 -08:00 committed by GitHub
parent 7d8c78ce20
commit 060e159d53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 51 additions and 22 deletions

View File

@ -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}",
]
}
}

View File

@ -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"
}
}
}

View File

@ -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"
}