Generate bitcode for plugin frameworks for flutter build ios-framework (#49102)

This commit is contained in:
Jenn Magder
2020-01-21 16:38:03 -08:00
committed by Flutter GitHub Bot
parent 4c32ae8e91
commit 2a7d57791d
4 changed files with 111 additions and 29 deletions

View File

@@ -159,7 +159,7 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {
cache ??= globals.cache;
for (final BuildMode mode in buildModes) {
globals.printStatus('Building framework for $iosProject in ${getNameForBuildMode(mode)} mode...');
globals.printStatus('Building frameworks for $iosProject in ${getNameForBuildMode(mode)} mode...');
final String xcodeBuildConfiguration = toTitleCase(getNameForBuildMode(mode));
final Directory modeDirectory = outputDirectory.childDirectory(xcodeBuildConfiguration);
@@ -175,7 +175,7 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {
produceFlutterPodspec(mode, modeDirectory);
} else {
// Copy Flutter.framework.
await _produceFlutterFramework(outputDirectory, mode, iPhoneBuildOutput, simulatorBuildOutput, modeDirectory);
await _produceFlutterFramework(mode, modeDirectory);
}
// Build aot, create module.framework and copy.
@@ -266,10 +266,7 @@ end
}
Future<void> _produceFlutterFramework(
Directory outputDirectory,
BuildMode mode,
Directory iPhoneBuildOutput,
Directory simulatorBuildOutput,
Directory modeDirectory,
) async {
final Status status = globals.logger.startProgress(
@@ -446,6 +443,15 @@ end
final Status status = globals.logger.startProgress(
' ├─Building plugins...', timeout: timeoutConfiguration.slowOperation);
try {
// Regardless of the last "flutter build" build mode,
// copy the corresponding engine.
// A plugin framework built with bitcode must link against the bitcode version
// of Flutter.framework (Release).
_project.ios.copyEngineArtifactToProject(mode);
final String bitcodeGenerationMode = mode == BuildMode.release ?
'bitcode' : 'marker'; // In release, force bitcode embedding without archiving.
List<String> pluginsBuildCommand = <String>[
'xcrun',
'xcodebuild',
@@ -455,6 +461,7 @@ end
'-configuration',
xcodeBuildConfiguration,
'SYMROOT=${iPhoneBuildOutput.path}',
'BITCODE_GENERATION_MODE=$bitcodeGenerationMode',
'ONLY_ACTIVE_ARCH=NO' // No device targeted, so build all valid architectures.
];
@@ -592,7 +599,7 @@ end
final Status status = globals.logger.startProgress(
' ├─Creating $frameworkBinaryName.xcframework...',
timeout: timeoutConfiguration.fastOperation,
timeout: timeoutConfiguration.slowOperation,
);
try {
if (mode == BuildMode.debug) {

View File

@@ -490,10 +490,6 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject {
return;
}
final Directory engineDest = ephemeralDirectory
.childDirectory('Flutter')
.childDirectory('engine');
_deleteIfExistsSync(ephemeralDirectory);
_overwriteFromTemplate(
globals.fs.path.join('module', 'ios', 'library'),
@@ -511,23 +507,32 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject {
ephemeralDirectory,
);
}
// Copy podspec and framework from engine cache. The actual build mode
// doesn't actually matter as it will be overwritten by xcode_backend.sh.
// However, cocoapods will run before that script and requires something
// to be in this location.
final Directory framework = globals.fs.directory(
globals.artifacts.getArtifactPath(Artifact.flutterFramework,
copyEngineArtifactToProject(BuildMode.debug);
}
}
void copyEngineArtifactToProject(BuildMode mode) {
// Copy podspec and framework from engine cache. The actual build mode
// doesn't actually matter as it will be overwritten by xcode_backend.sh.
// However, cocoapods will run before that script and requires something
// to be in this location.
final Directory framework = globals.fs.directory(
globals.artifacts.getArtifactPath(
Artifact.flutterFramework,
platform: TargetPlatform.ios,
mode: BuildMode.debug,
));
if (framework.existsSync()) {
final File podspec = framework.parent.childFile('Flutter.podspec');
fsUtils.copyDirectorySync(
framework,
engineDest.childDirectory('Flutter.framework'),
);
podspec.copySync(engineDest.childFile('Flutter.podspec').path);
}
mode: mode,
)
);
if (framework.existsSync()) {
final Directory engineDest = ephemeralDirectory
.childDirectory('Flutter')
.childDirectory('engine');
final File podspec = framework.parent.childFile('Flutter.podspec');
fsUtils.copyDirectorySync(
framework,
engineDest.childDirectory('Flutter.framework'),
);
podspec.copySync(engineDest.childFile('Flutter.podspec').path);
}
}