From dcb7a9df9bce4eb941157aa4038cb48adfe7fe04 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Mon, 21 Mar 2016 17:45:47 -0700 Subject: [PATCH] The dynamic services SDK produces a fat Mach binary of x64 and arm64 variants. --- sky/services/dynamic/BUILD.gn | 51 +++++++++++++++++++++++++++++++++- sky/tools/lipo.py | 52 +++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100755 sky/tools/lipo.py diff --git a/sky/services/dynamic/BUILD.gn b/sky/services/dynamic/BUILD.gn index c109c637a95..8be2b6ccaef 100644 --- a/sky/services/dynamic/BUILD.gn +++ b/sky/services/dynamic/BUILD.gn @@ -29,7 +29,7 @@ source_set("embedder") { ] } -static_library("sdk_lib") { +static_library("sdk_lib_single_arch") { output_name = "FlutterServices" complete_static_lib = true @@ -48,3 +48,52 @@ static_library("sdk_lib") { "//mojo/public/platform/native:system", ] } + + +group("sdk_lib") { + action("generate_fat_binary") { + stamp_file = "$root_out_dir/dynamic_service_dylib_lipo" + script = "//sky/tools/lipo.py" + + device_target = ":sdk_lib_single_arch(//build/toolchain/mac:ios_clang_arm)" + sim_target = ":sdk_lib_single_arch(//build/toolchain/mac:clang_x64)" + + device_binary = "$root_build_dir/obj/sky/services/dynamic/libFlutterServices.a" + sim_binary = "$root_build_dir/clang_x64/obj/sky/services/dynamic/libFlutterServices.a" + fat_binary = "$root_out_dir/FlutterServicesIOS.a" + + inputs = [ + device_binary, + sim_binary, + ] + + outputs = [ + stamp_file, + fat_binary, + ] + + args = [ + "--stamp", + rebase_path(stamp_file), + "--path", + rebase_path(device_binary), + "--path", + rebase_path(sim_binary), + "--output", + rebase_path(fat_binary), + ] + + deps = [ + "$device_target", + "$sim_target", + ] + } + + deps = [] + + if (is_ios) { + deps += [ + ":generate_fat_binary", + ] + } +} diff --git a/sky/tools/lipo.py b/sky/tools/lipo.py new file mode 100755 index 00000000000..abcc122ca92 --- /dev/null +++ b/sky/tools/lipo.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +# 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. + +import argparse +import subprocess +import sys +import os + + +def MakeStamp(stamp_path): + dir_name = os.path.dirname(stamp_path) + + if not os.path.isdir(dir_name): + os.makedirs() + + with open(stamp_path, 'a'): + os.utime(stamp_path, None) + + +def main(): + parser = argparse.ArgumentParser( + description='Creates a FAT Mach binary') + + parser.add_argument('--path', action='append', dest='paths', + default=[], help='The path to a Mach binary') + parser.add_argument('--output', type=str) + parser.add_argument('--stamp', type=str) + + args = parser.parse_args() + + cmd = [ + '/usr/bin/env', + 'xcrun', + 'lipo', + ] + + cmd.extend(args.paths) + + cmd.extend([ + '-create', + '-output', + args.output, + ]) + + subprocess.check_call(cmd) + + MakeStamp(args.stamp) + +if __name__ == '__main__': + sys.exit(main())