mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Support single arch local engines for 'build macos-framework' and 'ios-framework' (#110564)
This commit is contained in:
parent
c49531f02c
commit
5f5d4802fe
@ -732,6 +732,8 @@ abstract class LocalEngineArtifacts implements Artifacts {
|
||||
}) = CachedLocalEngineArtifacts;
|
||||
|
||||
String get engineOutPath;
|
||||
|
||||
String get localEngineName;
|
||||
}
|
||||
|
||||
/// Manages the artifacts of a locally built engine.
|
||||
@ -745,6 +747,7 @@ class CachedLocalEngineArtifacts implements LocalEngineArtifacts {
|
||||
required Platform platform,
|
||||
required OperatingSystemUtils operatingSystemUtils,
|
||||
}) : _fileSystem = fileSystem,
|
||||
localEngineName = fileSystem.path.basename(engineOutPath),
|
||||
_cache = cache,
|
||||
_processManager = processManager,
|
||||
_platform = platform,
|
||||
@ -753,6 +756,9 @@ class CachedLocalEngineArtifacts implements LocalEngineArtifacts {
|
||||
@override
|
||||
final String engineOutPath;
|
||||
|
||||
@override
|
||||
final String localEngineName;
|
||||
|
||||
final String _hostEngineOutPath;
|
||||
final FileSystem _fileSystem;
|
||||
final Cache _cache;
|
||||
@ -1063,4 +1069,7 @@ class _TestLocalEngine extends _TestArtifacts implements LocalEngineArtifacts {
|
||||
|
||||
@override
|
||||
final String engineOutPath;
|
||||
|
||||
@override
|
||||
String get localEngineName => fileSystem.path.basename(engineOutPath);
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
import 'package:package_config/package_config_types.dart';
|
||||
|
||||
import 'artifacts.dart';
|
||||
import 'base/config.dart';
|
||||
import 'base/context.dart';
|
||||
import 'base/file_system.dart';
|
||||
@ -562,8 +563,19 @@ enum AndroidArch {
|
||||
|
||||
/// The default set of iOS device architectures to build for.
|
||||
List<DarwinArch> defaultIOSArchsForEnvironment(
|
||||
EnvironmentType environmentType) {
|
||||
if (environmentType == EnvironmentType.simulator) {
|
||||
EnvironmentType environmentType,
|
||||
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>[
|
||||
DarwinArch.x86_64,
|
||||
DarwinArch.arm64,
|
||||
@ -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.
|
||||
//
|
||||
// When building for Darwin platforms, the tool invokes architecture-specific
|
||||
|
||||
@ -422,7 +422,7 @@ end
|
||||
kTargetFile: targetFile,
|
||||
kTargetPlatform: getNameForTargetPlatform(TargetPlatform.ios),
|
||||
kBitcodeFlag: 'true',
|
||||
kIosArchs: defaultIOSArchsForEnvironment(sdkType)
|
||||
kIosArchs: defaultIOSArchsForEnvironment(sdkType, globals.artifacts!)
|
||||
.map(getNameForDarwinArch)
|
||||
.join(' '),
|
||||
kSdkRoot: await globals.xcode!.sdkLocation(sdkType),
|
||||
|
||||
@ -193,10 +193,9 @@ end
|
||||
defines: <String, String>{
|
||||
kTargetFile: targetFile,
|
||||
kTargetPlatform: getNameForTargetPlatform(TargetPlatform.darwin),
|
||||
kDarwinArchs: <DarwinArch>[
|
||||
DarwinArch.x86_64,
|
||||
DarwinArch.arm64,
|
||||
].map(getNameForDarwinArch).join(' '),
|
||||
kDarwinArchs: defaultMacOSArchsForEnvironment(globals.artifacts!)
|
||||
.map(getNameForDarwinArch)
|
||||
.join(' '),
|
||||
...buildInfo.toBuildSystemEnvironment(),
|
||||
},
|
||||
artifacts: globals.artifacts!,
|
||||
|
||||
@ -176,7 +176,7 @@ Future<List<String>> _xcodeBuildSettingsLines({
|
||||
final String engineOutPath = localEngineArtifacts.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');
|
||||
|
||||
// Tell Xcode not to build universal binaries for local engines, which are
|
||||
|
||||
@ -60,7 +60,7 @@ Future<void> buildLinux(
|
||||
final LocalEngineArtifacts localEngineArtifacts = artifacts;
|
||||
final String engineOutPath = localEngineArtifacts.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);
|
||||
|
||||
|
||||
@ -221,7 +221,7 @@ void _writeGeneratedFlutterConfig(
|
||||
if (artifacts is LocalEngineArtifacts) {
|
||||
final String engineOutPath = artifacts.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);
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// 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/build_info.dart';
|
||||
|
||||
@ -99,6 +100,45 @@ void main() {
|
||||
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', () {
|
||||
expect(getIOSArchForName('armv7'), DarwinArch.armv7);
|
||||
expect(getIOSArchForName('arm64'), DarwinArch.arm64);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user