Skip to content

Commit 42252cd

Browse files
authored
Add FlutterMacOS.xcframework artifact (#143244)
Replace `FlutterMacOS.framework` cached artifact with `FlutterMacOS.xcframework`. Also, update usage of `FlutterMacOS.framework` to use `FlutterMacOS.xcframework`. Part of flutter/flutter#126016.
1 parent b2a3075 commit 42252cd

File tree

11 files changed

+322
-83
lines changed

11 files changed

+322
-83
lines changed

dev/bots/test.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,9 +1728,9 @@ List<String> binariesWithEntitlements(String flutterRoot) {
17281728
/// cache.
17291729
List<String> binariesWithoutEntitlements(String flutterRoot) {
17301730
return <String>[
1731-
'artifacts/engine/darwin-x64-profile/FlutterMacOS.framework/Versions/A/FlutterMacOS',
1732-
'artifacts/engine/darwin-x64-release/FlutterMacOS.framework/Versions/A/FlutterMacOS',
1733-
'artifacts/engine/darwin-x64/FlutterMacOS.framework/Versions/A/FlutterMacOS',
1731+
'artifacts/engine/darwin-x64-profile/FlutterMacOS.xcframework/macos-arm64_x86_64/FlutterMacOS.framework/Versions/A/FlutterMacOS',
1732+
'artifacts/engine/darwin-x64-release/FlutterMacOS.xcframework/macos-arm64_x86_64/FlutterMacOS.framework/Versions/A/FlutterMacOS',
1733+
'artifacts/engine/darwin-x64/FlutterMacOS.xcframework/macos-arm64_x86_64/FlutterMacOS.framework/Versions/A/FlutterMacOS',
17341734
'artifacts/engine/darwin-x64/font-subset',
17351735
'artifacts/engine/darwin-x64/impellerc',
17361736
'artifacts/engine/darwin-x64/libpath_ops.dylib',
@@ -1764,6 +1764,9 @@ List<String> signedXcframeworks(String flutterRoot) {
17641764
'artifacts/engine/ios-release/extension_safe/Flutter.xcframework',
17651765
'artifacts/engine/ios/Flutter.xcframework',
17661766
'artifacts/engine/ios/extension_safe/Flutter.xcframework',
1767+
'artifacts/engine/darwin-x64-profile/FlutterMacOS.xcframework',
1768+
'artifacts/engine/darwin-x64-release/FlutterMacOS.xcframework',
1769+
'artifacts/engine/darwin-x64/FlutterMacOS.xcframework',
17671770
]
17681771
.map((String relativePath) => path.join(flutterRoot, 'bin', 'cache', relativePath)).toList();
17691772
}

dev/devicelab/lib/tasks/plugin_tests.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ class PluginTest {
118118
// Currently this test is only implemented for macOS; it can be extended to
119119
// others as needed.
120120
if (buildTarget == 'macos') {
121+
// When using a local engine, podhelper.rb will search for a "macos-"
122+
// directory within the FlutterMacOS.xcframework, so create a dummy one.
123+
Directory(
124+
path.join(buildDir.path, 'FlutterMacOS.xcframework/macos-arm64_x86_64'),
125+
).createSync(recursive: true);
126+
121127
// Clean before regenerating the config to ensure that the pod steps run.
122128
await inDirectory(Directory(app.rootPath), () async {
123129
await evalFlutter('clean');

packages/flutter_tools/bin/podhelper.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ def flutter_additional_macos_build_settings(target)
137137
# This podhelper script is at $FLUTTER_ROOT/packages/flutter_tools/bin.
138138
# Add search paths from $FLUTTER_ROOT/bin/cache/artifacts/engine.
139139
artifacts_dir = File.join('..', '..', '..', '..', 'bin', 'cache', 'artifacts', 'engine')
140-
debug_framework_dir = File.expand_path(File.join(artifacts_dir, 'darwin-x64'), __FILE__)
141-
release_framework_dir = File.expand_path(File.join(artifacts_dir, 'darwin-x64-release'), __FILE__)
140+
debug_framework_dir = File.expand_path(File.join(artifacts_dir, 'darwin-x64', 'FlutterMacOS.xcframework'), __FILE__)
141+
release_framework_dir = File.expand_path(File.join(artifacts_dir, 'darwin-x64-release', 'FlutterMacOS.xcframework'), __FILE__)
142142
application_path = File.dirname(defined_in_file.realpath) if respond_to?(:defined_in_file)
143143
# Find the local engine path, if any.
144144
local_engine = application_path.nil? ?
@@ -156,9 +156,17 @@ def flutter_additional_macos_build_settings(target)
156156
# Skip other updates if it does not depend on Flutter (including transitive dependency)
157157
next unless depends_on_flutter(target, 'FlutterMacOS')
158158

159-
# Profile can't be derived from the CocoaPods build configuration. Use release framework (for linking only).
160-
configuration_engine_dir = local_engine || (build_configuration.type == :debug ? debug_framework_dir : release_framework_dir)
161-
build_configuration.build_settings['FRAMEWORK_SEARCH_PATHS'] = "\"#{configuration_engine_dir}\" $(inherited)"
159+
if local_engine
160+
configuration_engine_dir = File.expand_path(File.join(local_engine, 'FlutterMacOS.xcframework'), __FILE__)
161+
else
162+
# Profile can't be derived from the CocoaPods build configuration. Use release framework (for linking only).
163+
configuration_engine_dir = (build_configuration.type == :debug ? debug_framework_dir : release_framework_dir)
164+
end
165+
Dir.new(configuration_engine_dir).each_child do |xcframework_file|
166+
if xcframework_file.start_with?('macos-') # Could be macos-arm64_x86_64, macos-arm64, macos-x86_64
167+
build_configuration.build_settings['FRAMEWORK_SEARCH_PATHS'] = "\"#{configuration_engine_dir}/#{xcframework_file}\" $(inherited)"
168+
end
169+
end
162170

163171
# When deleted, the deployment version will inherit from the higher version derived from the 'Runner' target.
164172
# If the pod only supports a higher version, do not delete to correctly produce an error.

packages/flutter_tools/lib/src/artifacts.dart

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ enum Artifact {
2525
flutterXcframework,
2626
/// The framework directory of the macOS desktop.
2727
flutterMacOSFramework,
28+
flutterMacOSXcframework,
2829
vmSnapshotData,
2930
isolateSnapshotData,
3031
icuData,
@@ -184,6 +185,8 @@ String? _artifactToFileName(Artifact artifact, Platform hostPlatform, [ BuildMod
184185
return 'Flutter.xcframework';
185186
case Artifact.flutterMacOSFramework:
186187
return 'FlutterMacOS.framework';
188+
case Artifact.flutterMacOSXcframework:
189+
return 'FlutterMacOS.xcframework';
187190
case Artifact.vmSnapshotData:
188191
return 'vm_isolate_snapshot.bin';
189192
case Artifact.isolateSnapshotData:
@@ -598,6 +601,10 @@ class CachedArtifacts implements Artifacts {
598601
final String engineDir = _getEngineArtifactsPath(platform, mode)!;
599602
return _fileSystem.path.join(engineDir, _artifactToFileName(artifact, _platform));
600603
}
604+
if (platform != null && artifact == Artifact.flutterMacOSFramework) {
605+
final String engineDir = _getEngineArtifactsPath(platform, mode)!;
606+
return _getMacOSEngineArtifactPath(engineDir, _fileSystem, _platform);
607+
}
601608
return _getHostArtifactPath(artifact, platform ?? _currentHostPlatform(_platform, _operatingSystemUtils), mode);
602609
}
603610

@@ -617,6 +624,7 @@ class CachedArtifacts implements Artifacts {
617624
case Artifact.constFinder:
618625
case Artifact.flutterFramework:
619626
case Artifact.flutterMacOSFramework:
627+
case Artifact.flutterMacOSXcframework:
620628
case Artifact.flutterPatchedSdkPath:
621629
case Artifact.flutterTester:
622630
case Artifact.flutterXcframework:
@@ -657,6 +665,7 @@ class CachedArtifacts implements Artifacts {
657665
case Artifact.frontendServerSnapshotForEngineDartSdk:
658666
case Artifact.constFinder:
659667
case Artifact.flutterMacOSFramework:
668+
case Artifact.flutterMacOSXcframework:
660669
case Artifact.flutterPatchedSdkPath:
661670
case Artifact.flutterTester:
662671
case Artifact.fontSubset:
@@ -705,6 +714,7 @@ class CachedArtifacts implements Artifacts {
705714
case Artifact.constFinder:
706715
case Artifact.flutterFramework:
707716
case Artifact.flutterMacOSFramework:
717+
case Artifact.flutterMacOSXcframework:
708718
case Artifact.flutterTester:
709719
case Artifact.flutterXcframework:
710720
case Artifact.fontSubset:
@@ -771,6 +781,13 @@ class CachedArtifacts implements Artifacts {
771781
case Artifact.engineDartAotRuntime:
772782
return _fileSystem.path.join(_dartSdkPath(_cache), 'bin', _artifactToFileName(artifact, _platform));
773783
case Artifact.flutterMacOSFramework:
784+
String platformDirName = _enginePlatformDirectoryName(platform);
785+
if (mode == BuildMode.profile || mode == BuildMode.release) {
786+
platformDirName = '$platformDirName-${mode!.cliName}';
787+
}
788+
final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path;
789+
return _getMacOSEngineArtifactPath(_fileSystem.path.join(engineArtifactsPath, platformDirName), _fileSystem, _platform);
790+
case Artifact.flutterMacOSXcframework:
774791
case Artifact.linuxDesktopPath:
775792
case Artifact.windowsDesktopPath:
776793
case Artifact.linuxHeaders:
@@ -896,6 +913,33 @@ String _getIosEngineArtifactPath(String engineDirectory,
896913
.path;
897914
}
898915

916+
String _getMacOSEngineArtifactPath(
917+
String engineDirectory,
918+
FileSystem fileSystem,
919+
Platform hostPlatform,
920+
) {
921+
final Directory xcframeworkDirectory = fileSystem
922+
.directory(engineDirectory)
923+
.childDirectory(_artifactToFileName(Artifact.flutterMacOSXcframework, hostPlatform)!);
924+
925+
if (!xcframeworkDirectory.existsSync()) {
926+
throwToolExit('No xcframework found at ${xcframeworkDirectory.path}. Try running "flutter precache --macos".');
927+
}
928+
final Directory? flutterFrameworkSource = xcframeworkDirectory
929+
.listSync()
930+
.whereType<Directory>()
931+
.where((Directory platformDirectory) =>
932+
platformDirectory.basename.startsWith('macos-'))
933+
.firstOrNull;
934+
if (flutterFrameworkSource == null) {
935+
throwToolExit('No macOS frameworks found in ${xcframeworkDirectory.path}');
936+
}
937+
938+
return flutterFrameworkSource
939+
.childDirectory(_artifactToFileName(Artifact.flutterMacOSFramework, hostPlatform)!)
940+
.path;
941+
}
942+
899943
/// Manages the artifacts of a locally built engine.
900944
class CachedLocalEngineArtifacts implements Artifacts {
901945
CachedLocalEngineArtifacts(
@@ -1054,7 +1098,7 @@ class CachedLocalEngineArtifacts implements Artifacts {
10541098
return _fileSystem.path.join(localEngineInfo.targetOutPath, 'gen', 'flutter', 'lib', 'snapshot', artifactFileName);
10551099
case Artifact.icuData:
10561100
case Artifact.flutterXcframework:
1057-
case Artifact.flutterMacOSFramework:
1101+
case Artifact.flutterMacOSXcframework:
10581102
return _fileSystem.path.join(localEngineInfo.targetOutPath, artifactFileName);
10591103
case Artifact.platformKernelDill:
10601104
if (platform == TargetPlatform.fuchsia_x64 || platform == TargetPlatform.fuchsia_arm64) {
@@ -1066,6 +1110,9 @@ class CachedLocalEngineArtifacts implements Artifacts {
10661110
case Artifact.flutterFramework:
10671111
return _getIosEngineArtifactPath(
10681112
localEngineInfo.targetOutPath, environmentType, _fileSystem, _platform);
1113+
case Artifact.flutterMacOSFramework:
1114+
return _getMacOSEngineArtifactPath(
1115+
localEngineInfo.targetOutPath, _fileSystem, _platform);
10691116
case Artifact.flutterPatchedSdkPath:
10701117
// When using local engine always use [BuildMode.debug] regardless of
10711118
// what was specified in [mode] argument because local engine will
@@ -1246,6 +1293,7 @@ class CachedLocalWebSdkArtifacts implements Artifacts {
12461293
case Artifact.flutterFramework:
12471294
case Artifact.flutterXcframework:
12481295
case Artifact.flutterMacOSFramework:
1296+
case Artifact.flutterMacOSXcframework:
12491297
case Artifact.vmSnapshotData:
12501298
case Artifact.isolateSnapshotData:
12511299
case Artifact.icuData:

packages/flutter_tools/lib/src/build_system/targets/macos.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class ReleaseUnpackMacOS extends UnpackMacOS {
157157
@override
158158
List<Source> get inputs => <Source>[
159159
...super.inputs,
160-
const Source.artifact(Artifact.flutterMacOSFramework, mode: BuildMode.release),
160+
const Source.artifact(Artifact.flutterMacOSXcframework, mode: BuildMode.release),
161161
];
162162
}
163163

@@ -171,7 +171,7 @@ class ProfileUnpackMacOS extends UnpackMacOS {
171171
@override
172172
List<Source> get inputs => <Source>[
173173
...super.inputs,
174-
const Source.artifact(Artifact.flutterMacOSFramework, mode: BuildMode.profile),
174+
const Source.artifact(Artifact.flutterMacOSXcframework, mode: BuildMode.profile),
175175
];
176176
}
177177

@@ -185,7 +185,7 @@ class DebugUnpackMacOS extends UnpackMacOS {
185185
@override
186186
List<Source> get inputs => <Source>[
187187
...super.inputs,
188-
const Source.artifact(Artifact.flutterMacOSFramework, mode: BuildMode.debug),
188+
const Source.artifact(Artifact.flutterMacOSXcframework, mode: BuildMode.debug),
189189
];
190190
}
191191

packages/flutter_tools/lib/src/cache.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -944,14 +944,6 @@ abstract class EngineCachedArtifact extends CachedArtifact {
944944
await artifactUpdater.downloadZipArchive('Downloading $friendlyName tools...', Uri.parse(url + urlPath), dir);
945945

946946
_makeFilesExecutable(dir, operatingSystemUtils);
947-
948-
final File frameworkZip = fileSystem.file(fileSystem.path.join(dir.path, 'FlutterMacOS.framework.zip'));
949-
if (frameworkZip.existsSync()) {
950-
final Directory framework = fileSystem.directory(fileSystem.path.join(dir.path, 'FlutterMacOS.framework'));
951-
ErrorHandlingFileSystem.deleteIfExists(framework, recursive: true);
952-
framework.createSync();
953-
operatingSystemUtils.unzip(frameworkZip, framework);
954-
}
955947
}
956948

957949
final File licenseSource = cache.getLicenseFile();

packages/flutter_tools/lib/src/commands/build_macos_framework.dart

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:meta/meta.dart';
66

7+
import '../artifacts.dart';
78
import '../base/common.dart';
89
import '../base/file_system.dart';
910
import '../base/io.dart';
@@ -83,13 +84,16 @@ class BuildMacOSFrameworkCommand extends BuildFrameworkCommand {
8384

8485
if (boolArg('cocoapods')) {
8586
produceFlutterPodspec(buildInfo.mode, modeDirectory, force: boolArg('force'));
87+
} else {
88+
await _produceFlutterFramework(buildInfo, modeDirectory);
8689
}
8790

88-
// Build aot, create App.framework and copy FlutterMacOS.framework. Make XCFrameworks.
89-
await _produceAppFramework(buildInfo, modeDirectory);
91+
final Directory buildOutput = modeDirectory.childDirectory('macos');
92+
93+
// Build aot, create App.framework. Make XCFrameworks.
94+
await _produceAppFramework(buildInfo, modeDirectory, buildOutput);
9095

9196
// Build and copy plugins.
92-
final Directory buildOutput = modeDirectory.childDirectory('macos');
9397
await processPodsIfNeeded(project.macos, getMacOSBuildDirectory(), buildInfo.mode);
9498
if (boolArg('plugins') && hasPlugins(project)) {
9599
await _producePlugins(xcodeBuildConfiguration, buildOutput, modeDirectory);
@@ -200,15 +204,15 @@ end
200204
Future<void> _produceAppFramework(
201205
BuildInfo buildInfo,
202206
Directory outputBuildDirectory,
207+
Directory macosBuildOutput,
203208
) async {
204209
final Status status = globals.logger.startProgress(
205-
' ├─Building App.xcframework and FlutterMacOS.xcframework...',
210+
' ├─Building App.xcframework...',
206211
);
207-
208212
try {
209213
final Environment environment = Environment(
210214
projectDir: globals.fs.currentDirectory,
211-
outputDir: outputBuildDirectory,
215+
outputDir: macosBuildOutput,
212216
buildDir: project.dartTool.childDirectory('flutter_build'),
213217
cacheDir: globals.cache.getRoot(),
214218
flutterRootDir: globals.fs.directory(Cache.flutterRoot),
@@ -251,26 +255,45 @@ end
251255
status.stop();
252256
}
253257

254-
final Directory appFramework = outputBuildDirectory.childDirectory('App.framework');
258+
final Directory appFramework = macosBuildOutput.childDirectory('App.framework');
255259
await BuildFrameworkCommand.produceXCFramework(
256260
<Directory>[appFramework],
257261
'App',
258262
outputBuildDirectory,
259263
globals.processManager,
260264
);
261265
appFramework.deleteSync(recursive: true);
262-
final Directory flutterFramework = outputBuildDirectory.childDirectory('FlutterMacOS.framework');
263-
264-
// If FlutterMacOS.podspec was generated, do not generate XCFramework.
265-
if (!boolArg('cocoapods')) {
266-
await BuildFrameworkCommand.produceXCFramework(
267-
<Directory>[flutterFramework],
268-
'FlutterMacOS',
269-
outputBuildDirectory,
270-
globals.processManager,
266+
}
267+
268+
Future<void> _produceFlutterFramework(
269+
BuildInfo buildInfo,
270+
Directory modeDirectory,
271+
) async {
272+
final Status status = globals.logger.startProgress(
273+
' ├─Copying FlutterMacOS.xcframework...',
274+
);
275+
final String engineCacheFlutterFrameworkDirectory = globals.artifacts!.getArtifactPath(
276+
Artifact.flutterMacOSXcframework,
277+
platform: TargetPlatform.darwin,
278+
mode: buildInfo.mode,
279+
);
280+
final String flutterFrameworkFileName = globals.fs.path.basename(
281+
engineCacheFlutterFrameworkDirectory,
282+
);
283+
final Directory flutterFrameworkCopy = modeDirectory.childDirectory(
284+
flutterFrameworkFileName,
285+
);
286+
287+
try {
288+
// Copy xcframework engine cache framework to mode directory.
289+
copyDirectory(
290+
globals.fs.directory(engineCacheFlutterFrameworkDirectory),
291+
flutterFrameworkCopy,
292+
followLinks: false,
271293
);
294+
} finally {
295+
status.stop();
272296
}
273-
flutterFramework.deleteSync(recursive: true);
274297
}
275298

276299
Future<void> _producePlugins(

packages/flutter_tools/lib/src/flutter_cache.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -858,12 +858,12 @@ List<List<String>> _getWindowsDesktopBinaryDirs(String arch) {
858858
}
859859

860860
const List<List<String>> _macOSDesktopBinaryDirs = <List<String>>[
861-
<String>['darwin-x64', 'darwin-x64/FlutterMacOS.framework.zip'],
861+
<String>['darwin-x64', 'darwin-x64/framework.zip'],
862862
<String>['darwin-x64', 'darwin-x64/gen_snapshot.zip'],
863-
<String>['darwin-x64-profile', 'darwin-x64-profile/FlutterMacOS.framework.zip'],
863+
<String>['darwin-x64-profile', 'darwin-x64-profile/framework.zip'],
864864
<String>['darwin-x64-profile', 'darwin-x64-profile/artifacts.zip'],
865865
<String>['darwin-x64-profile', 'darwin-x64-profile/gen_snapshot.zip'],
866-
<String>['darwin-x64-release', 'darwin-x64-release/FlutterMacOS.framework.zip'],
866+
<String>['darwin-x64-release', 'darwin-x64-release/framework.zip'],
867867
<String>['darwin-x64-release', 'darwin-x64-release/artifacts.zip'],
868868
<String>['darwin-x64-release', 'darwin-x64-release/gen_snapshot.zip'],
869869
];

0 commit comments

Comments
 (0)