Skip to content

Commit 02806cc

Browse files
authored
Add scripts for cross-arch macOS framework (flutter#31014)
1 parent ab130f1 commit 02806cc

File tree

2 files changed

+109
-5
lines changed

2 files changed

+109
-5
lines changed

sky/tools/create_macos_framework.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright 2013 The Flutter Authors. All rights reserved.
4+
# Use of this source code is governed by a BSD-style license that can be
5+
# found in the LICENSE file.
6+
7+
import argparse
8+
import subprocess
9+
import shutil
10+
import sys
11+
import os
12+
13+
from create_xcframework import create_xcframework
14+
15+
DSYMUTIL = os.path.join(os.path.dirname(__file__), '..', '..', '..',
16+
'buildtools', 'mac-x64', 'clang', 'bin', 'dsymutil')
17+
18+
def main():
19+
parser = argparse.ArgumentParser(description='Creates FlutterMacOS.framework for macOS')
20+
21+
parser.add_argument('--dst', type=str, required=True)
22+
parser.add_argument('--arm64-out-dir', type=str, required=True)
23+
parser.add_argument('--x64-out-dir', type=str, required=True)
24+
parser.add_argument('--strip', action="store_true", default=False)
25+
parser.add_argument('--dsym', action="store_true", default=False)
26+
27+
args = parser.parse_args()
28+
29+
fat_framework = os.path.join(args.dst, 'FlutterMacOS.framework')
30+
arm64_framework = os.path.join(args.arm64_out_dir, 'FlutterMacOS.framework')
31+
x64_framework = os.path.join(args.x64_out_dir, 'FlutterMacOS.framework')
32+
33+
arm64_dylib = os.path.join(arm64_framework, 'FlutterMacOS')
34+
x64_dylib = os.path.join(x64_framework, 'FlutterMacOS')
35+
36+
if not os.path.isdir(arm64_framework):
37+
print('Cannot find macOS arm64 Framework at %s' % arm64_framework)
38+
return 1
39+
40+
if not os.path.isdir(x64_framework):
41+
print('Cannot find macOS x64 Framework at %s' % x64_framework)
42+
return 1
43+
44+
if not os.path.isfile(arm64_dylib):
45+
print('Cannot find macOS arm64 dylib at %s' % arm64_dylib)
46+
return 1
47+
48+
if not os.path.isfile(x64_dylib):
49+
print('Cannot find macOS x64 dylib at %s' % x64_dylib)
50+
return 1
51+
52+
if not os.path.isfile(DSYMUTIL):
53+
print('Cannot find dsymutil at %s' % DSYMUTIL)
54+
return 1
55+
56+
shutil.rmtree(fat_framework, True)
57+
shutil.copytree(arm64_framework, fat_framework, symlinks=True)
58+
59+
fat_framework_binary = os.path.join(fat_framework, 'Versions', 'A', 'FlutterMacOS')
60+
61+
# Create the arm64/x64 fat framework.
62+
subprocess.check_call([
63+
'lipo',
64+
arm64_dylib,
65+
x64_dylib,
66+
'-create',
67+
'-output',
68+
fat_framework_binary
69+
])
70+
process_framework(args, fat_framework, fat_framework_binary)
71+
72+
73+
def process_framework(args, fat_framework, fat_framework_binary):
74+
if args.dsym:
75+
dsym_out = os.path.splitext(fat_framework)[0] + '.dSYM'
76+
subprocess.check_call([DSYMUTIL, '-o', dsym_out, fat_framework_binary])
77+
78+
if args.strip:
79+
# copy unstripped
80+
unstripped_out = os.path.join(args.dst, 'FlutterMacOS.unstripped')
81+
shutil.copyfile(fat_framework_binary, unstripped_out)
82+
83+
subprocess.check_call(["strip", "-x", "-S", fat_framework_binary])
84+
85+
86+
if __name__ == '__main__':
87+
sys.exit(main())

sky/tools/create_macos_gen_snapshots.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,45 @@
1111

1212

1313
def main():
14-
parser = argparse.ArgumentParser(description='Copies architecture-dependent gen_snapshot binaries to output dir')
14+
parser = argparse.ArgumentParser(
15+
description='Copies architecture-dependent gen_snapshot binaries to output dir'
16+
)
1517

1618
parser.add_argument('--dst', type=str, required=True)
19+
parser.add_argument('--x64-out-dir', type=str)
1720
parser.add_argument('--arm64-out-dir', type=str)
1821
parser.add_argument('--armv7-out-dir', type=str)
1922

2023
args = parser.parse_args()
2124

25+
if args.x64_out_dir:
26+
generate_gen_snapshot(
27+
args.x64_out_dir,
28+
os.path.join(args.dst, 'gen_snapshot_x64')
29+
)
30+
2231
if args.arm64_out_dir:
23-
generate_gen_snapshot(args.arm64_out_dir, os.path.join(args.dst, 'gen_snapshot_arm64'))
32+
generate_gen_snapshot(
33+
os.path.join(args.arm64_out_dir, 'clang_x64'),
34+
os.path.join(args.dst, 'gen_snapshot_arm64')
35+
)
2436

2537
if args.armv7_out_dir:
26-
generate_gen_snapshot(args.armv7_out_dir, os.path.join(args.dst, 'gen_snapshot_armv7'))
38+
generate_gen_snapshot(
39+
os.path.join(args.armv7_out_dir, 'clang_x64'),
40+
os.path.join(args.dst, 'gen_snapshot_armv7')
41+
)
2742

2843

2944
def generate_gen_snapshot(directory, destination):
30-
gen_snapshot_dir = os.path.join(directory, 'clang_x64', 'gen_snapshot')
45+
gen_snapshot_dir = os.path.join(directory, 'gen_snapshot')
3146
if not os.path.isfile(gen_snapshot_dir):
3247
print('Cannot find gen_snapshot at %s' % gen_snapshot_dir)
3348
sys.exit(1)
3449

35-
subprocess.check_call(['xcrun', 'bitcode_strip', '-r', gen_snapshot_dir, '-o', destination])
50+
subprocess.check_call(
51+
['xcrun', 'bitcode_strip', '-r', gen_snapshot_dir, '-o', destination]
52+
)
3653

3754

3855
if __name__ == '__main__':

0 commit comments

Comments
 (0)