Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit cf9ea79

Browse files
committed
Build arm64 FlutterEmbedder.framework and lipo the result
1 parent c284cd1 commit cf9ea79

File tree

4 files changed

+190
-1
lines changed

4 files changed

+190
-1
lines changed

.pylintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ docstring-quote = double
3838
# multiple time (only on the command line, not in the configuration file where
3939
# it should appear only once).
4040
disable=
41+
duplicate-code,
4142
exec-used,
4243
fixme,
4344
missing-class-docstring,

ci/builders/mac_host_engine.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"type": "gcs",
88
"include_paths": [
99
"out/host_debug/zip_archives/darwin-x64/artifacts.zip",
10-
"out/host_debug/zip_archives/darwin-x64/FlutterEmbedder.framework.zip",
1110
"out/host_debug/zip_archives/dart-sdk-darwin-x64.zip"
1211
],
1312
"name": "host_debug",
@@ -214,6 +213,7 @@
214213
"flutter/build/archives:archive_gen_snapshot",
215214
"flutter/build/archives:artifacts",
216215
"flutter/build/archives:dart_sdk_archive",
216+
"flutter/build/archives:flutter_embedder_framework",
217217
"flutter/shell/platform/darwin/macos:zip_macos_flutter_framework"
218218
]
219219
}
@@ -299,6 +299,19 @@
299299
],
300300
"generators": {
301301
"tasks": [
302+
{
303+
"name": "Debug-FlutterEmbedder.framework",
304+
"parameters": [
305+
"--dst",
306+
"out/debug/framework",
307+
"--arm64-out-dir",
308+
"out/mac_debug_arm64",
309+
"--x64-out-dir",
310+
"out/host_debug",
311+
"--zip"
312+
],
313+
"script": "flutter/sky/tools/create_embedder_framework.py"
314+
},
302315
{
303316
"name": "Release-FlutterMacOS.framework",
304317
"parameters": [
@@ -390,6 +403,11 @@
390403
]
391404
},
392405
"archives": [
406+
{
407+
"source": "out/debug/framework/FlutterEmbedder.framework.zip",
408+
"destination": "darwin-x64/FlutterEmbedder.framework.zip",
409+
"realm": "production"
410+
},
393411
{
394412
"source": "out/release/framework/FlutterMacOS.dSYM.zip",
395413
"destination": "darwin-x64-release/FlutterMacOS.dSYM.zip",

ci/licenses_golden/excluded_files

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@
356356
../../../flutter/sky/packages/sky_engine/README.md
357357
../../../flutter/sky/packages/sky_engine/lib/_embedder.yaml
358358
../../../flutter/sky/packages/sky_engine/pubspec.yaml
359+
../../../flutter/sky/tools/create_embedder_framework.py
359360
../../../flutter/sky/tools/create_full_ios_framework.py
360361
../../../flutter/sky/tools/create_ios_framework.py
361362
../../../flutter/sky/tools/create_macos_framework.py
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
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+
buildroot_dir = os.path.abspath(
14+
os.path.join(os.path.realpath(__file__), '..', '..', '..', '..')
15+
)
16+
17+
DSYMUTIL = os.path.join(
18+
os.path.dirname(__file__), '..', '..', '..', 'buildtools', 'mac-x64',
19+
'clang', 'bin', 'dsymutil'
20+
)
21+
22+
out_dir = os.path.join(buildroot_dir, 'out')
23+
24+
25+
def main():
26+
parser = argparse.ArgumentParser(
27+
description='Creates FlutterEmbedder.framework for macOS'
28+
)
29+
30+
parser.add_argument('--dst', type=str, required=True)
31+
parser.add_argument('--arm64-out-dir', type=str, required=True)
32+
parser.add_argument('--x64-out-dir', type=str, required=True)
33+
parser.add_argument('--strip', action='store_true', default=False)
34+
parser.add_argument('--dsym', action='store_true', default=False)
35+
# TODO(godofredoc): Remove after recipes v2 have landed.
36+
parser.add_argument('--zip', action='store_true', default=False)
37+
38+
args = parser.parse_args()
39+
40+
dst = (
41+
args.dst
42+
if os.path.isabs(args.dst) else os.path.join(buildroot_dir, args.dst)
43+
)
44+
arm64_out_dir = (
45+
args.arm64_out_dir if os.path.isabs(args.arm64_out_dir) else
46+
os.path.join(buildroot_dir, args.arm64_out_dir)
47+
)
48+
x64_out_dir = (
49+
args.x64_out_dir if os.path.isabs(args.x64_out_dir) else
50+
os.path.join(buildroot_dir, args.x64_out_dir)
51+
)
52+
53+
fat_framework = os.path.join(dst, 'FlutterEmbedder.framework')
54+
arm64_framework = os.path.join(arm64_out_dir, 'FlutterEmbedder.framework')
55+
x64_framework = os.path.join(x64_out_dir, 'FlutterEmbedder.framework')
56+
57+
arm64_dylib = os.path.join(arm64_framework, 'FlutterEmbedder')
58+
x64_dylib = os.path.join(x64_framework, 'FlutterEmbedder')
59+
60+
if not os.path.isdir(arm64_framework):
61+
print('Cannot find macOS arm64 Framework at %s' % arm64_framework)
62+
return 1
63+
64+
if not os.path.isdir(x64_framework):
65+
print('Cannot find macOS x64 Framework at %s' % x64_framework)
66+
return 1
67+
68+
if not os.path.isfile(arm64_dylib):
69+
print('Cannot find macOS arm64 dylib at %s' % arm64_dylib)
70+
return 1
71+
72+
if not os.path.isfile(x64_dylib):
73+
print('Cannot find macOS x64 dylib at %s' % x64_dylib)
74+
return 1
75+
76+
if not os.path.isfile(DSYMUTIL):
77+
print('Cannot find dsymutil at %s' % DSYMUTIL)
78+
return 1
79+
80+
shutil.rmtree(fat_framework, True)
81+
shutil.copytree(arm64_framework, fat_framework, symlinks=True)
82+
regenerate_symlinks(fat_framework)
83+
84+
fat_framework_binary = os.path.join(
85+
fat_framework, 'Versions', 'A', 'FlutterEmbedder'
86+
)
87+
88+
# Create the arm64/x64 fat framework.
89+
subprocess.check_call([
90+
'lipo', arm64_dylib, x64_dylib, '-create', '-output', fat_framework_binary
91+
])
92+
process_framework(dst, args, fat_framework, fat_framework_binary)
93+
94+
return 0
95+
96+
97+
def regenerate_symlinks(fat_framework):
98+
"""Regenerates the symlinks structure.
99+
100+
Recipes V2 upload artifacts in CAS before integration and CAS follows symlinks.
101+
This logic regenerates the symlinks in the expected structure.
102+
"""
103+
if os.path.islink(os.path.join(fat_framework, 'FlutterEmbedder')):
104+
return
105+
os.remove(os.path.join(fat_framework, 'FlutterEmbedder'))
106+
shutil.rmtree(os.path.join(fat_framework, 'Headers'), True)
107+
shutil.rmtree(os.path.join(fat_framework, 'Modules'), True)
108+
shutil.rmtree(os.path.join(fat_framework, 'Resources'), True)
109+
current_version_path = os.path.join(fat_framework, 'Versions', 'Current')
110+
shutil.rmtree(current_version_path, True)
111+
os.symlink('A', current_version_path)
112+
os.symlink(
113+
os.path.join('Versions', 'Current', 'FlutterEmbedder'),
114+
os.path.join(fat_framework, 'FlutterEmbedder')
115+
)
116+
os.symlink(
117+
os.path.join('Versions', 'Current', 'Headers'),
118+
os.path.join(fat_framework, 'Headers')
119+
)
120+
os.symlink(
121+
os.path.join('Versions', 'Current', 'Modules'),
122+
os.path.join(fat_framework, 'Modules')
123+
)
124+
os.symlink(
125+
os.path.join('Versions', 'Current', 'Resources'),
126+
os.path.join(fat_framework, 'Resources')
127+
)
128+
129+
130+
def process_framework(dst, args, fat_framework, fat_framework_binary):
131+
if args.dsym:
132+
dsym_out = os.path.splitext(fat_framework)[0] + '.dSYM'
133+
subprocess.check_call([DSYMUTIL, '-o', dsym_out, fat_framework_binary])
134+
if args.zip:
135+
dsym_dst = os.path.join(dst, 'FlutterEmbedder.dSYM')
136+
subprocess.check_call([
137+
'zip', '-r', '-y', 'FlutterEmbedder.dSYM.zip', '.'
138+
],
139+
cwd=dsym_dst)
140+
dsym_final_src_path = os.path.join(dsym_dst, 'FlutterEmbedder.dSYM.zip')
141+
dsym_final_dst_path = os.path.join(dst, 'FlutterEmbedder.dSYM.zip')
142+
shutil.move(dsym_final_src_path, dsym_final_dst_path)
143+
144+
if args.strip:
145+
# copy unstripped
146+
unstripped_out = os.path.join(dst, 'FlutterEmbedder.unstripped')
147+
shutil.copyfile(fat_framework_binary, unstripped_out)
148+
subprocess.check_call(['strip', '-x', '-S', fat_framework_binary])
149+
150+
# Zip FlutterEmbedder.framework.
151+
if args.zip:
152+
framework_dst = os.path.join(dst, 'FlutterEmbedder.framework')
153+
subprocess.check_call([
154+
'zip',
155+
'-r',
156+
'-y',
157+
'FlutterEmbedder.framework.zip',
158+
'.',
159+
],
160+
cwd=framework_dst)
161+
final_src_path = os.path.join(
162+
framework_dst, 'FlutterEmbedder.framework.zip'
163+
)
164+
final_dst_path = os.path.join(dst, 'FlutterEmbedder.framework.zip')
165+
shutil.move(final_src_path, final_dst_path)
166+
167+
168+
if __name__ == '__main__':
169+
sys.exit(main())

0 commit comments

Comments
 (0)