Unverified Commit 1df165ea authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Rename iOS arch for macOS release mode (macOS release mode 2 of 3) (#38645)

parent 9823b3db
...@@ -46,7 +46,7 @@ class GenSnapshot { ...@@ -46,7 +46,7 @@ class GenSnapshot {
Future<int> run({ Future<int> run({
@required SnapshotType snapshotType, @required SnapshotType snapshotType,
IOSArch iosArch, DarwinArch darwinArch,
Iterable<String> additionalArgs = const <String>[], Iterable<String> additionalArgs = const <String>[],
}) { }) {
final List<String> args = <String>[ final List<String> args = <String>[
...@@ -59,7 +59,7 @@ class GenSnapshot { ...@@ -59,7 +59,7 @@ class GenSnapshot {
// iOS has a separate gen_snapshot for armv7 and arm64 in the same, // iOS has a separate gen_snapshot for armv7 and arm64 in the same,
// directory. So we need to select the right one. // directory. So we need to select the right one.
if (snapshotType.platform == TargetPlatform.ios) { if (snapshotType.platform == TargetPlatform.ios) {
snapshotterPath += '_' + getNameForIOSArch(iosArch); snapshotterPath += '_' + getNameForDarwinArch(darwinArch);
} }
StringConverter outputFilter; StringConverter outputFilter;
...@@ -89,7 +89,7 @@ class AOTSnapshotter { ...@@ -89,7 +89,7 @@ class AOTSnapshotter {
@required String mainPath, @required String mainPath,
@required String packagesPath, @required String packagesPath,
@required String outputPath, @required String outputPath,
IOSArch iosArch, DarwinArch darwinArch,
List<String> extraGenSnapshotOptions = const <String>[], List<String> extraGenSnapshotOptions = const <String>[],
@required bool bitcode, @required bool bitcode,
}) async { }) async {
...@@ -103,7 +103,7 @@ class AOTSnapshotter { ...@@ -103,7 +103,7 @@ class AOTSnapshotter {
return 1; return 1;
} }
// TODO(cbracken): replace IOSArch with TargetPlatform.ios_{armv7,arm64}. // TODO(cbracken): replace IOSArch with TargetPlatform.ios_{armv7,arm64}.
assert(platform != TargetPlatform.ios || iosArch != null); assert(platform != TargetPlatform.ios || darwinArch != null);
final PackageMap packageMap = PackageMap(packagesPath); final PackageMap packageMap = PackageMap(packagesPath);
final String packageMapError = packageMap.checkValid(); final String packageMapError = packageMap.checkValid();
...@@ -130,7 +130,7 @@ class AOTSnapshotter { ...@@ -130,7 +130,7 @@ class AOTSnapshotter {
} }
final String assembly = fs.path.join(outputDir.path, 'snapshot_assembly.S'); final String assembly = fs.path.join(outputDir.path, 'snapshot_assembly.S');
if (platform == TargetPlatform.ios) { if (platform == TargetPlatform.ios || platform == TargetPlatform.darwin_x64) {
// Assembly AOT snapshot. // Assembly AOT snapshot.
outputPaths.add(assembly); outputPaths.add(assembly);
genSnapshotArgs.add('--snapshot_kind=app-aot-assembly'); genSnapshotArgs.add('--snapshot_kind=app-aot-assembly');
...@@ -143,7 +143,7 @@ class AOTSnapshotter { ...@@ -143,7 +143,7 @@ class AOTSnapshotter {
genSnapshotArgs.add('--strip'); genSnapshotArgs.add('--strip');
} }
if (platform == TargetPlatform.android_arm || iosArch == IOSArch.armv7) { if (platform == TargetPlatform.android_arm || darwinArch == DarwinArch.armv7) {
// Use softfp for Android armv7 devices. // Use softfp for Android armv7 devices.
// This is the default for armv7 iOS builds, but harmless to set. // This is the default for armv7 iOS builds, but harmless to set.
// TODO(cbracken): eliminate this when we fix https://github.com/flutter/flutter/issues/17489 // TODO(cbracken): eliminate this when we fix https://github.com/flutter/flutter/issues/17489
...@@ -168,7 +168,7 @@ class AOTSnapshotter { ...@@ -168,7 +168,7 @@ class AOTSnapshotter {
() => genSnapshot.run( () => genSnapshot.run(
snapshotType: snapshotType, snapshotType: snapshotType,
additionalArgs: genSnapshotArgs, additionalArgs: genSnapshotArgs,
iosArch: iosArch, darwinArch: darwinArch,
)); ));
if (genSnapshotExitCode != 0) { if (genSnapshotExitCode != 0) {
printError('Dart snapshot generator failed with exit code $genSnapshotExitCode'); printError('Dart snapshot generator failed with exit code $genSnapshotExitCode');
...@@ -197,9 +197,9 @@ class AOTSnapshotter { ...@@ -197,9 +197,9 @@ class AOTSnapshotter {
// On iOS, we use Xcode to compile the snapshot into a dynamic library that the // On iOS, we use Xcode to compile the snapshot into a dynamic library that the
// end-developer can link into their app. // end-developer can link into their app.
if (platform == TargetPlatform.ios) { if (platform == TargetPlatform.ios || platform == TargetPlatform.darwin_x64) {
final RunResult result = await _buildIosFramework( final RunResult result = await _buildFramework(
iosArch: iosArch, appleArch: darwinArch,
assemblyPath: bitcode ? '$assembly.bitcode' : assembly, assemblyPath: bitcode ? '$assembly.bitcode' : assembly,
outputPath: outputDir.path, outputPath: outputDir.path,
bitcode: bitcode, bitcode: bitcode,
...@@ -210,17 +210,21 @@ class AOTSnapshotter { ...@@ -210,17 +210,21 @@ class AOTSnapshotter {
return 0; return 0;
} }
/// Builds an iOS framework at [outputPath]/App.framework from the assembly /// Builds an iOS or macOS framework at [outputPath]/App.framework from the assembly
/// source at [assemblyPath]. /// source at [assemblyPath].
Future<RunResult> _buildIosFramework({ Future<RunResult> _buildFramework({
@required IOSArch iosArch, @required DarwinArch appleArch,
@required String assemblyPath, @required String assemblyPath,
@required String outputPath, @required String outputPath,
@required bool bitcode, @required bool bitcode,
}) async { }) async {
final String targetArch = iosArch == IOSArch.armv7 ? 'armv7' : 'arm64'; final String targetArch = getNameForDarwinArch(appleArch);
printStatus('Building App.framework for $targetArch...'); printStatus('Building App.framework for $targetArch...');
final List<String> commonBuildOptions = <String>['-arch', targetArch, '-miphoneos-version-min=8.0']; final List<String> commonBuildOptions = <String>[
'-arch', targetArch,
if (appleArch == DarwinArch.arm64 || appleArch == DarwinArch.armv7)
'-miphoneos-version-min=8.0',
];
final String assemblyO = fs.path.join(outputPath, 'snapshot_assembly.o'); final String assemblyO = fs.path.join(outputPath, 'snapshot_assembly.o');
final RunResult compileResult = await xcode.cc(<String>[ final RunResult compileResult = await xcode.cc(<String>[
...@@ -322,6 +326,7 @@ class AOTSnapshotter { ...@@ -322,6 +326,7 @@ class AOTSnapshotter {
TargetPlatform.android_arm, TargetPlatform.android_arm,
TargetPlatform.android_arm64, TargetPlatform.android_arm64,
TargetPlatform.ios, TargetPlatform.ios,
TargetPlatform.darwin_x64,
].contains(platform); ].contains(platform);
} }
......
...@@ -265,12 +265,13 @@ enum TargetPlatform { ...@@ -265,12 +265,13 @@ enum TargetPlatform {
web_javascript, web_javascript,
} }
/// iOS target device architecture. /// iOS and macOS target device architecture.
// //
// TODO(cbracken): split TargetPlatform.ios into ios_armv7, ios_arm64. // TODO(cbracken): split TargetPlatform.ios into ios_armv7, ios_arm64.
enum IOSArch { enum DarwinArch {
armv7, armv7,
arm64, arm64,
x86_64,
} }
enum AndroidArch { enum AndroidArch {
...@@ -281,27 +282,29 @@ enum AndroidArch { ...@@ -281,27 +282,29 @@ enum AndroidArch {
} }
/// The default set of iOS device architectures to build for. /// The default set of iOS device architectures to build for.
const List<IOSArch> defaultIOSArchs = <IOSArch>[ const List<DarwinArch> defaultIOSArchs = <DarwinArch>[
IOSArch.arm64, DarwinArch.arm64,
]; ];
String getNameForIOSArch(IOSArch arch) { String getNameForDarwinArch(DarwinArch arch) {
switch (arch) { switch (arch) {
case IOSArch.armv7: case DarwinArch.armv7:
return 'armv7'; return 'armv7';
case IOSArch.arm64: case DarwinArch.arm64:
return 'arm64'; return 'arm64';
case DarwinArch.x86_64:
return 'x86_64';
} }
assert(false); assert(false);
return null; return null;
} }
IOSArch getIOSArchForName(String arch) { DarwinArch getIOSArchForName(String arch) {
switch (arch) { switch (arch) {
case 'armv7': case 'armv7':
return IOSArch.armv7; return DarwinArch.armv7;
case 'arm64': case 'arm64':
return IOSArch.arm64; return DarwinArch.arm64;
} }
assert(false); assert(false);
return null; return null;
......
...@@ -32,8 +32,8 @@ abstract class AotAssemblyBase extends Target { ...@@ -32,8 +32,8 @@ abstract class AotAssemblyBase extends Target {
final bool bitcode = environment.defines[kBitcodeFlag] == 'true'; final bool bitcode = environment.defines[kBitcodeFlag] == 'true';
final BuildMode buildMode = getBuildModeForName(environment.defines[kBuildMode]); final BuildMode buildMode = getBuildModeForName(environment.defines[kBuildMode]);
final TargetPlatform targetPlatform = getTargetPlatformForName(environment.defines[kTargetPlatform]); final TargetPlatform targetPlatform = getTargetPlatformForName(environment.defines[kTargetPlatform]);
final List<IOSArch> iosArchs = environment.defines[kIosArchs]?.split(',')?.map(getIOSArchForName)?.toList() final List<DarwinArch> iosArchs = environment.defines[kIosArchs]?.split(',')?.map(getIOSArchForName)?.toList()
?? <IOSArch>[IOSArch.arm64]; ?? <DarwinArch>[DarwinArch.arm64];
if (targetPlatform != TargetPlatform.ios) { if (targetPlatform != TargetPlatform.ios) {
throw Exception('aot_assembly is only supported for iOS applications'); throw Exception('aot_assembly is only supported for iOS applications');
} }
...@@ -46,7 +46,7 @@ abstract class AotAssemblyBase extends Target { ...@@ -46,7 +46,7 @@ abstract class AotAssemblyBase extends Target {
mainPath: environment.buildDir.childFile('app.dill').path, mainPath: environment.buildDir.childFile('app.dill').path,
packagesPath: environment.projectDir.childFile('.packages').path, packagesPath: environment.projectDir.childFile('.packages').path,
outputPath: outputPath, outputPath: outputPath,
iosArch: iosArchs.single, darwinArch: iosArchs.single,
bitcode: bitcode, bitcode: bitcode,
); );
if (snapshotExitCode != 0) { if (snapshotExitCode != 0) {
...@@ -56,14 +56,14 @@ abstract class AotAssemblyBase extends Target { ...@@ -56,14 +56,14 @@ abstract class AotAssemblyBase extends Target {
// If we're building multiple iOS archs the binaries need to be lipo'd // If we're building multiple iOS archs the binaries need to be lipo'd
// together. // together.
final List<Future<int>> pending = <Future<int>>[]; final List<Future<int>> pending = <Future<int>>[];
for (IOSArch iosArch in iosArchs) { for (DarwinArch iosArch in iosArchs) {
pending.add(snapshotter.build( pending.add(snapshotter.build(
platform: targetPlatform, platform: targetPlatform,
buildMode: buildMode, buildMode: buildMode,
mainPath: environment.buildDir.childFile('app.dill').path, mainPath: environment.buildDir.childFile('app.dill').path,
packagesPath: environment.projectDir.childFile('.packages').path, packagesPath: environment.projectDir.childFile('.packages').path,
outputPath: fs.path.join(outputPath, getNameForIOSArch(iosArch)), outputPath: fs.path.join(outputPath, getNameForDarwinArch(iosArch)),
iosArch: iosArch, darwinArch: iosArch,
bitcode: bitcode, bitcode: bitcode,
)); ));
} }
...@@ -73,8 +73,8 @@ abstract class AotAssemblyBase extends Target { ...@@ -73,8 +73,8 @@ abstract class AotAssemblyBase extends Target {
} }
final ProcessResult result = await processManager.run(<String>[ final ProcessResult result = await processManager.run(<String>[
'lipo', 'lipo',
...iosArchs.map((IOSArch iosArch) => ...iosArchs.map((DarwinArch iosArch) =>
fs.path.join(outputPath, getNameForIOSArch(iosArch), 'App.framework', 'App')), fs.path.join(outputPath, getNameForDarwinArch(iosArch), 'App.framework', 'App')),
'-create', '-create',
'-output', '-output',
fs.path.join(outputPath, 'App.framework', 'App'), fs.path.join(outputPath, 'App.framework', 'App'),
......
...@@ -40,8 +40,8 @@ class BuildAotCommand extends BuildSubCommand with TargetPlatformBasedDevelopmen ...@@ -40,8 +40,8 @@ class BuildAotCommand extends BuildSubCommand with TargetPlatformBasedDevelopmen
) )
..addMultiOption('ios-arch', ..addMultiOption('ios-arch',
splitCommas: true, splitCommas: true,
defaultsTo: defaultIOSArchs.map<String>(getNameForIOSArch), defaultsTo: defaultIOSArchs.map<String>(getNameForDarwinArch),
allowed: IOSArch.values.map<String>(getNameForIOSArch), allowed: DarwinArch.values.map<String>(getNameForDarwinArch),
help: 'iOS architectures to build.', help: 'iOS architectures to build.',
) )
..addMultiOption(FlutterOptions.kExtraFrontEndOptions, ..addMultiOption(FlutterOptions.kExtraFrontEndOptions,
...@@ -118,17 +118,17 @@ class BuildAotCommand extends BuildSubCommand with TargetPlatformBasedDevelopmen ...@@ -118,17 +118,17 @@ class BuildAotCommand extends BuildSubCommand with TargetPlatformBasedDevelopmen
// Build AOT snapshot. // Build AOT snapshot.
if (platform == TargetPlatform.ios) { if (platform == TargetPlatform.ios) {
// Determine which iOS architectures to build for. // Determine which iOS architectures to build for.
final Iterable<IOSArch> buildArchs = argResults['ios-arch'].map<IOSArch>(getIOSArchForName); final Iterable<DarwinArch> buildArchs = argResults['ios-arch'].map<DarwinArch>(getIOSArchForName);
final Map<IOSArch, String> iosBuilds = <IOSArch, String>{}; final Map<DarwinArch, String> iosBuilds = <DarwinArch, String>{};
for (IOSArch arch in buildArchs) for (DarwinArch arch in buildArchs)
iosBuilds[arch] = fs.path.join(outputPath, getNameForIOSArch(arch)); iosBuilds[arch] = fs.path.join(outputPath, getNameForDarwinArch(arch));
// Generate AOT snapshot and compile to arch-specific App.framework. // Generate AOT snapshot and compile to arch-specific App.framework.
final Map<IOSArch, Future<int>> exitCodes = <IOSArch, Future<int>>{}; final Map<DarwinArch, Future<int>> exitCodes = <DarwinArch, Future<int>>{};
iosBuilds.forEach((IOSArch iosArch, String outputPath) { iosBuilds.forEach((DarwinArch iosArch, String outputPath) {
exitCodes[iosArch] = snapshotter.build( exitCodes[iosArch] = snapshotter.build(
platform: platform, platform: platform,
iosArch: iosArch, darwinArch: iosArch,
buildMode: buildMode, buildMode: buildMode,
mainPath: mainPath, mainPath: mainPath,
packagesPath: PackageMap.globalPackagesPath, packagesPath: PackageMap.globalPackagesPath,
...@@ -160,7 +160,7 @@ class BuildAotCommand extends BuildSubCommand with TargetPlatformBasedDevelopmen ...@@ -160,7 +160,7 @@ class BuildAotCommand extends BuildSubCommand with TargetPlatformBasedDevelopmen
]); ]);
} else { } else {
status?.cancel(); status?.cancel();
exitCodes.forEach((IOSArch iosArch, Future<int> exitCodeFuture) async { exitCodes.forEach((DarwinArch iosArch, Future<int> exitCodeFuture) async {
final int buildExitCode = await exitCodeFuture; final int buildExitCode = await exitCodeFuture;
printError('Snapshotting ($iosArch) exited with non-zero exit code: $buildExitCode'); printError('Snapshotting ($iosArch) exited with non-zero exit code: $buildExitCode');
}); });
......
...@@ -265,7 +265,7 @@ class IOSDevice extends Device { ...@@ -265,7 +265,7 @@ class IOSDevice extends Device {
printTrace('Building ${package.name} for $id'); printTrace('Building ${package.name} for $id');
final String cpuArchitecture = await iMobileDevice.getInfoForDevice(id, 'CPUArchitecture'); final String cpuArchitecture = await iMobileDevice.getInfoForDevice(id, 'CPUArchitecture');
final IOSArch iosArch = getIOSArchForName(cpuArchitecture); final DarwinArch iosArch = getIOSArchForName(cpuArchitecture);
// Step 1: Build the precompiled/DBC application if necessary. // Step 1: Build the precompiled/DBC application if necessary.
final XcodeBuildResult buildResult = await buildXcodeProject( final XcodeBuildResult buildResult = await buildXcodeProject(
......
...@@ -201,7 +201,7 @@ Future<XcodeBuildResult> buildXcodeProject({ ...@@ -201,7 +201,7 @@ Future<XcodeBuildResult> buildXcodeProject({
BuildInfo buildInfo, BuildInfo buildInfo,
String targetOverride, String targetOverride,
bool buildForDevice, bool buildForDevice,
IOSArch activeArch, DarwinArch activeArch,
bool codesign = true, bool codesign = true,
bool usesTerminalUi = true, bool usesTerminalUi = true,
}) async { }) async {
...@@ -317,7 +317,7 @@ Future<XcodeBuildResult> buildXcodeProject({ ...@@ -317,7 +317,7 @@ Future<XcodeBuildResult> buildXcodeProject({
} }
if (activeArch != null) { if (activeArch != null) {
final String activeArchName = getNameForIOSArch(activeArch); final String activeArchName = getNameForDarwinArch(activeArch);
if (activeArchName != null) { if (activeArchName != null) {
buildCommands.add('ONLY_ACTIVE_ARCH=YES'); buildCommands.add('ONLY_ACTIVE_ARCH=YES');
buildCommands.add('ARCHS=$activeArchName'); buildCommands.add('ARCHS=$activeArchName');
......
...@@ -50,7 +50,7 @@ class _FakeGenSnapshot implements GenSnapshot { ...@@ -50,7 +50,7 @@ class _FakeGenSnapshot implements GenSnapshot {
Future<int> run({ Future<int> run({
SnapshotType snapshotType, SnapshotType snapshotType,
String depfilePath, String depfilePath,
IOSArch iosArch, DarwinArch darwinArch,
Iterable<String> additionalArgs = const <String>[], Iterable<String> additionalArgs = const <String>[],
}) async { }) async {
_callCount += 1; _callCount += 1;
...@@ -191,7 +191,7 @@ void main() { ...@@ -191,7 +191,7 @@ void main() {
mainPath: 'main.dill', mainPath: 'main.dill',
packagesPath: '.packages', packagesPath: '.packages',
outputPath: outputPath, outputPath: outputPath,
iosArch: IOSArch.armv7, darwinArch: DarwinArch.armv7,
bitcode: true, bitcode: true,
); );
...@@ -245,7 +245,7 @@ void main() { ...@@ -245,7 +245,7 @@ void main() {
mainPath: 'main.dill', mainPath: 'main.dill',
packagesPath: '.packages', packagesPath: '.packages',
outputPath: outputPath, outputPath: outputPath,
iosArch: IOSArch.armv7, darwinArch: DarwinArch.armv7,
bitcode: false, bitcode: false,
); );
...@@ -292,7 +292,7 @@ void main() { ...@@ -292,7 +292,7 @@ void main() {
mainPath: 'main.dill', mainPath: 'main.dill',
packagesPath: '.packages', packagesPath: '.packages',
outputPath: outputPath, outputPath: outputPath,
iosArch: IOSArch.arm64, darwinArch: DarwinArch.arm64,
bitcode: false, bitcode: false,
); );
...@@ -328,7 +328,7 @@ void main() { ...@@ -328,7 +328,7 @@ void main() {
mainPath: 'main.dill', mainPath: 'main.dill',
packagesPath: '.packages', packagesPath: '.packages',
outputPath: outputPath, outputPath: outputPath,
iosArch: IOSArch.armv7, darwinArch: DarwinArch.armv7,
bitcode: false, bitcode: false,
); );
...@@ -366,7 +366,7 @@ void main() { ...@@ -366,7 +366,7 @@ void main() {
mainPath: 'main.dill', mainPath: 'main.dill',
packagesPath: '.packages', packagesPath: '.packages',
outputPath: outputPath, outputPath: outputPath,
iosArch: IOSArch.arm64, darwinArch: DarwinArch.arm64,
bitcode: false, bitcode: false,
); );
......
...@@ -323,10 +323,10 @@ class MockXcode extends Mock implements Xcode {} ...@@ -323,10 +323,10 @@ class MockXcode extends Mock implements Xcode {}
class FakeGenSnapshot implements GenSnapshot { class FakeGenSnapshot implements GenSnapshot {
List<String> lastCallAdditionalArgs; List<String> lastCallAdditionalArgs;
@override @override
Future<int> run({SnapshotType snapshotType, IOSArch iosArch, Iterable<String> additionalArgs = const <String>[]}) async { Future<int> run({SnapshotType snapshotType, DarwinArch darwinArch, Iterable<String> additionalArgs = const <String>[]}) async {
lastCallAdditionalArgs = additionalArgs.toList(); lastCallAdditionalArgs = additionalArgs.toList();
final Directory out = fs.file(lastCallAdditionalArgs.last).parent; final Directory out = fs.file(lastCallAdditionalArgs.last).parent;
if (iosArch == null) { if (darwinArch == null) {
out.childFile('app.so').createSync(); out.childFile('app.so').createSync();
out.childFile('gen_snapshot.d').createSync(); out.childFile('gen_snapshot.d').createSync();
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment