Skip to content

Commit

Permalink
Support single arch local engines for 'build macos-framework' and 'io…
Browse files Browse the repository at this point in the history
…s-framework' (#110564)
  • Loading branch information
jmagman committed Aug 30, 2022
1 parent c49531f commit 5f5d480
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 10 deletions.
9 changes: 9 additions & 0 deletions packages/flutter_tools/lib/src/artifacts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,8 @@ abstract class LocalEngineArtifacts implements Artifacts {
}) = CachedLocalEngineArtifacts;

String get engineOutPath;

String get localEngineName;
}

/// Manages the artifacts of a locally built engine.
Expand All @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -1063,4 +1069,7 @@ class _TestLocalEngine extends _TestArtifacts implements LocalEngineArtifacts {

@override
final String engineOutPath;

@override
String get localEngineName => fileSystem.path.basename(engineOutPath);
}
31 changes: 29 additions & 2 deletions packages/flutter_tools/lib/src/build_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/linux/build_linux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/windows/build_windows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
40 changes: 40 additions & 0 deletions packages/flutter_tools/test/general.shard/build_info_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5f5d480

Please sign in to comment.