Skip to content
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

[macOS] Use arm64 snapshot in arm64 App.framework #100504

Merged
merged 1 commit into from
Mar 22, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/flutter_tools/lib/src/base/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ class GenSnapshot {

String snapshotterPath = getSnapshotterPath(snapshotType);

// iOS has a separate gen_snapshot for armv7 and arm64 in the same,
// directory. So we need to select the right one.
if (snapshotType.platform == TargetPlatform.ios) {
snapshotterPath += '_${getNameForDarwinArch(darwinArch!)}';
// iOS and macOS have separate gen_snapshot binaries for each target
// architecture (iOS: armv7, arm64; macOS: x86_64, arm64). Select the right
// one for the target architecture in question.
if (snapshotType.platform == TargetPlatform.ios ||
snapshotType.platform == TargetPlatform.darwin) {
snapshotterPath += '_${getDartNameForDarwinArch(darwinArch!)}';
}

return _processUtils.stream(
Expand Down
25 changes: 25 additions & 0 deletions packages/flutter_tools/lib/src/build_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,31 @@ List<DarwinArch> defaultIOSArchsForEnvironment(
];
}

// Returns the Dart SDK's name for the specified target architecture.
//
// When building for Darwin platforms, the tool invokes architecture-specific
// variants of `gen_snapshot`, one for each target architecture. The output
// instructions are then built into architecture-specific binaries, which are
// merged into a universal binary using the `lipo` tool.
String getDartNameForDarwinArch(DarwinArch arch) {
switch (arch) {
case DarwinArch.armv7:
return 'armv7';
case DarwinArch.arm64:
return 'arm64';
case DarwinArch.x86_64:
return 'x64';
}
}

// Returns Apple's name for the specified target architecture.
//
// When invoking Apple tools such as `xcodebuild` or `lipo`, the tool often
// passes one or more target architectures as paramters. The names returned by
// this function reflect Apple's name for the specified architecture.
//
// For consistency with developer expectations, Flutter outputs also use these
// architecture names in its build products for Darwin target platforms.
String getNameForDarwinArch(DarwinArch arch) {
switch (arch) {
case DarwinArch.armv7:
Expand Down
12 changes: 12 additions & 0 deletions packages/flutter_tools/test/general.shard/build_info_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ void main() {
});
});

testWithoutContext('getDartNameForDarwinArch returns name used in Dart SDK', () {
expect(getDartNameForDarwinArch(DarwinArch.armv7), 'armv7');
expect(getDartNameForDarwinArch(DarwinArch.arm64), 'arm64');
expect(getDartNameForDarwinArch(DarwinArch.x86_64), 'x64');
});

testWithoutContext('getNameForDarwinArch returns Apple names', () {
expect(getNameForDarwinArch(DarwinArch.armv7), 'armv7');
expect(getNameForDarwinArch(DarwinArch.arm64), 'arm64');
expect(getNameForDarwinArch(DarwinArch.x86_64), 'x86_64');
});

testWithoutContext('getNameForTargetPlatform on Darwin arches', () {
expect(getNameForTargetPlatform(TargetPlatform.ios, darwinArch: DarwinArch.arm64), 'ios-arm64');
expect(getNameForTargetPlatform(TargetPlatform.ios, darwinArch: DarwinArch.armv7), 'ios-armv7');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,15 +384,15 @@ void main() {

processManager.addCommands(<FakeCommand>[
FakeCommand(command: <String>[
'Artifact.genSnapshot.TargetPlatform.darwin.release',
'Artifact.genSnapshot.TargetPlatform.darwin.release_arm64',
'--deterministic',
'--snapshot_kind=app-aot-assembly',
'--assembly=${environment.buildDir.childFile('arm64/snapshot_assembly.S').path}',
'--strip',
environment.buildDir.childFile('app.dill').path
]),
FakeCommand(command: <String>[
'Artifact.genSnapshot.TargetPlatform.darwin.release',
'Artifact.genSnapshot.TargetPlatform.darwin.release_x64',
'--deterministic',
'--snapshot_kind=app-aot-assembly',
'--assembly=${environment.buildDir.childFile('x86_64/snapshot_assembly.S').path}',
Expand Down