From ad77065cad9856c030c6cf3d2be5e3f1d2db0343 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 6 Oct 2022 00:26:35 +0100 Subject: [PATCH] [macOS][iOS] Eliminate strip_bitcode action (flutter/engine#36627) Eliminates the `strip_bitcode` GN rule defined in //flutter/sky/tools/mac.gni and the related script at //flutter/sky/tools/strip_bitcode.py. As of Xcode 14, bitcode is deprecated, no longer enabled by default, and generates a warning message if a project enables it. Bitcode support will be removed entirely from a future version of Xcode. The `strip_bitcode` rule had two purposes: 1. Copy the binary specified by its input parameter to the path specified by its output parameter. 2. Strip bitcode segments as it does so. While we no longer require the second of these functions, we still use the first to create a `gen_snapshot` binary suffixed with the target architecture. This replaces `strip_bitcode` with the built-in gn `copy` rule instead. Issue: https://github.com/flutter/flutter/issues/107884 Issue: https://github.com/flutter/flutter/issues/112896 Issue: https://github.com/flutter/flutter/issues/101138 Issue: https://github.com/flutter/flutter/issues/103386 --- engine/src/flutter/lib/snapshot/BUILD.gn | 13 +++--- engine/src/flutter/sky/tools/macos.gni | 41 ----------------- engine/src/flutter/sky/tools/strip_bitcode.py | 44 ------------------- 3 files changed, 6 insertions(+), 92 deletions(-) delete mode 100644 engine/src/flutter/sky/tools/macos.gni delete mode 100755 engine/src/flutter/sky/tools/strip_bitcode.py diff --git a/engine/src/flutter/lib/snapshot/BUILD.gn b/engine/src/flutter/lib/snapshot/BUILD.gn index 22930d5c8b..d8176bdf51 100644 --- a/engine/src/flutter/lib/snapshot/BUILD.gn +++ b/engine/src/flutter/lib/snapshot/BUILD.gn @@ -6,7 +6,6 @@ import("//build/compiled_action.gni") import("//build/fuchsia/sdk.gni") import("//flutter/common/config.gni") import("//flutter/lib/ui/dart_ui.gni") -import("//flutter/sky/tools/macos.gni") import("//third_party/dart/utils/compile_platform.gni") # Generates the Dart/Flutter core platform files and tools. @@ -252,7 +251,7 @@ bin_to_linkable("platform_strong_dill_linkable") { # This target is used for builds targeting iOS/Android OS. if (host_os == "mac" && target_os != "mac" && (target_cpu == "arm" || target_cpu == "arm64")) { - strip_bitcode("create_arm_gen_snapshot") { + copy("create_arm_gen_snapshot") { # The toolchain-specific output directory. For cross-compiles, this is a # clang-x64 or clang-arm64 subdirectory of the top-level build directory. host_output_dir = get_label_info( @@ -265,8 +264,8 @@ if (host_os == "mac" && target_os != "mac" && target_cpu_suffix = "armv7" } - input = "${host_output_dir}/gen_snapshot" - output = "${host_output_dir}/gen_snapshot_${target_cpu_suffix}" + sources = [ "${host_output_dir}/gen_snapshot" ] + outputs = [ "${host_output_dir}/gen_snapshot_${target_cpu_suffix}" ] deps = [ "//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)" ] visibility = [ ":*" ] } @@ -280,15 +279,15 @@ if (host_os == "mac" && target_os != "mac" && # # This target is used for builds targeting macOS. if (host_os == "mac" && target_os == "mac") { - strip_bitcode("create_macos_gen_snapshots") { + copy("create_macos_gen_snapshots") { # The toolchain-specific output directory. For cross-compiles, this is a # clang-x64 or clang-arm64 subdirectory of the top-level build directory. host_output_dir = get_label_info( "//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)", "root_out_dir") - input = "${host_output_dir}/gen_snapshot" - output = "${root_out_dir}/gen_snapshot_${target_cpu}" + sources = [ "${host_output_dir}/gen_snapshot" ] + outputs = [ "${root_out_dir}/gen_snapshot_${target_cpu}" ] deps = [ "//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)" ] metadata = { snapshot_entitlement_file_path = [ "gen_snapshot_{$target_cpu}" ] diff --git a/engine/src/flutter/sky/tools/macos.gni b/engine/src/flutter/sky/tools/macos.gni deleted file mode 100644 index f321dda68a..0000000000 --- a/engine/src/flutter/sky/tools/macos.gni +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright 2013 The Flutter Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -import("//flutter/common/config.gni") - -# Copies an input macOS binary to the specified output path. Bitcode segments, -# if any, are stripped. -# -# Example: -# -# strip_bitcode( -# input = "$root_build_dir/gen_snapshot" -# output = "$root_build_dir/gen_snapshot_arm64" -# deps = [ ":gen_snapshot" ] -# ) -# -# TODO(cbracken): https://github.com/flutter/flutter/issues/107884 -# When we stop building with bitcode enabled, this template and the -# strip_bitcode.py script can be deleted and users can call copy() instead. -template("strip_bitcode") { - assert(defined(invoker.input), "The input to strip_bitcode must be defined") - assert(defined(invoker.output), "The output to strip_bitcode most be defined") - action(target_name) { - forward_variables_from(invoker, - [ - "deps", - "metadata", - "visibility", - ]) - script = "//flutter/sky/tools/strip_bitcode.py" - args = [ - "--input", - rebase_path(invoker.input), - "--output", - rebase_path(invoker.output), - ] - inputs = [ invoker.input ] - outputs = [ invoker.output ] - } -} diff --git a/engine/src/flutter/sky/tools/strip_bitcode.py b/engine/src/flutter/sky/tools/strip_bitcode.py deleted file mode 100755 index c5786ad561..0000000000 --- a/engine/src/flutter/sky/tools/strip_bitcode.py +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright 2013 The Flutter Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -import argparse -import os -import subprocess -import sys - - -def main(): - parser = argparse.ArgumentParser( - description='Copies an input macOS binary to the specified output path. ' - 'Bitcode segments, if any, are stripped.' - ) - parser.add_argument( - '--input', - type=str, - required=True, - help='path of input binary to be read' - ) - parser.add_argument( - '--output', - type=str, - required=True, - help='path of output binary to be written' - ) - args = parser.parse_args() - - # Verify input binary exists. - if not os.path.isfile(args.input): - print('Cannot find input binary at %s' % args.input) - sys.exit(1) - - # Copy input path to output path. Strip bitcode segments, if any. - subprocess.check_call([ - 'xcrun', 'bitcode_strip', '-r', args.input, '-o', args.output - ]) - - -if __name__ == '__main__': - sys.exit(main())