Unverified Commit 5f5d4802 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Support single arch local engines for 'build macos-framework' and 'ios-framework' (#110564)

parent c49531f0
...@@ -732,6 +732,8 @@ abstract class LocalEngineArtifacts implements Artifacts { ...@@ -732,6 +732,8 @@ abstract class LocalEngineArtifacts implements Artifacts {
}) = CachedLocalEngineArtifacts; }) = CachedLocalEngineArtifacts;
String get engineOutPath; String get engineOutPath;
String get localEngineName;
} }
/// Manages the artifacts of a locally built engine. /// Manages the artifacts of a locally built engine.
...@@ -745,6 +747,7 @@ class CachedLocalEngineArtifacts implements LocalEngineArtifacts { ...@@ -745,6 +747,7 @@ class CachedLocalEngineArtifacts implements LocalEngineArtifacts {
required Platform platform, required Platform platform,
required OperatingSystemUtils operatingSystemUtils, required OperatingSystemUtils operatingSystemUtils,
}) : _fileSystem = fileSystem, }) : _fileSystem = fileSystem,
localEngineName = fileSystem.path.basename(engineOutPath),
_cache = cache, _cache = cache,
_processManager = processManager, _processManager = processManager,
_platform = platform, _platform = platform,
...@@ -753,6 +756,9 @@ class CachedLocalEngineArtifacts implements LocalEngineArtifacts { ...@@ -753,6 +756,9 @@ class CachedLocalEngineArtifacts implements LocalEngineArtifacts {
@override @override
final String engineOutPath; final String engineOutPath;
@override
final String localEngineName;
final String _hostEngineOutPath; final String _hostEngineOutPath;
final FileSystem _fileSystem; final FileSystem _fileSystem;
final Cache _cache; final Cache _cache;
...@@ -1063,4 +1069,7 @@ class _TestLocalEngine extends _TestArtifacts implements LocalEngineArtifacts { ...@@ -1063,4 +1069,7 @@ class _TestLocalEngine extends _TestArtifacts implements LocalEngineArtifacts {
@override @override
final String engineOutPath; final String engineOutPath;
@override
String get localEngineName => fileSystem.path.basename(engineOutPath);
} }
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'package:package_config/package_config_types.dart'; import 'package:package_config/package_config_types.dart';
import 'artifacts.dart';
import 'base/config.dart'; import 'base/config.dart';
import 'base/context.dart'; import 'base/context.dart';
import 'base/file_system.dart'; import 'base/file_system.dart';
...@@ -562,8 +563,19 @@ enum AndroidArch { ...@@ -562,8 +563,19 @@ enum AndroidArch {
/// The default set of iOS device architectures to build for. /// The default set of iOS device architectures to build for.
List<DarwinArch> defaultIOSArchsForEnvironment( List<DarwinArch> defaultIOSArchsForEnvironment(
EnvironmentType environmentType) { EnvironmentType environmentType,
if (environmentType == EnvironmentType.simulator) { Artifacts artifacts,
) {
// Handle single-arch local engines.
if (artifacts is LocalEngineArtifacts) {
final String localEngineName = artifacts.localEngineName;
if (localEngineName.contains('_arm64')) {
return <DarwinArch>[ DarwinArch.arm64 ];
}
if (localEngineName.contains('_sim')) {
return <DarwinArch>[ DarwinArch.x86_64 ];
}
} else if (environmentType == EnvironmentType.simulator) {
return <DarwinArch>[ return <DarwinArch>[
DarwinArch.x86_64, DarwinArch.x86_64,
DarwinArch.arm64, DarwinArch.arm64,
...@@ -574,6 +586,21 @@ List<DarwinArch> defaultIOSArchsForEnvironment( ...@@ -574,6 +586,21 @@ List<DarwinArch> defaultIOSArchsForEnvironment(
]; ];
} }
/// The default set of macOS device architectures to build for.
List<DarwinArch> defaultMacOSArchsForEnvironment(Artifacts artifacts) {
// Handle single-arch local engines.
if (artifacts is LocalEngineArtifacts) {
if (artifacts.localEngineName.contains('_arm64')) {
return <DarwinArch>[ DarwinArch.arm64 ];
}
return <DarwinArch>[ DarwinArch.x86_64 ];
}
return <DarwinArch>[
DarwinArch.x86_64,
DarwinArch.arm64,
];
}
// Returns the Dart SDK's name for the specified target architecture. // Returns the Dart SDK's name for the specified target architecture.
// //
// When building for Darwin platforms, the tool invokes architecture-specific // When building for Darwin platforms, the tool invokes architecture-specific
......
...@@ -422,7 +422,7 @@ end ...@@ -422,7 +422,7 @@ end
kTargetFile: targetFile, kTargetFile: targetFile,
kTargetPlatform: getNameForTargetPlatform(TargetPlatform.ios), kTargetPlatform: getNameForTargetPlatform(TargetPlatform.ios),
kBitcodeFlag: 'true', kBitcodeFlag: 'true',
kIosArchs: defaultIOSArchsForEnvironment(sdkType) kIosArchs: defaultIOSArchsForEnvironment(sdkType, globals.artifacts!)
.map(getNameForDarwinArch) .map(getNameForDarwinArch)
.join(' '), .join(' '),
kSdkRoot: await globals.xcode!.sdkLocation(sdkType), kSdkRoot: await globals.xcode!.sdkLocation(sdkType),
......
...@@ -193,10 +193,9 @@ end ...@@ -193,10 +193,9 @@ end
defines: <String, String>{ defines: <String, String>{
kTargetFile: targetFile, kTargetFile: targetFile,
kTargetPlatform: getNameForTargetPlatform(TargetPlatform.darwin), kTargetPlatform: getNameForTargetPlatform(TargetPlatform.darwin),
kDarwinArchs: <DarwinArch>[ kDarwinArchs: defaultMacOSArchsForEnvironment(globals.artifacts!)
DarwinArch.x86_64, .map(getNameForDarwinArch)
DarwinArch.arm64, .join(' '),
].map(getNameForDarwinArch).join(' '),
...buildInfo.toBuildSystemEnvironment(), ...buildInfo.toBuildSystemEnvironment(),
}, },
artifacts: globals.artifacts!, artifacts: globals.artifacts!,
......
...@@ -176,7 +176,7 @@ Future<List<String>> _xcodeBuildSettingsLines({ ...@@ -176,7 +176,7 @@ Future<List<String>> _xcodeBuildSettingsLines({
final String engineOutPath = localEngineArtifacts.engineOutPath; final String engineOutPath = localEngineArtifacts.engineOutPath;
xcodeBuildSettings.add('FLUTTER_ENGINE=${globals.fs.path.dirname(globals.fs.path.dirname(engineOutPath))}'); xcodeBuildSettings.add('FLUTTER_ENGINE=${globals.fs.path.dirname(globals.fs.path.dirname(engineOutPath))}');
final String localEngineName = globals.fs.path.basename(engineOutPath); final String localEngineName = localEngineArtifacts.localEngineName;
xcodeBuildSettings.add('LOCAL_ENGINE=$localEngineName'); xcodeBuildSettings.add('LOCAL_ENGINE=$localEngineName');
// Tell Xcode not to build universal binaries for local engines, which are // Tell Xcode not to build universal binaries for local engines, which are
......
...@@ -60,7 +60,7 @@ Future<void> buildLinux( ...@@ -60,7 +60,7 @@ Future<void> buildLinux(
final LocalEngineArtifacts localEngineArtifacts = artifacts; final LocalEngineArtifacts localEngineArtifacts = artifacts;
final String engineOutPath = localEngineArtifacts.engineOutPath; final String engineOutPath = localEngineArtifacts.engineOutPath;
environmentConfig['FLUTTER_ENGINE'] = globals.fs.path.dirname(globals.fs.path.dirname(engineOutPath)); environmentConfig['FLUTTER_ENGINE'] = globals.fs.path.dirname(globals.fs.path.dirname(engineOutPath));
environmentConfig['LOCAL_ENGINE'] = globals.fs.path.basename(engineOutPath); environmentConfig['LOCAL_ENGINE'] = localEngineArtifacts.localEngineName;
} }
writeGeneratedCmakeConfig(Cache.flutterRoot!, linuxProject, buildInfo, environmentConfig); writeGeneratedCmakeConfig(Cache.flutterRoot!, linuxProject, buildInfo, environmentConfig);
......
...@@ -221,7 +221,7 @@ void _writeGeneratedFlutterConfig( ...@@ -221,7 +221,7 @@ void _writeGeneratedFlutterConfig(
if (artifacts is LocalEngineArtifacts) { if (artifacts is LocalEngineArtifacts) {
final String engineOutPath = artifacts.engineOutPath; final String engineOutPath = artifacts.engineOutPath;
environment['FLUTTER_ENGINE'] = globals.fs.path.dirname(globals.fs.path.dirname(engineOutPath)); environment['FLUTTER_ENGINE'] = globals.fs.path.dirname(globals.fs.path.dirname(engineOutPath));
environment['LOCAL_ENGINE'] = globals.fs.path.basename(engineOutPath); environment['LOCAL_ENGINE'] = artifacts.localEngineName;
} }
writeGeneratedCmakeConfig(Cache.flutterRoot!, windowsProject, buildInfo, environment); writeGeneratedCmakeConfig(Cache.flutterRoot!, windowsProject, buildInfo, environment);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
...@@ -99,6 +100,45 @@ void main() { ...@@ -99,6 +100,45 @@ void main() {
expect(getNameForTargetPlatform(TargetPlatform.android), isNot(contains('ios'))); expect(getNameForTargetPlatform(TargetPlatform.android), isNot(contains('ios')));
}); });
testWithoutContext('defaultIOSArchsForEnvironment', () {
expect(defaultIOSArchsForEnvironment(
EnvironmentType.physical,
Artifacts.test(localEngine: 'ios_debug_unopt'),
).single, DarwinArch.arm64);
expect(defaultIOSArchsForEnvironment(
EnvironmentType.simulator,
Artifacts.test(localEngine: 'ios_debug_sim_unopt'),
).single, DarwinArch.x86_64);
expect(defaultIOSArchsForEnvironment(
EnvironmentType.simulator,
Artifacts.test(localEngine: 'ios_debug_sim_unopt_arm64'),
).single, DarwinArch.arm64);
expect(defaultIOSArchsForEnvironment(
EnvironmentType.physical, Artifacts.test(),
).single, DarwinArch.arm64);
expect(defaultIOSArchsForEnvironment(
EnvironmentType.simulator, Artifacts.test(),
), <DarwinArch>[ DarwinArch.x86_64, DarwinArch.arm64 ]);
});
testWithoutContext('defaultMacOSArchsForEnvironment', () {
expect(defaultMacOSArchsForEnvironment(
Artifacts.test(localEngine: 'host_debug_unopt'),
).single, DarwinArch.x86_64);
expect(defaultMacOSArchsForEnvironment(
Artifacts.test(localEngine: 'host_debug_unopt_arm64'),
).single, DarwinArch.arm64);
expect(defaultMacOSArchsForEnvironment(
Artifacts.test(),
), <DarwinArch>[ DarwinArch.x86_64, DarwinArch.arm64 ]);
});
testWithoutContext('getIOSArchForName on Darwin arches', () { testWithoutContext('getIOSArchForName on Darwin arches', () {
expect(getIOSArchForName('armv7'), DarwinArch.armv7); expect(getIOSArchForName('armv7'), DarwinArch.armv7);
expect(getIOSArchForName('arm64'), DarwinArch.arm64); expect(getIOSArchForName('arm64'), DarwinArch.arm64);
......
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