Skip to content

Commit 35afe1b

Browse files
authored
Stop embedding bitcode for iOS in tool (#112831)
1 parent 8c0aa6c commit 35afe1b

File tree

22 files changed

+71
-508
lines changed

22 files changed

+71
-508
lines changed

dev/devicelab/bin/tasks/build_ios_framework_module_test.dart

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ Future<void> _testBuildIosFramework(Directory projectDir, { bool isModule = fals
171171
);
172172

173173
await _checkDylib(appFrameworkPath);
174-
await _checkBitcode(appFrameworkPath, mode);
175174

176175
final String aotSymbols = await _dylibSymbols(appFrameworkPath);
177176

@@ -228,15 +227,14 @@ Future<void> _testBuildIosFramework(Directory projectDir, { bool isModule = fals
228227
section("Check all modes' engine dylib");
229228

230229
for (final String mode in <String>['Debug', 'Profile', 'Release']) {
231-
final String engineBinary = path.join(
230+
checkFileExists(path.join(
232231
outputPath,
233232
mode,
234233
'Flutter.xcframework',
235234
'ios-arm64',
236235
'Flutter.framework',
237236
'Flutter',
238-
);
239-
await _checkBitcode(engineBinary, mode);
237+
));
240238

241239
checkFileExists(path.join(
242240
outputPath,
@@ -836,15 +834,6 @@ Future<void> _checkStatic(String pathToLibrary) async {
836834
}
837835
}
838836

839-
Future<void> _checkBitcode(String frameworkPath, String mode) async {
840-
checkFileExists(frameworkPath);
841-
842-
// Bitcode only needed in Release mode for archiving.
843-
if (mode == 'Release' && !await containsBitcode(frameworkPath)) {
844-
throw TaskResult.failure('$frameworkPath does not contain bitcode');
845-
}
846-
}
847-
848837
Future<String> _dylibSymbols(String pathToDylib) {
849838
return eval('nm', <String>[
850839
'-g',

dev/devicelab/lib/framework/ios.dart

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -47,43 +47,6 @@ Future<String?> minPhoneOSVersion(String pathToBinary) async {
4747
return minVersion;
4848
}
4949

50-
Future<bool> containsBitcode(String pathToBinary) async {
51-
// See: https://stackoverflow.com/questions/32755775/how-to-check-a-static-library-is-built-contain-bitcode
52-
final String loadCommands = await eval('otool', <String>[
53-
'-l',
54-
'-arch',
55-
'arm64',
56-
pathToBinary,
57-
]);
58-
if (!loadCommands.contains('__LLVM')) {
59-
return false;
60-
}
61-
// Presence of the section may mean a bitcode marker was embedded (size=1), but there is no content.
62-
if (!loadCommands.contains('size 0x0000000000000001')) {
63-
return true;
64-
}
65-
// Check the false positives: size=1 wasn't referencing the __LLVM section.
66-
67-
bool emptyBitcodeMarkerFound = false;
68-
// Section
69-
// sectname __bundle
70-
// segname __LLVM
71-
// addr 0x003c4000
72-
// size 0x0042b633
73-
// offset 3932160
74-
// ...
75-
final List<String> lines = LineSplitter.split(loadCommands).toList();
76-
lines.asMap().forEach((int index, String line) {
77-
if (line.contains('segname __LLVM') && lines.length - index - 1 > 3) {
78-
emptyBitcodeMarkerFound |= lines
79-
.skip(index - 1)
80-
.take(4)
81-
.any((String line) => line.contains(' size 0x0000000000000001'));
82-
}
83-
});
84-
return !emptyBitcodeMarkerFound;
85-
}
86-
8750
/// Creates and boots a new simulator, passes the new simulator's identifier to
8851
/// `testFunction`.
8952
///

packages/flutter_tools/bin/podhelper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ def flutter_additional_ios_build_settings(target)
6565
# Skip other updates if it's not a Flutter plugin (transitive dependency).
6666
next unless target.dependencies.any? { |dependency| dependency.name == 'Flutter' }
6767

68+
# Bitcode is deprecated, Flutter.framework bitcode blob will have been stripped.
69+
build_configuration.build_settings['ENABLE_BITCODE'] = 'NO'
70+
6871
# Profile can't be derived from the CocoaPods build configuration. Use release framework (for linking only).
6972
configuration_engine_dir = build_configuration.type == :debug ? debug_framework_dir : release_framework_dir
7073
Dir.new(configuration_engine_dir).each_child do |xcframework_file|

packages/flutter_tools/bin/xcode_backend.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,6 @@ class Context {
333333
);
334334
}
335335

336-
String bitcodeFlag = '';
337-
if (environment['ENABLE_BITCODE'] == 'YES' && environment['ACTION'] == 'install') {
338-
bitcodeFlag = 'true';
339-
}
340-
341336
final List<String> flutterArgs = <String>[];
342337

343338
if (verbose) {
@@ -365,7 +360,6 @@ class Context {
365360
'-dTreeShakeIcons=${environment['TREE_SHAKE_ICONS'] ?? ''}',
366361
'-dTrackWidgetCreation=${environment['TRACK_WIDGET_CREATION'] ?? ''}',
367362
'-dDartObfuscation=${environment['DART_OBFUSCATION'] ?? ''}',
368-
'-dEnableBitcode=$bitcodeFlag',
369363
'-dAction=${environment['ACTION'] ?? ''}',
370364
'--ExtraGenSnapshotOptions=${environment['EXTRA_GEN_SNAPSHOT_OPTIONS'] ?? ''}',
371365
'--DartDefines=${environment['DART_DEFINES'] ?? ''}',

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,11 @@ class AOTSnapshotter {
116116
DarwinArch? darwinArch,
117117
String? sdkRoot,
118118
List<String> extraGenSnapshotOptions = const <String>[],
119-
required bool bitcode,
120119
String? splitDebugInfo,
121120
required bool dartObfuscation,
122121
bool quiet = false,
123122
}) async {
124123
assert(platform != TargetPlatform.ios || darwinArch != null);
125-
if (bitcode && platform != TargetPlatform.ios) {
126-
_logger.printError('Bitcode is only supported for iOS.');
127-
return 1;
128-
}
129124

130125
if (!_isValidAotPlatform(platform, buildMode)) {
131126
_logger.printError('${getNameForTargetPlatform(platform)} does not support AOT compilation.');
@@ -244,7 +239,6 @@ class AOTSnapshotter {
244239
sdkRoot: sdkRoot,
245240
assemblyPath: assembly,
246241
outputPath: outputDir.path,
247-
bitcode: bitcode,
248242
quiet: quiet,
249243
stripAfterBuild: stripAfterBuild,
250244
extractAppleDebugSymbols: extractAppleDebugSymbols
@@ -262,7 +256,6 @@ class AOTSnapshotter {
262256
String? sdkRoot,
263257
required String assemblyPath,
264258
required String outputPath,
265-
required bool bitcode,
266259
required bool quiet,
267260
required bool stripAfterBuild,
268261
required bool extractAppleDebugSymbols
@@ -286,12 +279,10 @@ class AOTSnapshotter {
286279
],
287280
];
288281

289-
const String embedBitcodeArg = '-fembed-bitcode';
290282
final String assemblyO = _fileSystem.path.join(outputPath, 'snapshot_assembly.o');
291283

292284
final RunResult compileResult = await _xcode.cc(<String>[
293285
...commonBuildOptions,
294-
if (bitcode) embedBitcodeArg,
295286
'-c',
296287
assemblyPath,
297288
'-o',
@@ -311,7 +302,6 @@ class AOTSnapshotter {
311302
'-Xlinker', '-rpath', '-Xlinker', '@executable_path/Frameworks',
312303
'-Xlinker', '-rpath', '-Xlinker', '@loader_path/Frameworks',
313304
'-install_name', '@rpath/App.framework/App',
314-
if (bitcode) embedBitcodeArg,
315305
'-o', appLib,
316306
assemblyO,
317307
];

packages/flutter_tools/lib/src/build_info.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -942,9 +942,6 @@ const String kTargetPlatform = 'TargetPlatform';
942942
/// The define to control what target file is used.
943943
const String kTargetFile = 'TargetFile';
944944

945-
/// The define to control whether the AOT snapshot is built with bitcode.
946-
const String kBitcodeFlag = 'EnableBitcode';
947-
948945
/// Whether to enable or disable track widget creation.
949946
const String kTrackWidgetCreation = 'TrackWidgetCreation';
950947

packages/flutter_tools/lib/src/build_system/targets/android.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ class AndroidAot extends AotElfBase {
250250
buildMode: buildMode,
251251
mainPath: environment.buildDir.childFile('app.dill').path,
252252
outputPath: output.path,
253-
bitcode: false,
254253
extraGenSnapshotOptions: extraGenSnapshotOptions,
255254
splitDebugInfo: splitDebugInfo,
256255
dartObfuscation: dartObfuscation,

packages/flutter_tools/lib/src/build_system/targets/common.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ abstract class AotElfBase extends Target {
296296
buildMode: buildMode,
297297
mainPath: environment.buildDir.childFile('app.dill').path,
298298
outputPath: outputPath,
299-
bitcode: false,
300299
extraGenSnapshotOptions: extraGenSnapshotOptions,
301300
splitDebugInfo: splitDebugInfo,
302301
dartObfuscation: dartObfuscation,

packages/flutter_tools/lib/src/build_system/targets/ios.dart

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ abstract class AotAssemblyBase extends Target {
5656
}
5757

5858
final List<String> extraGenSnapshotOptions = decodeCommaSeparated(environment.defines, kExtraGenSnapshotOptions);
59-
final bool bitcode = environment.defines[kBitcodeFlag] == 'true';
6059
final BuildMode buildMode = getBuildModeForName(environmentBuildMode);
6160
final TargetPlatform targetPlatform = getTargetPlatformForName(environmentTargetPlatform);
6261
final String? splitDebugInfo = environment.defines[kSplitDebugInfo];
@@ -101,7 +100,6 @@ abstract class AotAssemblyBase extends Target {
101100
outputPath: environment.fileSystem.path.join(buildOutputPath, getNameForDarwinArch(darwinArch)),
102101
darwinArch: darwinArch,
103102
sdkRoot: sdkRoot,
104-
bitcode: bitcode,
105103
quiet: true,
106104
splitDebugInfo: splitDebugInfo,
107105
dartObfuscation: dartObfuscation,
@@ -287,9 +285,6 @@ abstract class UnpackIOS extends Target {
287285
if (archs == null) {
288286
throw MissingDefineException(kIosArchs, name);
289287
}
290-
if (environment.defines[kBitcodeFlag] == null) {
291-
throw MissingDefineException(kBitcodeFlag, name);
292-
}
293288
_copyFramework(environment, sdkRoot);
294289

295290
final File frameworkBinary = environment.outputDir.childDirectory('Flutter.framework').childFile('Flutter');
@@ -298,7 +293,9 @@ abstract class UnpackIOS extends Target {
298293
throw Exception('Binary $frameworkBinaryPath does not exist, cannot thin');
299294
}
300295
_thinFramework(environment, frameworkBinaryPath, archs);
301-
_bitcodeStripFramework(environment, frameworkBinaryPath);
296+
if (buildMode == BuildMode.release) {
297+
_bitcodeStripFramework(environment, frameworkBinaryPath);
298+
}
302299
_signFramework(environment, frameworkBinaryPath, buildMode);
303300
}
304301

@@ -373,16 +370,14 @@ abstract class UnpackIOS extends Target {
373370
}
374371
}
375372

376-
/// Destructively strip bitcode from the framework, if needed.
373+
/// Destructively strip bitcode from the framework. This can be removed
374+
/// when the framework is no longer built with bitcode.
377375
void _bitcodeStripFramework(Environment environment, String frameworkBinaryPath) {
378-
if (environment.defines[kBitcodeFlag] == 'true') {
379-
return;
380-
}
381376
final ProcessResult stripResult = environment.processManager.runSync(<String>[
382377
'xcrun',
383378
'bitcode_strip',
384379
frameworkBinaryPath,
385-
'-m', // leave the bitcode marker.
380+
'-r', // Delete the bitcode segment.
386381
'-o',
387382
frameworkBinaryPath,
388383
]);
@@ -669,7 +664,6 @@ Future<void> _createStubAppFramework(File outputFile, Environment environment,
669664
for (String arch in iosArchNames ?? <String>{}) ...<String>['-arch', arch],
670665
stubSource.path,
671666
'-dynamiclib',
672-
'-fembed-bitcode-marker',
673667
// Keep version in sync with AOTSnapshotter flag
674668
if (environmentType == EnvironmentType.physical)
675669
'-miphoneos-version-min=11.0'

packages/flutter_tools/lib/src/build_system/targets/macos.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ class CompileMacOSFramework extends Target {
285285
}
286286

287287
pending.add(snapshotter.build(
288-
bitcode: false,
289288
buildMode: buildMode,
290289
mainPath: environment.buildDir.childFile('app.dill').path,
291290
outputPath: environment.fileSystem.path.join(buildOutputPath, getNameForDarwinArch(darwinArch)),

0 commit comments

Comments
 (0)