Skip to content

Fix frameworks added to bundle multiple times instead of lipo #144688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,15 @@ Target _getNativeTarget(DarwinArch darwinArch) {
Map<KernelAssetPath, List<Asset>> _fatAssetTargetLocations(List<Asset> nativeAssets) {
final Set<String> alreadyTakenNames = <String>{};
final Map<KernelAssetPath, List<Asset>> result = <KernelAssetPath, List<Asset>>{};
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
for (final Asset asset in nativeAssets) {
final KernelAssetPath path = _targetLocationIOS(asset, alreadyTakenNames).path;
// Use same target path for all assets with the same id.
final KernelAssetPath path = idToPath[asset.id] ??
_targetLocationIOS(
asset,
alreadyTakenNames,
).path;
idToPath[asset.id] = path;
result[path] ??= <Asset>[];
result[path]!.add(asset);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,16 @@ Map<KernelAssetPath, List<Asset>> _fatAssetTargetLocations(
final Set<String> alreadyTakenNames = <String>{};
final Map<KernelAssetPath, List<Asset>> result =
<KernelAssetPath, List<Asset>>{};
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
for (final Asset asset in nativeAssets) {
final KernelAssetPath path = _targetLocationMacOS(
asset,
absolutePath,
alreadyTakenNames,
).path;
// Use same target path for all assets with the same id.
final KernelAssetPath path = idToPath[asset.id] ??
_targetLocationMacOS(
asset,
absolutePath,
alreadyTakenNames,
).path;
idToPath[asset.id] = path;
result[path] ??= <Asset>[];
result[path]!.add(asset);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ class FakeNativeAssetsBuildRunner implements NativeAssetsBuildRunner {
FakeNativeAssetsBuildRunner({
this.hasPackageConfigResult = true,
this.packagesWithNativeAssetsResult = const <Package>[],
this.onBuild,
this.dryRunResult = const FakeNativeAssetsBuilderResult(),
this.buildResult = const FakeNativeAssetsBuilderResult(),
CCompilerConfig? cCompilerConfigResult,
CCompilerConfig? ndkCCompilerConfigResult,
}) : cCompilerConfigResult = cCompilerConfigResult ?? CCompilerConfig(),
ndkCCompilerConfigResult = ndkCCompilerConfigResult ?? CCompilerConfig();

final native_assets_builder.BuildResult Function(Target)? onBuild;
final native_assets_builder.BuildResult buildResult;
final native_assets_builder.DryRunResult dryRunResult;
final bool hasPackageConfigResult;
Expand All @@ -51,7 +53,7 @@ class FakeNativeAssetsBuildRunner implements NativeAssetsBuildRunner {
}) async {
buildInvocations++;
lastBuildMode = buildMode;
return buildResult;
return onBuild?.call(target) ?? buildResult;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much cleaner indeed! 😄

}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ void main() {
'-create',
'-output',
'/build/native_assets/ios/bar.framework/bar',
'libbar.dylib',
'arm64/libbar.dylib',
'x64/libbar.dylib',
],
),
const FakeCommand(
Expand Down Expand Up @@ -253,7 +254,7 @@ void main() {
await packageConfig.parent.create();
await packageConfig.create();
await buildNativeAssetsIOS(
darwinArchs: <DarwinArch>[DarwinArch.arm64],
darwinArchs: <DarwinArch>[DarwinArch.arm64, DarwinArch.x86_64],
environmentType: EnvironmentType.simulator,
projectUri: projectUri,
buildMode: BuildMode.debug,
Expand All @@ -263,13 +264,13 @@ void main() {
packagesWithNativeAssetsResult: <Package>[
Package('bar', projectUri),
],
buildResult: FakeNativeAssetsBuilderResult(
onBuild: (native_assets_cli.Target target) => FakeNativeAssetsBuilderResult(
assets: <Asset>[
Asset(
id: 'package:bar/bar.dart',
linkMode: LinkMode.dynamic,
target: native_assets_cli.Target.iOSArm64,
path: AssetAbsolutePath(Uri.file('libbar.dylib')),
target: target,
path: AssetAbsolutePath(Uri.file('${target.architecture}/libbar.dylib')),
),
],
),
Expand All @@ -278,8 +279,8 @@ void main() {
expect(
(globals.logger as BufferLogger).traceText,
stringContainsInOrder(<String>[
'Building native assets for [ios_arm64] debug.',
'Building native assets for [ios_arm64] done.',
'Building native assets for [ios_arm64, ios_x64] debug.',
'Building native assets for [ios_arm64, ios_x64] done.',
]),
);
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ void main() {
'-create',
'-output',
dylibPath,
'libbar.dylib',
'arm64/libbar.dylib',
'x64/libbar.dylib',
],
),
if (!flutterTester)
Expand Down Expand Up @@ -291,7 +292,7 @@ void main() {
await packageConfig.parent.create();
await packageConfig.create();
final (Uri? nativeAssetsYaml, _) = await buildNativeAssetsMacOS(
darwinArchs: <DarwinArch>[DarwinArch.arm64],
darwinArchs: <DarwinArch>[DarwinArch.arm64, DarwinArch.x86_64],
projectUri: projectUri,
buildMode: BuildMode.debug,
fileSystem: fileSystem,
Expand All @@ -300,13 +301,13 @@ void main() {
packagesWithNativeAssetsResult: <Package>[
Package('bar', projectUri),
],
buildResult: FakeNativeAssetsBuilderResult(
onBuild: (native_assets_cli.Target target) => FakeNativeAssetsBuilderResult(
assets: <Asset>[
Asset(
id: 'package:bar/bar.dart',
linkMode: LinkMode.dynamic,
target: native_assets_cli.Target.macOSArm64,
path: AssetAbsolutePath(Uri.file('libbar.dylib')),
target: target,
path: AssetAbsolutePath(Uri.file('${target.architecture}/libbar.dylib')),
),
],
),
Expand All @@ -315,8 +316,8 @@ void main() {
expect(
(globals.logger as BufferLogger).traceText,
stringContainsInOrder(<String>[
'Building native assets for [macos_arm64] debug.',
'Building native assets for [macos_arm64] done.',
'Building native assets for [macos_arm64, macos_x64] debug.',
'Building native assets for [macos_arm64, macos_x64] done.',
]),
);
expect(
Expand Down