Reland "Relax arguments around local engine, build hello_world with bitcode" (#39434)

This commit is contained in:
Dan Field
2019-08-28 15:19:04 -07:00
committed by GitHub
parent f26f8e8348
commit cb965495d7
9 changed files with 41 additions and 125 deletions

View File

@@ -179,13 +179,14 @@ class AOTSnapshotter {
// The DWARF section confuses Xcode tooling, so this strips it. Ideally,
// gen_snapshot would provide an argument to do this automatically.
if (platform == TargetPlatform.ios && bitcode) {
final IOSink sink = fs.file('$assembly.bitcode').openWrite();
final IOSink sink = fs.file('$assembly.stripped.S').openWrite();
for (String line in fs.file(assembly).readAsLinesSync()) {
if (line.startsWith('.section __DWARF')) {
break;
}
sink.writeln(line);
}
await sink.flush();
await sink.close();
}
@@ -199,7 +200,8 @@ class AOTSnapshotter {
if (platform == TargetPlatform.ios || platform == TargetPlatform.darwin_x64) {
final RunResult result = await _buildFramework(
appleArch: darwinArch,
assemblyPath: bitcode ? '$assembly.bitcode' : assembly,
isIOS: platform == TargetPlatform.ios,
assemblyPath: bitcode ? '$assembly.stripped.S' : assembly,
outputPath: outputDir.path,
bitcode: bitcode,
);
@@ -213,26 +215,29 @@ class AOTSnapshotter {
/// source at [assemblyPath].
Future<RunResult> _buildFramework({
@required DarwinArch appleArch,
@required bool isIOS,
@required String assemblyPath,
@required String outputPath,
@required bool bitcode,
}) async {
final String targetArch = getNameForDarwinArch(appleArch);
printStatus('Building App.framework for $targetArch...');
final List<String> commonBuildOptions = <String>[
'-arch', targetArch,
if (appleArch == DarwinArch.arm64 || appleArch == DarwinArch.armv7)
if (isIOS)
'-miphoneos-version-min=8.0',
];
const String embedBitcodeArg = '-fembed-bitcode';
final String assemblyO = fs.path.join(outputPath, 'snapshot_assembly.o');
final RunResult compileResult = await xcode.cc(<String>[
...commonBuildOptions,
'-arch', targetArch,
if (bitcode) embedBitcodeArg,
'-c',
assemblyPath,
'-o',
assemblyO,
if (bitcode) '-fembed-bitcode',
]);
if (compileResult.exitCode != 0) {
printError('Failed to compile AOT snapshot. Compiler terminated with exit code ${compileResult.exitCode}');
@@ -248,26 +253,16 @@ class AOTSnapshotter {
'-Xlinker', '-rpath', '-Xlinker', '@executable_path/Frameworks',
'-Xlinker', '-rpath', '-Xlinker', '@loader_path/Frameworks',
'-install_name', '@rpath/App.framework/App',
if (bitcode) '-fembed-bitcode',
if (bitcode) embedBitcodeArg,
if (bitcode && isIOS) ...<String>[embedBitcodeArg, '-isysroot', await xcode.iPhoneSdkLocation()],
'-o', appLib,
assemblyO,
];
final RunResult linkResult = await xcode.clang(linkArgs);
if (linkResult.exitCode != 0) {
printError('Failed to link AOT snapshot. Linker terminated with exit code ${compileResult.exitCode}');
return linkResult;
}
// See https://github.com/flutter/flutter/issues/22560
// These have to be placed in a .noindex folder to prevent Xcode from
// using Spotlight to find them and potentially attach the wrong ones.
final RunResult dsymResult = await xcode.dsymutil(<String>[
appLib,
'-o', fs.path.join(outputPath, 'App.framework.dSYM.noindex'),
]);
if (dsymResult.exitCode != 0) {
printError('Failed to extract dSYM out of dynamic lib');
}
return dsymResult;
return linkResult;
}
/// Compiles a Dart file to kernel.

View File

@@ -83,7 +83,7 @@ class BuildAotCommand extends BuildSubCommand with TargetPlatformBasedDevelopmen
if (platform != TargetPlatform.ios) {
throwToolExit('Bitcode is only supported on iOS (TargetPlatform is $targetPlatform).');
}
await validateBitcode();
await validateBitcode(buildMode, platform);
}
Status status;
@@ -150,14 +150,6 @@ class BuildAotCommand extends BuildSubCommand with TargetPlatformBasedDevelopmen
'-create',
'-output', fs.path.join(outputPath, 'App.framework', 'App'),
]);
final Iterable<String> dSYMs = iosBuilds.values.map<String>((String outputDir) => fs.path.join(outputDir, 'App.framework.dSYM.noindex'));
fs.directory(fs.path.join(outputPath, 'App.framework.dSYM.noindex', 'Contents', 'Resources', 'DWARF'))..createSync(recursive: true);
await runCheckedAsync(<String>[
'lipo',
'-create',
'-output', fs.path.join(outputPath, 'App.framework.dSYM.noindex', 'Contents', 'Resources', 'DWARF', 'App'),
...dSYMs.map((String path) => fs.path.join(path, 'Contents', 'Resources', 'DWARF', 'App'))
]);
} else {
status?.cancel();
exitCodes.forEach((DarwinArch iosArch, Future<int> exitCodeFuture) async {
@@ -202,24 +194,18 @@ class BuildAotCommand extends BuildSubCommand with TargetPlatformBasedDevelopmen
}
}
Future<void> validateBitcode() async {
Future<void> validateBitcode(BuildMode buildMode, TargetPlatform targetPlatform) async {
final Artifacts artifacts = Artifacts.instance;
if (artifacts is! LocalEngineArtifacts) {
throwToolExit('Bitcode is only supported with a local engine built with --bitcode.');
}
final String flutterFrameworkPath = artifacts.getArtifactPath(Artifact.flutterFramework);
final String flutterFrameworkPath = artifacts.getArtifactPath(
Artifact.flutterFramework,
mode: buildMode,
platform: targetPlatform,
);
if (!fs.isDirectorySync(flutterFrameworkPath)) {
throwToolExit('Flutter.framework not found at $flutterFrameworkPath');
}
final Xcode xcode = context.get<Xcode>();
// Check for bitcode in Flutter binary.
final RunResult otoolResult = await xcode.otool(<String>[
'-l', fs.path.join(flutterFrameworkPath, 'Flutter'),
]);
if (!otoolResult.stdout.contains('__LLVM')) {
throwToolExit('The Flutter.framework at $flutterFrameworkPath does not contain bitcode.');
}
final RunResult clangResult = await xcode.clang(<String>['--version']);
final String clangVersion = clangResult.stdout.split('\n').first;
final String engineClangVersion = PlistParser.instance.getValueFromFile(

View File

@@ -4,6 +4,7 @@
import 'dart:async';
import '../base/common.dart';
import '../base/context.dart';
import '../base/file_system.dart';
import '../base/io.dart';
@@ -100,16 +101,14 @@ class Xcode {
return runCheckedAsync(<String>['xcrun', 'clang', ...args]);
}
Future<RunResult> dsymutil(List<String> args) {
return runCheckedAsync(<String>['xcrun', 'dsymutil', ...args]);
}
Future<RunResult> strip(List<String> args) {
return runCheckedAsync(<String>['xcrun', 'strip', ...args]);
}
Future<RunResult> otool(List<String> args) {
return runCheckedAsync(<String>['xcrun', 'otool', ...args]);
Future<String> iPhoneSdkLocation() async {
final RunResult runResult = await runCheckedAsync(
<String>['xcrun', '--sdk', 'iphoneos', '--show-sdk-path'],
);
if (runResult.exitCode != 0) {
throwToolExit('Could not find iPhone SDK location: ${runResult.stderr}');
}
return runResult.stdout.trim();
}
String getSimulatorPath() {