Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flutter build macos-framework command #105242

Merged
merged 3 commits into from
Jun 3, 2022

Conversation

jmagman
Copy link
Member

@jmagman jmagman commented Jun 2, 2022

Implement flutter build macos-framework to support basic add-to-app for macOS. This can be run from a normal macOS Flutter app, it does not implement the module template.

$ flutter build macos-framework
Running "flutter pub get" in flutter_gallery...                  1,775ms

💪 Building with sound null safety 💪

Building macOS frameworks in debug mode...
 ├─Building App.xcframework and FlutterMacOS.xcframework...        13.5s
Running pod install...                                           1,534ms
 ├─Building plugins...                                              7.7s
 └─Moving to build/macos/framework/Debug
Building macOS frameworks in profile mode...
Building App.framework for x86_64...
Building App.framework for arm64...
 ├─Building App.xcframework and FlutterMacOS.xcframework...        50.1s
 ├─Building plugins...                                              9.5s
 └─Moving to build/macos/framework/Profile
Building macOS frameworks in release mode...
Building App.framework for x86_64...
Building App.framework for arm64...
 ├─Building App.xcframework and FlutterMacOS.xcframework...        45.3s
 ├─Building plugins...                                              8.6s
 └─Moving to build/macos/framework/Release
Frameworks written to /Users/magder/Projects/flutter/dev/integration_tests/flutter_gallery/build/macos/framework.

Copy GeneratedPluginRegistrant.swift into your project.

I don't like the stray Building App.framework for arm64.. logging but it's not coming from this PR, we can address that later.

$ flutter build macos-framework --cocoapods --force

💪 Building with sound null safety 💪

Building macOS frameworks in debug mode...
 ├─Creating FlutterMacOS.podspec...                                  6ms
 ├─Building App.xcframework and FlutterMacOS.xcframework...         3.1s
 ├─Building plugins...                                              7.2s
 └─Moving to build/macos/framework/Debug
Building macOS frameworks in profile mode...
 ├─Creating FlutterMacOS.podspec...                                  1ms
 ├─Building App.xcframework and FlutterMacOS.xcframework...         3.2s
 ├─Building plugins...                                              7.5s
 └─Moving to build/macos/framework/Profile
Building macOS frameworks in release mode...
 ├─Creating FlutterMacOS.podspec...                                  1ms
 ├─Building App.xcframework and FlutterMacOS.xcframework...      2,785ms
 ├─Building plugins...                                              7.5s
 └─Moving to build/macos/framework/Release
Frameworks written to /Users/magder/Projects/flutter/dev/integration_tests/flutter_gallery/build/macos/framework.

Copy GeneratedPluginRegistrant.swift into your project

See also refactoring work in #105194
Fixes #104866

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@jmagman jmagman added tool Affects the "flutter" command-line tool. See also t: labels. platform-mac Building on or for macOS specifically labels Jun 2, 2022
@jmagman jmagman self-assigned this Jun 2, 2022
@flutter-dashboard flutter-dashboard bot added the team Infra upgrades, team productivity, code health, technical debt. See also team: labels. label Jun 2, 2022
Comment on lines 45 to 47
Future<Set<DevelopmentArtifact>> get requiredArtifacts async => const <DevelopmentArtifact>{
DevelopmentArtifact.macOS,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
Future<Set<DevelopmentArtifact>> get requiredArtifacts async => const <DevelopmentArtifact>{
DevelopmentArtifact.macOS,
};
Future<Set<DevelopmentArtifact>> get requiredArtifacts async => const <DevelopmentArtifact>{
DevelopmentArtifact.macOS,
};

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dart-fmt did this 🙁 let me fix by hand.

/// contains the Flutter engine and framework code as well as plugins. It can
/// be integrated into plain Xcode projects without using or other package
/// managers.
class BuildMacOSFrameworkCommand extends BuildFrameworkCommand {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to share more between this and BuildIOSFrameworkCommand but almost every line is subtly different.
For example, the iOS assemble target only creates App.framework, but the macOS one creates App.framework and copies FlutterMacOS.framework, so a separate copy isn't needed. iOS publishes Flutter.xcframework, but macOS publishes FlutterMacOS.framework, which means the xcframework needs to be created. iOS has extra logic for building simulator frameworks, etc.

}

final Status status =
globals.logger.startProgress(' └─Moving to ${globals.fs.path.relative(modeDirectory.path)}');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look like it matches what the following try block is doing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I'll change to a printStatus since I still want to convey the path.

modeDirectory.deleteSync(recursive: true);
}

if (boolArg('cocoapods') ?? false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make these boolArg(...)!? (I believe) the only way this would error out is if a later refactor to the arg parsing results in this command no longer having a cocoapods flag and this code wasn't updated, which would be a tool bug that we'd want to know about.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jasguerrero I keep running into this pattern. Can we make boolArg return a nonnull bool to simplify the code, and have it throw an exception (not toolExit since it's a developer error) if the flag doesn't exist?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a good idea

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed #105263 to track

Copy link
Member

@christopherfujino christopherfujino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fluttergithubbot fluttergithubbot merged commit 3f1f0a8 into flutter:master Jun 3, 2022
@jmagman jmagman deleted the build-macos-fw branch June 3, 2022 17:13
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 3, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Jun 3, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 4, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 4, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 4, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 5, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 5, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 5, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 6, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 6, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 6, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 6, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 6, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
camsim99 pushed a commit to camsim99/flutter that referenced this pull request Aug 10, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform-mac Building on or for macOS specifically team Infra upgrades, team productivity, code health, technical debt. See also team: labels. tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement flutter build macos-framework to allow macOS apps to be embedded in non-Flutter host-apps
3 participants