diff --git a/engine/src/flutter/lib/snapshot/BUILD.gn b/engine/src/flutter/lib/snapshot/BUILD.gn index 5eef5474ba..6630216eaf 100644 --- a/engine/src/flutter/lib/snapshot/BUILD.gn +++ b/engine/src/flutter/lib/snapshot/BUILD.gn @@ -6,7 +6,7 @@ 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_snapshots.gni") +import("//flutter/sky/tools/macos.gni") import("//third_party/dart/utils/compile_platform.gni") # Generates the Dart/Flutter core platform files and tools. @@ -248,7 +248,8 @@ bin_to_linkable("platform_strong_dill_linkable") { # Builds gen_snapshot using the host toolchain then copies the resulting binary # to `gen_snapshot_armv7` or `gen_snapshot_arm64` depending on the target # platform. -if (host_os == "mac" && (target_cpu == "arm" || target_cpu == "arm64")) { +if (host_os == "mac" && target_os != "mac" && + (target_cpu == "arm" || target_cpu == "arm64")) { action("create_arm_gen_snapshot") { host_output_dir = get_label_info( "//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)", @@ -280,9 +281,19 @@ if (host_os == "mac" && (target_cpu == "arm" || target_cpu == "arm64")) { } if (host_os == "mac" && target_os == "mac") { - macos_gen_snapshots("create_macos_gen_snapshots") { - deps = [ ":generate_snapshot_bin" ] - arch = "$target_cpu" + strip_bitcode("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}" + 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/gen_snapshots.py b/engine/src/flutter/sky/tools/gen_snapshots.py deleted file mode 100755 index 3dde468131..0000000000 --- a/engine/src/flutter/sky/tools/gen_snapshots.py +++ /dev/null @@ -1,46 +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 subprocess -import sys -import os - - -def main(): - parser = argparse.ArgumentParser( - description='Copies architecture-dependent gen_snapshot binaries to output dir' - ) - - parser.add_argument('--dst', type=str, required=True) - parser.add_argument('--out-dir', type=str) - parser.add_argument('--arch', type=str) - - args = parser.parse_args() - - subdir = '' - if args.arch != 'x64': - subdir = 'clang_x64' - - generate_gen_snapshot( - os.path.join(args.out_dir, subdir), - os.path.join(args.dst, 'gen_snapshot_%s' % args.arch) - ) - - -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) - sys.exit(1) - - subprocess.check_call([ - 'xcrun', 'bitcode_strip', '-r', gen_snapshot_dir, '-o', destination - ]) - - -if __name__ == '__main__': - sys.exit(main()) diff --git a/engine/src/flutter/sky/tools/macos.gni b/engine/src/flutter/sky/tools/macos.gni new file mode 100644 index 0000000000..f321dda68a --- /dev/null +++ b/engine/src/flutter/sky/tools/macos.gni @@ -0,0 +1,41 @@ +# 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/macos_snapshots.gni b/engine/src/flutter/sky/tools/macos_snapshots.gni deleted file mode 100644 index cc624c20bb..0000000000 --- a/engine/src/flutter/sky/tools/macos_snapshots.gni +++ /dev/null @@ -1,48 +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") - -# Generates macos gen snapshots $root_build_dir/zip_archives folder. -# - -# The output variable specifies the name of the zip file to create. -# The files variable is an array of scopes that specify a source file or -# directory and a destination path in the archive to create. -# -# For example, to create a zip file named archive.zip with all files in the -# root directory of the archive: -# -# zip_bundle("sample") { -# output = "archive.zip" -# files = [ -# { -# source = "$root_build_dir/some/path/to/lib.so" -# destination = "lib.so" -# }, -# { -# source = "$root_build_dir/some/other/path/with/files" -# destination = "other_files" -# }, -# ] -# } -template("macos_gen_snapshots") { - action(target_name) { - forward_variables_from(invoker, [ "visibility" ]) - deps = invoker.deps - outputs = [ "$root_build_dir/gen_snapshot_${invoker.arch}" ] - script = "//flutter/sky/tools/gen_snapshots.py" - args = [ - "--dst", - rebase_path("$root_out_dir/"), - "--out-dir", - rebase_path("$root_out_dir"), - "--arch", - invoker.arch, - ] - metadata = { - snapshot_entitlement_file_path = [ "gen_snapshot_${invoker.arch}" ] - } - } -} diff --git a/engine/src/flutter/sky/tools/strip_bitcode.py b/engine/src/flutter/sky/tools/strip_bitcode.py new file mode 100755 index 0000000000..c5786ad561 --- /dev/null +++ b/engine/src/flutter/sky/tools/strip_bitcode.py @@ -0,0 +1,44 @@ +#!/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())