Skip to content

Commit 2078620

Browse files
committed
Fix Flutter iOS simulator native asset packaging
1 parent 6b9b408 commit 2078620

File tree

2 files changed

+58
-4
lines changed

2 files changed

+58
-4
lines changed

packages/flutter/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Unreleased
2+
3+
- Fix Flutter iOS simulator native-asset packaging by emitting an
4+
architecture-specific dylib for each simulator target.
5+
16
## 0.9.85
27

38
- Initial release.

packages/flutter/hook/build.dart

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ void main(List<String> args) async {
1717

1818
final binaryPath = _resolveBinaryPath(os, arch, codeConfig);
1919
if (binaryPath == null) {
20-
throw UnsupportedError(
21-
'sqlite_vector does not support $os $arch.',
22-
);
20+
throw UnsupportedError('sqlite_vector does not support $os $arch.');
2321
}
2422

2523
final nativeLibDir = p.join(
@@ -34,17 +32,68 @@ void main(List<String> args) async {
3432
);
3533
}
3634

35+
output.dependencies.add(file.uri);
36+
37+
final assetFile = await _prepareAssetFile(
38+
input: input,
39+
os: os,
40+
arch: arch,
41+
config: codeConfig,
42+
file: file,
43+
);
44+
3745
output.assets.code.add(
3846
CodeAsset(
3947
package: input.packageName,
4048
name: 'src/native/sqlite_vector_extension.dart',
4149
linkMode: DynamicLoadingBundled(),
42-
file: file.uri,
50+
file: assetFile.uri,
4351
),
4452
);
4553
});
4654
}
4755

56+
Future<File> _prepareAssetFile({
57+
required BuildInput input,
58+
required OS os,
59+
required Architecture arch,
60+
required CodeConfig config,
61+
required File file,
62+
}) async {
63+
if (os != OS.iOS || config.iOS.targetSdk == IOSSdk.iPhoneOS) {
64+
return file;
65+
}
66+
67+
final thinArch = switch (arch) {
68+
Architecture.arm64 => 'arm64',
69+
Architecture.x64 => 'x86_64',
70+
_ => null,
71+
};
72+
if (thinArch == null) {
73+
return file;
74+
}
75+
76+
final outputName = 'vector_ios_sim_$thinArch.dylib';
77+
final outputFile = File.fromUri(input.outputDirectory.resolve(outputName));
78+
await outputFile.parent.create(recursive: true);
79+
80+
final result = await Process.run('/usr/bin/lipo', [
81+
file.path,
82+
'-thin',
83+
thinArch,
84+
'-output',
85+
outputFile.path,
86+
]);
87+
if (result.exitCode != 0) {
88+
throw StateError(
89+
'Failed to thin sqlite_vector iOS simulator binary for $thinArch: '
90+
'${result.stderr}',
91+
);
92+
}
93+
94+
return outputFile;
95+
}
96+
4897
String? _resolveBinaryPath(OS os, Architecture arch, CodeConfig config) {
4998
if (os == OS.android) {
5099
return switch (arch) {

0 commit comments

Comments
 (0)