Skip to content

Commit 8876bcc

Browse files
Use separate artifacts for arm64 and x64 versions of gen_snapshot on Apple platforms (#164419)
Fixes flutter/flutter#156175
1 parent 50f6b48 commit 8876bcc

File tree

5 files changed

+44
-19
lines changed

5 files changed

+44
-19
lines changed

packages/flutter_tools/lib/src/artifacts.dart

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import 'globals.dart' as globals;
2929
enum Artifact {
3030
/// The tool which compiles a dart kernel file into native code.
3131
genSnapshot,
32+
genSnapshotArm64,
33+
genSnapshotX64,
3234

3335
/// The flutter tester binary.
3436
flutterTester,
@@ -173,6 +175,10 @@ String? _artifactToFileName(Artifact artifact, Platform hostPlatform, [BuildMode
173175
switch (artifact) {
174176
case Artifact.genSnapshot:
175177
return 'gen_snapshot';
178+
case Artifact.genSnapshotArm64:
179+
return 'gen_snapshot_arm64';
180+
case Artifact.genSnapshotX64:
181+
return 'gen_snapshot_x64';
176182
case Artifact.flutterTester:
177183
return 'flutter_tester$exe';
178184
case Artifact.flutterFramework:
@@ -543,6 +549,8 @@ class CachedArtifacts implements Artifacts {
543549
final String engineDir = _getEngineArtifactsPath(platform, mode)!;
544550
switch (artifact) {
545551
case Artifact.genSnapshot:
552+
case Artifact.genSnapshotArm64:
553+
case Artifact.genSnapshotX64:
546554
return _fileSystem.path.join(engineDir, _artifactToFileName(artifact, _platform));
547555
case Artifact.engineDartSdkPath:
548556
case Artifact.engineDartBinary:
@@ -581,6 +589,8 @@ class CachedArtifacts implements Artifacts {
581589
final String engineDir = _getEngineArtifactsPath(platform, mode)!;
582590
switch (artifact) {
583591
case Artifact.genSnapshot:
592+
case Artifact.genSnapshotArm64:
593+
case Artifact.genSnapshotX64:
584594
assert(mode != BuildMode.debug, 'Artifact $artifact only available in non-debug mode.');
585595

586596
// TODO(cbracken): Build Android gen_snapshot as Arm64 binary to run
@@ -636,6 +646,8 @@ class CachedArtifacts implements Artifacts {
636646
) {
637647
switch (artifact) {
638648
case Artifact.genSnapshot:
649+
case Artifact.genSnapshotArm64:
650+
case Artifact.genSnapshotX64:
639651
case Artifact.flutterXcframework:
640652
final String artifactFileName = _artifactToFileName(artifact, _platform)!;
641653
final String engineDir = _getEngineArtifactsPath(platform, mode)!;
@@ -686,6 +698,9 @@ class CachedArtifacts implements Artifacts {
686698
case Artifact.genSnapshot:
687699
final String genSnapshot = mode.isRelease ? 'gen_snapshot_product' : 'gen_snapshot';
688700
return _fileSystem.path.join(root, runtime, 'dart_binaries', genSnapshot);
701+
case Artifact.genSnapshotArm64:
702+
case Artifact.genSnapshotX64:
703+
throw ArgumentError('$artifact is not available on this platform');
689704
case Artifact.flutterPatchedSdkPath:
690705
const String artifactFileName = 'flutter_runner_patched_sdk';
691706
return _fileSystem.path.join(root, runtime, artifactFileName);
@@ -741,6 +756,8 @@ class CachedArtifacts implements Artifacts {
741756
String _getHostArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode? mode) {
742757
switch (artifact) {
743758
case Artifact.genSnapshot:
759+
case Artifact.genSnapshotArm64:
760+
case Artifact.genSnapshotX64:
744761
// For script snapshots any gen_snapshot binary will do. Returning gen_snapshot for
745762
// android_arm in profile mode because it is available on all supported host platforms.
746763
return _getAndroidArtifactPath(artifact, TargetPlatform.android_arm, BuildMode.profile);
@@ -1178,7 +1195,9 @@ class CachedLocalEngineArtifacts implements Artifacts {
11781195
isDirectoryArtifact ? null : _artifactToFileName(artifact, _platform, mode);
11791196
switch (artifact) {
11801197
case Artifact.genSnapshot:
1181-
return _genSnapshotPath();
1198+
case Artifact.genSnapshotArm64:
1199+
case Artifact.genSnapshotX64:
1200+
return _genSnapshotPath(artifact);
11821201
case Artifact.flutterTester:
11831202
return _flutterTesterPath(platform!);
11841203
case Artifact.isolateSnapshotData:
@@ -1344,15 +1363,15 @@ class CachedLocalEngineArtifacts implements Artifacts {
13441363
return _fileSystem.path.join(localEngineInfo.targetOutPath, 'flutter_web_sdk');
13451364
}
13461365

1347-
String _genSnapshotPath() {
1366+
String _genSnapshotPath(Artifact artifact) {
13481367
const List<String> clangDirs = <String>[
13491368
'.',
13501369
'clang_x64',
13511370
'clang_x86',
13521371
'clang_i386',
13531372
'clang_arm64',
13541373
];
1355-
final String genSnapshotName = _artifactToFileName(Artifact.genSnapshot, _platform)!;
1374+
final String genSnapshotName = _artifactToFileName(artifact, _platform)!;
13561375
for (final String clangDir in clangDirs) {
13571376
final String genSnapshotPath = _fileSystem.path.join(
13581377
localEngineInfo.targetOutPath,
@@ -1422,6 +1441,8 @@ class CachedLocalWebSdkArtifacts implements Artifacts {
14221441
_artifactToFileName(artifact, _platform, mode),
14231442
);
14241443
case Artifact.genSnapshot:
1444+
case Artifact.genSnapshotArm64:
1445+
case Artifact.genSnapshotX64:
14251446
case Artifact.flutterTester:
14261447
case Artifact.flutterFramework:
14271448
case Artifact.flutterFrameworkDsym:

packages/flutter_tools/lib/src/base/build.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ class GenSnapshot {
3535
final Artifacts _artifacts;
3636
final ProcessUtils _processUtils;
3737

38-
String getSnapshotterPath(SnapshotType snapshotType) {
38+
String getSnapshotterPath(SnapshotType snapshotType, Artifact artifact) {
3939
return _artifacts.getArtifactPath(
40-
Artifact.genSnapshot,
40+
artifact,
4141
platform: snapshotType.platform,
4242
mode: snapshotType.mode,
4343
);
@@ -63,16 +63,20 @@ class GenSnapshot {
6363
assert(snapshotType.platform != TargetPlatform.ios || darwinArch != null);
6464
final List<String> args = <String>[...additionalArgs];
6565

66-
String snapshotterPath = getSnapshotterPath(snapshotType);
67-
6866
// iOS and macOS have separate gen_snapshot binaries for each target
6967
// architecture (iOS: armv7, arm64; macOS: x86_64, arm64). Select the right
7068
// one for the target architecture in question.
69+
Artifact genSnapshotArtifact;
7170
if (snapshotType.platform == TargetPlatform.ios ||
7271
snapshotType.platform == TargetPlatform.darwin) {
73-
snapshotterPath += '_${darwinArch!.dartName}';
72+
genSnapshotArtifact =
73+
darwinArch == DarwinArch.arm64 ? Artifact.genSnapshotArm64 : Artifact.genSnapshotX64;
74+
} else {
75+
genSnapshotArtifact = Artifact.genSnapshot;
7476
}
7577

78+
final String snapshotterPath = getSnapshotterPath(snapshotType, genSnapshotArtifact);
79+
7680
return _processUtils.stream(<String>[
7781
snapshotterPath,
7882
...args,

packages/flutter_tools/test/general.shard/base/build_test.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ void main() {
8181

8282
testWithoutContext('iOS arm64', () async {
8383
final String genSnapshotPath = artifacts.getArtifactPath(
84-
Artifact.genSnapshot,
84+
Artifact.genSnapshotArm64,
8585
platform: TargetPlatform.ios,
8686
mode: BuildMode.release,
8787
);
8888
processManager.addCommand(
89-
FakeCommand(command: <String>['${genSnapshotPath}_arm64', '--additional_arg']),
89+
FakeCommand(command: <String>[genSnapshotPath, '--additional_arg']),
9090
);
9191

9292
final int result = await genSnapshot.run(
@@ -197,14 +197,14 @@ void main() {
197197
final String assembly = fileSystem.path.join(outputPath, 'snapshot_assembly.S');
198198
final String debugPath = fileSystem.path.join('foo', 'app.ios-arm64.symbols');
199199
final String genSnapshotPath = artifacts.getArtifactPath(
200-
Artifact.genSnapshot,
200+
Artifact.genSnapshotArm64,
201201
platform: TargetPlatform.ios,
202202
mode: BuildMode.profile,
203203
);
204204
processManager.addCommands(<FakeCommand>[
205205
FakeCommand(
206206
command: <String>[
207-
'${genSnapshotPath}_arm64',
207+
genSnapshotPath,
208208
'--deterministic',
209209
'--snapshot_kind=app-aot-assembly',
210210
'--assembly=$assembly',
@@ -272,14 +272,14 @@ void main() {
272272
final String outputPath = fileSystem.path.join('build', 'foo');
273273
final String assembly = fileSystem.path.join(outputPath, 'snapshot_assembly.S');
274274
final String genSnapshotPath = artifacts.getArtifactPath(
275-
Artifact.genSnapshot,
275+
Artifact.genSnapshotArm64,
276276
platform: TargetPlatform.ios,
277277
mode: BuildMode.profile,
278278
);
279279
processManager.addCommands(<FakeCommand>[
280280
FakeCommand(
281281
command: <String>[
282-
'${genSnapshotPath}_arm64',
282+
genSnapshotPath,
283283
'--deterministic',
284284
'--snapshot_kind=app-aot-assembly',
285285
'--assembly=$assembly',
@@ -343,14 +343,14 @@ void main() {
343343
testWithoutContext('builds iOS snapshot', () async {
344344
final String outputPath = fileSystem.path.join('build', 'foo');
345345
final String genSnapshotPath = artifacts.getArtifactPath(
346-
Artifact.genSnapshot,
346+
Artifact.genSnapshotArm64,
347347
platform: TargetPlatform.ios,
348348
mode: BuildMode.release,
349349
);
350350
processManager.addCommands(<FakeCommand>[
351351
FakeCommand(
352352
command: <String>[
353-
'${genSnapshotPath}_arm64',
353+
genSnapshotPath,
354354
'--deterministic',
355355
'--snapshot_kind=app-aot-assembly',
356356
'--assembly=${fileSystem.path.join(outputPath, 'snapshot_assembly.S')}',

packages/flutter_tools/test/general.shard/build_system/targets/common_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ void main() {
794794
FakeCommand(
795795
command: <String>[
796796
// This path is not known by the cache due to the iOS gen_snapshot split.
797-
'Artifact.genSnapshot.TargetPlatform.ios.profile_arm64',
797+
'Artifact.genSnapshotArm64.TargetPlatform.ios.profile',
798798
'--deterministic',
799799
'--write-v8-snapshot-profile-to=code_size_1/snapshot.arm64.json',
800800
'--trace-precompiler-to=code_size_1/trace.arm64.json',

packages/flutter_tools/test/general.shard/build_system/targets/macos_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ void main() {
813813
processManager.addCommands(<FakeCommand>[
814814
FakeCommand(
815815
command: <String>[
816-
'Artifact.genSnapshot.TargetPlatform.darwin.release_arm64',
816+
'Artifact.genSnapshotArm64.TargetPlatform.darwin.release',
817817
'--deterministic',
818818
'--snapshot_kind=app-aot-assembly',
819819
'--assembly=${environment.buildDir.childFile('arm64/snapshot_assembly.S').path}',
@@ -822,7 +822,7 @@ void main() {
822822
),
823823
FakeCommand(
824824
command: <String>[
825-
'Artifact.genSnapshot.TargetPlatform.darwin.release_x64',
825+
'Artifact.genSnapshotX64.TargetPlatform.darwin.release',
826826
'--deterministic',
827827
'--snapshot_kind=app-aot-assembly',
828828
'--assembly=${environment.buildDir.childFile('x86_64/snapshot_assembly.S').path}',

0 commit comments

Comments
 (0)