Enable bitcode compilation for AOT (#36471)
diff --git a/packages/flutter_tools/test/general.shard/base/build_test.dart b/packages/flutter_tools/test/general.shard/base/build_test.dart
index 13f96b9..bfbda39 100644
--- a/packages/flutter_tools/test/general.shard/base/build_test.dart
+++ b/packages/flutter_tools/test/general.shard/base/build_test.dart
@@ -116,6 +116,13 @@
when(mockArtifacts.getArtifactPath(Artifact.snapshotDart,
platform: anyNamed('platform'), mode: mode)).thenReturn(kSnapshotDart);
}
+
+ when(mockXcode.dsymutil(any)).thenAnswer((_) => Future<RunResult>.value(
+ RunResult(
+ ProcessResult(1, 0, '', ''),
+ <String>['command name', 'arguments...']),
+ ),
+ );
});
final Map<Type, Generator> contextOverrides = <Type, Generator>{
@@ -135,6 +142,7 @@
mainPath: 'main.dill',
packagesPath: '.packages',
outputPath: outputPath,
+ bitcode: false,
), isNot(equals(0)));
}, overrides: contextOverrides);
@@ -146,6 +154,7 @@
mainPath: 'main.dill',
packagesPath: '.packages',
outputPath: outputPath,
+ bitcode: false,
), isNot(0));
}, overrides: contextOverrides);
@@ -157,17 +166,19 @@
mainPath: 'main.dill',
packagesPath: '.packages',
outputPath: outputPath,
+ bitcode: false,
), isNot(0));
}, overrides: contextOverrides);
- testUsingContext('builds iOS armv7 profile AOT snapshot', () async {
+ testUsingContext('iOS debug AOT with bitcode uses right flags', () async {
fs.file('main.dill').writeAsStringSync('binary magic');
final String outputPath = fs.path.join('build', 'foo');
fs.directory(outputPath).createSync(recursive: true);
+ final String assembly = fs.path.join(outputPath, 'snapshot_assembly.S');
genSnapshot.outputs = <String, String>{
- fs.path.join(outputPath, 'snapshot_assembly.S'): '',
+ assembly: 'blah blah\n.section __DWARF\nblah blah\n',
};
final RunResult successResult = RunResult(ProcessResult(1, 0, '', ''), <String>['command name', 'arguments...']);
@@ -181,6 +192,7 @@
packagesPath: '.packages',
outputPath: outputPath,
iosArch: IOSArch.armv7,
+ bitcode: true,
);
expect(genSnapshotExitCode, 0);
@@ -190,11 +202,70 @@
expect(genSnapshot.additionalArgs, <String>[
'--deterministic',
'--snapshot_kind=app-aot-assembly',
- '--assembly=${fs.path.join(outputPath, 'snapshot_assembly.S')}',
+ '--assembly=$assembly',
'--no-sim-use-hardfp',
'--no-use-integer-division',
'main.dill',
]);
+
+ verify(xcode.cc(argThat(contains('-fembed-bitcode')))).called(1);
+ verify(xcode.clang(argThat(contains('-fembed-bitcode')))).called(1);
+ verify(xcode.dsymutil(any)).called(1);
+
+ final File assemblyFile = fs.file(assembly);
+ final File assemblyBitcodeFile = fs.file('$assembly.bitcode');
+ expect(assemblyFile.existsSync(), true);
+ expect(assemblyBitcodeFile.existsSync(), true);
+ expect(assemblyFile.readAsStringSync().contains('.section __DWARF'), true);
+ expect(assemblyBitcodeFile.readAsStringSync().contains('.section __DWARF'), false);
+ }, overrides: contextOverrides);
+
+ testUsingContext('builds iOS armv7 profile AOT snapshot', () async {
+ fs.file('main.dill').writeAsStringSync('binary magic');
+
+ final String outputPath = fs.path.join('build', 'foo');
+ fs.directory(outputPath).createSync(recursive: true);
+
+ final String assembly = fs.path.join(outputPath, 'snapshot_assembly.S');
+ genSnapshot.outputs = <String, String>{
+ assembly: 'blah blah\n.section __DWARF\nblah blah\n',
+ };
+
+ final RunResult successResult = RunResult(ProcessResult(1, 0, '', ''), <String>['command name', 'arguments...']);
+ when(xcode.cc(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
+ when(xcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
+
+ final int genSnapshotExitCode = await snapshotter.build(
+ platform: TargetPlatform.ios,
+ buildMode: BuildMode.profile,
+ mainPath: 'main.dill',
+ packagesPath: '.packages',
+ outputPath: outputPath,
+ iosArch: IOSArch.armv7,
+ bitcode: false,
+ );
+
+ expect(genSnapshotExitCode, 0);
+ expect(genSnapshot.callCount, 1);
+ expect(genSnapshot.snapshotType.platform, TargetPlatform.ios);
+ expect(genSnapshot.snapshotType.mode, BuildMode.profile);
+ expect(genSnapshot.additionalArgs, <String>[
+ '--deterministic',
+ '--snapshot_kind=app-aot-assembly',
+ '--assembly=$assembly',
+ '--no-sim-use-hardfp',
+ '--no-use-integer-division',
+ 'main.dill',
+ ]);
+ verifyNever(xcode.cc(argThat(contains('-fembed-bitcode'))));
+ verifyNever(xcode.clang(argThat(contains('-fembed-bitcode'))));
+ verify(xcode.dsymutil(any)).called(1);
+
+ final File assemblyFile = fs.file(assembly);
+ final File assemblyBitcodeFile = fs.file('$assembly.bitcode');
+ expect(assemblyFile.existsSync(), true);
+ expect(assemblyBitcodeFile.existsSync(), false);
+ expect(assemblyFile.readAsStringSync().contains('.section __DWARF'), true);
}, overrides: contextOverrides);
testUsingContext('builds iOS arm64 profile AOT snapshot', () async {
@@ -218,6 +289,7 @@
packagesPath: '.packages',
outputPath: outputPath,
iosArch: IOSArch.arm64,
+ bitcode: false,
);
expect(genSnapshotExitCode, 0);
@@ -253,6 +325,7 @@
packagesPath: '.packages',
outputPath: outputPath,
iosArch: IOSArch.armv7,
+ bitcode: false,
);
expect(genSnapshotExitCode, 0);
@@ -290,6 +363,7 @@
packagesPath: '.packages',
outputPath: outputPath,
iosArch: IOSArch.arm64,
+ bitcode: false,
);
expect(genSnapshotExitCode, 0);
@@ -316,6 +390,7 @@
mainPath: 'main.dill',
packagesPath: '.packages',
outputPath: outputPath,
+ bitcode: false,
);
expect(genSnapshotExitCode, 0);
@@ -345,6 +420,7 @@
mainPath: 'main.dill',
packagesPath: '.packages',
outputPath: outputPath,
+ bitcode: false,
);
expect(genSnapshotExitCode, 0);
@@ -380,6 +456,7 @@
mainPath: 'main.dill',
packagesPath: '.packages',
outputPath: outputPath,
+ bitcode: false,
);
expect(genSnapshotExitCode, 0);