Rename iOS arch for macOS release mode (macOS release mode 2 of 3) (#38645)
diff --git a/packages/flutter_tools/lib/src/base/build.dart b/packages/flutter_tools/lib/src/base/build.dart
index 2543383..0cb8595 100644
--- a/packages/flutter_tools/lib/src/base/build.dart
+++ b/packages/flutter_tools/lib/src/base/build.dart
@@ -46,7 +46,7 @@
Future<int> run({
@required SnapshotType snapshotType,
- IOSArch iosArch,
+ DarwinArch darwinArch,
Iterable<String> additionalArgs = const <String>[],
}) {
final List<String> args = <String>[
@@ -59,7 +59,7 @@
// iOS has a separate gen_snapshot for armv7 and arm64 in the same,
// directory. So we need to select the right one.
if (snapshotType.platform == TargetPlatform.ios) {
- snapshotterPath += '_' + getNameForIOSArch(iosArch);
+ snapshotterPath += '_' + getNameForDarwinArch(darwinArch);
}
StringConverter outputFilter;
@@ -89,7 +89,7 @@
@required String mainPath,
@required String packagesPath,
@required String outputPath,
- IOSArch iosArch,
+ DarwinArch darwinArch,
List<String> extraGenSnapshotOptions = const <String>[],
@required bool bitcode,
}) async {
@@ -103,7 +103,7 @@
return 1;
}
// 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 String packageMapError = packageMap.checkValid();
@@ -130,7 +130,7 @@
}
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.
outputPaths.add(assembly);
genSnapshotArgs.add('--snapshot_kind=app-aot-assembly');
@@ -143,7 +143,7 @@
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.
// 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
@@ -168,7 +168,7 @@
() => genSnapshot.run(
snapshotType: snapshotType,
additionalArgs: genSnapshotArgs,
- iosArch: iosArch,
+ darwinArch: darwinArch,
));
if (genSnapshotExitCode != 0) {
printError('Dart snapshot generator failed with exit code $genSnapshotExitCode');
@@ -197,9 +197,9 @@
// On iOS, we use Xcode to compile the snapshot into a dynamic library that the
// end-developer can link into their app.
- if (platform == TargetPlatform.ios) {
- final RunResult result = await _buildIosFramework(
- iosArch: iosArch,
+ if (platform == TargetPlatform.ios || platform == TargetPlatform.darwin_x64) {
+ final RunResult result = await _buildFramework(
+ appleArch: darwinArch,
assemblyPath: bitcode ? '$assembly.bitcode' : assembly,
outputPath: outputDir.path,
bitcode: bitcode,
@@ -210,17 +210,21 @@
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].
- Future<RunResult> _buildIosFramework({
- @required IOSArch iosArch,
+ Future<RunResult> _buildFramework({
+ @required DarwinArch appleArch,
@required String assemblyPath,
@required String outputPath,
@required bool bitcode,
}) async {
- final String targetArch = iosArch == IOSArch.armv7 ? 'armv7' : 'arm64';
+ final String targetArch = getNameForDarwinArch(appleArch);
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 RunResult compileResult = await xcode.cc(<String>[
@@ -322,6 +326,7 @@
TargetPlatform.android_arm,
TargetPlatform.android_arm64,
TargetPlatform.ios,
+ TargetPlatform.darwin_x64,
].contains(platform);
}
diff --git a/packages/flutter_tools/lib/src/build_info.dart b/packages/flutter_tools/lib/src/build_info.dart
index d53c654..5331465 100644
--- a/packages/flutter_tools/lib/src/build_info.dart
+++ b/packages/flutter_tools/lib/src/build_info.dart
@@ -265,12 +265,13 @@
web_javascript,
}
-/// iOS target device architecture.
+/// iOS and macOS target device architecture.
//
// TODO(cbracken): split TargetPlatform.ios into ios_armv7, ios_arm64.
-enum IOSArch {
+enum DarwinArch {
armv7,
arm64,
+ x86_64,
}
enum AndroidArch {
@@ -281,27 +282,29 @@
}
/// The default set of iOS device architectures to build for.
-const List<IOSArch> defaultIOSArchs = <IOSArch>[
- IOSArch.arm64,
+const List<DarwinArch> defaultIOSArchs = <DarwinArch>[
+ DarwinArch.arm64,
];
-String getNameForIOSArch(IOSArch arch) {
+String getNameForDarwinArch(DarwinArch arch) {
switch (arch) {
- case IOSArch.armv7:
+ case DarwinArch.armv7:
return 'armv7';
- case IOSArch.arm64:
+ case DarwinArch.arm64:
return 'arm64';
+ case DarwinArch.x86_64:
+ return 'x86_64';
}
assert(false);
return null;
}
-IOSArch getIOSArchForName(String arch) {
+DarwinArch getIOSArchForName(String arch) {
switch (arch) {
case 'armv7':
- return IOSArch.armv7;
+ return DarwinArch.armv7;
case 'arm64':
- return IOSArch.arm64;
+ return DarwinArch.arm64;
}
assert(false);
return null;
diff --git a/packages/flutter_tools/lib/src/build_system/targets/ios.dart b/packages/flutter_tools/lib/src/build_system/targets/ios.dart
index f0ca9a6..e822240 100644
--- a/packages/flutter_tools/lib/src/build_system/targets/ios.dart
+++ b/packages/flutter_tools/lib/src/build_system/targets/ios.dart
@@ -32,8 +32,8 @@
final bool bitcode = environment.defines[kBitcodeFlag] == 'true';
final BuildMode buildMode = getBuildModeForName(environment.defines[kBuildMode]);
final TargetPlatform targetPlatform = getTargetPlatformForName(environment.defines[kTargetPlatform]);
- final List<IOSArch> iosArchs = environment.defines[kIosArchs]?.split(',')?.map(getIOSArchForName)?.toList()
- ?? <IOSArch>[IOSArch.arm64];
+ final List<DarwinArch> iosArchs = environment.defines[kIosArchs]?.split(',')?.map(getIOSArchForName)?.toList()
+ ?? <DarwinArch>[DarwinArch.arm64];
if (targetPlatform != TargetPlatform.ios) {
throw Exception('aot_assembly is only supported for iOS applications');
}
@@ -46,7 +46,7 @@
mainPath: environment.buildDir.childFile('app.dill').path,
packagesPath: environment.projectDir.childFile('.packages').path,
outputPath: outputPath,
- iosArch: iosArchs.single,
+ darwinArch: iosArchs.single,
bitcode: bitcode,
);
if (snapshotExitCode != 0) {
@@ -56,14 +56,14 @@
// If we're building multiple iOS archs the binaries need to be lipo'd
// together.
final List<Future<int>> pending = <Future<int>>[];
- for (IOSArch iosArch in iosArchs) {
+ for (DarwinArch iosArch in iosArchs) {
pending.add(snapshotter.build(
platform: targetPlatform,
buildMode: buildMode,
mainPath: environment.buildDir.childFile('app.dill').path,
packagesPath: environment.projectDir.childFile('.packages').path,
- outputPath: fs.path.join(outputPath, getNameForIOSArch(iosArch)),
- iosArch: iosArch,
+ outputPath: fs.path.join(outputPath, getNameForDarwinArch(iosArch)),
+ darwinArch: iosArch,
bitcode: bitcode,
));
}
@@ -73,8 +73,8 @@
}
final ProcessResult result = await processManager.run(<String>[
'lipo',
- ...iosArchs.map((IOSArch iosArch) =>
- fs.path.join(outputPath, getNameForIOSArch(iosArch), 'App.framework', 'App')),
+ ...iosArchs.map((DarwinArch iosArch) =>
+ fs.path.join(outputPath, getNameForDarwinArch(iosArch), 'App.framework', 'App')),
'-create',
'-output',
fs.path.join(outputPath, 'App.framework', 'App'),
diff --git a/packages/flutter_tools/lib/src/commands/build_aot.dart b/packages/flutter_tools/lib/src/commands/build_aot.dart
index bb951f7..6718891 100644
--- a/packages/flutter_tools/lib/src/commands/build_aot.dart
+++ b/packages/flutter_tools/lib/src/commands/build_aot.dart
@@ -40,8 +40,8 @@
)
..addMultiOption('ios-arch',
splitCommas: true,
- defaultsTo: defaultIOSArchs.map<String>(getNameForIOSArch),
- allowed: IOSArch.values.map<String>(getNameForIOSArch),
+ defaultsTo: defaultIOSArchs.map<String>(getNameForDarwinArch),
+ allowed: DarwinArch.values.map<String>(getNameForDarwinArch),
help: 'iOS architectures to build.',
)
..addMultiOption(FlutterOptions.kExtraFrontEndOptions,
@@ -118,17 +118,17 @@
// Build AOT snapshot.
if (platform == TargetPlatform.ios) {
// Determine which iOS architectures to build for.
- final Iterable<IOSArch> buildArchs = argResults['ios-arch'].map<IOSArch>(getIOSArchForName);
- final Map<IOSArch, String> iosBuilds = <IOSArch, String>{};
- for (IOSArch arch in buildArchs)
- iosBuilds[arch] = fs.path.join(outputPath, getNameForIOSArch(arch));
+ final Iterable<DarwinArch> buildArchs = argResults['ios-arch'].map<DarwinArch>(getIOSArchForName);
+ final Map<DarwinArch, String> iosBuilds = <DarwinArch, String>{};
+ for (DarwinArch arch in buildArchs)
+ iosBuilds[arch] = fs.path.join(outputPath, getNameForDarwinArch(arch));
// Generate AOT snapshot and compile to arch-specific App.framework.
- final Map<IOSArch, Future<int>> exitCodes = <IOSArch, Future<int>>{};
- iosBuilds.forEach((IOSArch iosArch, String outputPath) {
+ final Map<DarwinArch, Future<int>> exitCodes = <DarwinArch, Future<int>>{};
+ iosBuilds.forEach((DarwinArch iosArch, String outputPath) {
exitCodes[iosArch] = snapshotter.build(
platform: platform,
- iosArch: iosArch,
+ darwinArch: iosArch,
buildMode: buildMode,
mainPath: mainPath,
packagesPath: PackageMap.globalPackagesPath,
@@ -160,7 +160,7 @@
]);
} else {
status?.cancel();
- exitCodes.forEach((IOSArch iosArch, Future<int> exitCodeFuture) async {
+ exitCodes.forEach((DarwinArch iosArch, Future<int> exitCodeFuture) async {
final int buildExitCode = await exitCodeFuture;
printError('Snapshotting ($iosArch) exited with non-zero exit code: $buildExitCode');
});
diff --git a/packages/flutter_tools/lib/src/ios/devices.dart b/packages/flutter_tools/lib/src/ios/devices.dart
index 0d7714a..f177c9f 100644
--- a/packages/flutter_tools/lib/src/ios/devices.dart
+++ b/packages/flutter_tools/lib/src/ios/devices.dart
@@ -265,7 +265,7 @@
printTrace('Building ${package.name} for $id');
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.
final XcodeBuildResult buildResult = await buildXcodeProject(
diff --git a/packages/flutter_tools/lib/src/ios/mac.dart b/packages/flutter_tools/lib/src/ios/mac.dart
index bbbf868..d2e975f 100644
--- a/packages/flutter_tools/lib/src/ios/mac.dart
+++ b/packages/flutter_tools/lib/src/ios/mac.dart
@@ -201,7 +201,7 @@
BuildInfo buildInfo,
String targetOverride,
bool buildForDevice,
- IOSArch activeArch,
+ DarwinArch activeArch,
bool codesign = true,
bool usesTerminalUi = true,
}) async {
@@ -317,7 +317,7 @@
}
if (activeArch != null) {
- final String activeArchName = getNameForIOSArch(activeArch);
+ final String activeArchName = getNameForDarwinArch(activeArch);
if (activeArchName != null) {
buildCommands.add('ONLY_ACTIVE_ARCH=YES');
buildCommands.add('ARCHS=$activeArchName');
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 3f387b2..d2fb7da 100644
--- a/packages/flutter_tools/test/general.shard/base/build_test.dart
+++ b/packages/flutter_tools/test/general.shard/base/build_test.dart
@@ -50,7 +50,7 @@
Future<int> run({
SnapshotType snapshotType,
String depfilePath,
- IOSArch iosArch,
+ DarwinArch darwinArch,
Iterable<String> additionalArgs = const <String>[],
}) async {
_callCount += 1;
@@ -191,7 +191,7 @@
mainPath: 'main.dill',
packagesPath: '.packages',
outputPath: outputPath,
- iosArch: IOSArch.armv7,
+ darwinArch: DarwinArch.armv7,
bitcode: true,
);
@@ -245,7 +245,7 @@
mainPath: 'main.dill',
packagesPath: '.packages',
outputPath: outputPath,
- iosArch: IOSArch.armv7,
+ darwinArch: DarwinArch.armv7,
bitcode: false,
);
@@ -292,7 +292,7 @@
mainPath: 'main.dill',
packagesPath: '.packages',
outputPath: outputPath,
- iosArch: IOSArch.arm64,
+ darwinArch: DarwinArch.arm64,
bitcode: false,
);
@@ -328,7 +328,7 @@
mainPath: 'main.dill',
packagesPath: '.packages',
outputPath: outputPath,
- iosArch: IOSArch.armv7,
+ darwinArch: DarwinArch.armv7,
bitcode: false,
);
@@ -366,7 +366,7 @@
mainPath: 'main.dill',
packagesPath: '.packages',
outputPath: outputPath,
- iosArch: IOSArch.arm64,
+ darwinArch: DarwinArch.arm64,
bitcode: false,
);
diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/dart_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/dart_test.dart
index 417a554..caa5352 100644
--- a/packages/flutter_tools/test/general.shard/build_system/targets/dart_test.dart
+++ b/packages/flutter_tools/test/general.shard/build_system/targets/dart_test.dart
@@ -323,10 +323,10 @@
class FakeGenSnapshot implements GenSnapshot {
List<String> lastCallAdditionalArgs;
@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();
final Directory out = fs.file(lastCallAdditionalArgs.last).parent;
- if (iosArch == null) {
+ if (darwinArch == null) {
out.childFile('app.so').createSync();
out.childFile('gen_snapshot.d').createSync();
return 0;