From c100e07c9e2717b7d8ea5bada0c6f9a1d9432bd3 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Wed, 24 Jul 2024 14:56:16 -0700 Subject: [PATCH] [iOS] Build universal gen_snapshots for iOS (flutter/engine#54009) This merges the macOS and iOS rules for creating the `gen_snapshot_arm64` and `gen_snapshot_x64` used to build for iOS devices, as well as for iOS simulators on both arm64 hosts (`gen_snapshot_arm64`) and x64 hosts (`gen_snapshot_x64`). The macOS 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. This also updates `create_full_ios_framework.py` to bundle the newly-generated universal gen_snapshot binaries and produce the artifacts.zip archive that is uploaded via the build config in `mac_ios_engine.json`. The `create_arm_gen_snapshot` rule remains until I'm 100% convinced it's not used for macOS host Android target builds. Issue: https://github.com/flutter/flutter/issues/101138 Issue: https://github.com/flutter/flutter/issues/69157 This is stacked on top of https://github.com/flutter/engine/pull/54008. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../flutter/ci/builders/mac_ios_engine.json | 18 ++++++++++-------- engine/src/flutter/lib/snapshot/BUILD.gn | 11 +++++------ .../sky/tools/create_full_ios_framework.py | 17 ++++++++--------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/engine/src/flutter/ci/builders/mac_ios_engine.json b/engine/src/flutter/ci/builders/mac_ios_engine.json index 163b6a6868..cca4c02b79 100644 --- a/engine/src/flutter/ci/builders/mac_ios_engine.json +++ b/engine/src/flutter/ci/builders/mac_ios_engine.json @@ -117,6 +117,7 @@ "ninja": { "config": "ci/ios_debug", "targets": [ + "flutter/lib/snapshot:generate_snapshot_bins", "flutter/shell/platform/darwin/ios:flutter_framework" ] }, @@ -161,8 +162,8 @@ "ninja": { "config": "ci/ios_profile", "targets": [ - "flutter/shell/platform/darwin/ios:flutter_framework", - "flutter/lib/snapshot:generate_snapshot_bin" + "flutter/lib/snapshot:generate_snapshot_bins", + "flutter/shell/platform/darwin/ios:flutter_framework" ] }, "postsubmit_overrides": { @@ -206,8 +207,8 @@ "ninja": { "config": "ci/ios_release", "targets": [ - "flutter/shell/platform/darwin/ios:flutter_framework", - "flutter/lib/snapshot:generate_snapshot_bin" + "flutter/lib/snapshot:generate_snapshot_bins", + "flutter/shell/platform/darwin/ios:flutter_framework" ] }, "postsubmit_overrides": { @@ -349,6 +350,7 @@ "ninja": { "config": "ci/ios_debug_extension_safe", "targets": [ + "flutter/lib/snapshot:generate_snapshot_bins", "flutter/shell/platform/darwin/ios:flutter_framework" ] }, @@ -395,8 +397,8 @@ "ninja": { "config": "ci/ios_profile_extension_safe", "targets": [ - "flutter/shell/platform/darwin/ios:flutter_framework", - "flutter/lib/snapshot:generate_snapshot_bin" + "flutter/lib/snapshot:generate_snapshot_bins", + "flutter/shell/platform/darwin/ios:flutter_framework" ] }, "postsubmit_overrides": { @@ -442,8 +444,8 @@ "ninja": { "config": "ci/ios_release_extension_safe", "targets": [ - "flutter/shell/platform/darwin/ios:flutter_framework", - "flutter/lib/snapshot:generate_snapshot_bin" + "flutter/lib/snapshot:generate_snapshot_bins", + "flutter/shell/platform/darwin/ios:flutter_framework" ] }, "postsubmit_overrides": { diff --git a/engine/src/flutter/lib/snapshot/BUILD.gn b/engine/src/flutter/lib/snapshot/BUILD.gn index e048a33b45..689bcdaddc 100644 --- a/engine/src/flutter/lib/snapshot/BUILD.gn +++ b/engine/src/flutter/lib/snapshot/BUILD.gn @@ -33,7 +33,7 @@ group("generate_snapshot_bins") { # # For macOS target builds: needed for both target CPUs (arm64, x64). # For iOS, Android target builds: all AOT target CPUs are arm/arm64. - if (host_os == "mac" && target_os == "mac") { + if (host_os == "mac" && (target_os == "mac" || target_os == "ios")) { deps += [ ":create_macos_gen_snapshots" ] } else if (host_os == "mac" && (target_cpu == "arm" || target_cpu == "arm64")) { @@ -184,17 +184,16 @@ 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 macOS. -if (host_os == "mac" && target_os == "mac") { +# This target is used for builds targeting iOS and macOS. +if (host_os == "mac" && (target_os == "mac" || target_os == "ios")) { template("build_mac_gen_snapshot") { assert(defined(invoker.host_arch)) host_cpu = invoker.host_arch build_toolchain = "//build/toolchain/mac:clang_$host_cpu" - if (host_cpu == target_cpu) { + gen_snapshot_target_name = "gen_snapshot" + if (target_os == "mac" && host_cpu == target_cpu) { gen_snapshot_target_name = "gen_snapshot_host_targeting_host" - } else { - gen_snapshot_target_name = "gen_snapshot" } gen_snapshot_target = "$dart_src/runtime/bin:$gen_snapshot_target_name($build_toolchain)" diff --git a/engine/src/flutter/sky/tools/create_full_ios_framework.py b/engine/src/flutter/sky/tools/create_full_ios_framework.py index 37d4340bbd..7c1ae0f0a9 100644 --- a/engine/src/flutter/sky/tools/create_full_ios_framework.py +++ b/engine/src/flutter/sky/tools/create_full_ios_framework.py @@ -230,21 +230,20 @@ def process_framework(args, dst, framework, framework_binary): def generate_gen_snapshot(dst, x64_out_dir, arm64_out_dir): if x64_out_dir: - _generate_gen_snapshot(x64_out_dir, os.path.join(dst, 'gen_snapshot_x64')) + x64_path = os.path.join(x64_out_dir, 'gen_snapshot_x64') + _generate_gen_snapshot(x64_path, os.path.join(dst, 'gen_snapshot_x64')) if arm64_out_dir: - _generate_gen_snapshot( - os.path.join(arm64_out_dir, 'clang_x64'), os.path.join(dst, 'gen_snapshot_arm64') - ) + arm64_path = os.path.join(arm64_out_dir, 'gen_snapshot_arm64') + _generate_gen_snapshot(arm64_path, os.path.join(dst, 'gen_snapshot_arm64')) -def _generate_gen_snapshot(directory, destination): - gen_snapshot_dir = os.path.join(directory, 'gen_snapshot') - if not os.path.isfile(gen_snapshot_dir): - print('Cannot find gen_snapshot at %s' % gen_snapshot_dir) +def _generate_gen_snapshot(gen_snapshot_path, destination): + if not os.path.isfile(gen_snapshot_path): + print('Cannot find gen_snapshot at %s' % gen_snapshot_path) sys.exit(1) - subprocess.check_call(['xcrun', 'bitcode_strip', '-r', gen_snapshot_dir, '-o', destination]) + subprocess.check_call(['xcrun', 'bitcode_strip', '-r', gen_snapshot_path, '-o', destination]) if __name__ == '__main__':