Introduce command to build a swift package for SwiftPM add to app integration#184660
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces Swift Package Manager (SwiftPM) integration for Flutter add-to-app scenarios on iOS and macOS. It adds the 'build swift-package' command, updates the build system to handle plugin dependencies, and includes integration tests for verifying the SwiftPM integration. The reviewer suggested refactoring the large BuildCommand constructor, encapsulating complex plugin filtering logic, and reconsidering the hardcoded build mode selection for non-simulator SDKs.
| required Artifacts artifacts, | ||
| required Cache cache, | ||
| required FileSystem fileSystem, | ||
| required FlutterVersion flutterVersion, | ||
| required BuildSystem buildSystem, | ||
| required OperatingSystemUtils osUtils, | ||
| required Logger logger, | ||
| required AndroidSdk? androidSdk, | ||
| required Config config, | ||
| required Platform platform, | ||
| required ProcessUtils processUtils, | ||
| required ProcessManager processManager, | ||
| required FileSystemUtils fileSystemUtils, | ||
| required TemplateRenderer templateRenderer, | ||
| required Terminal terminal, | ||
| required PlistParser plistParser, | ||
| required Xcode? xcode, |
| if (_utils.project.isModule && | ||
| (binaryName == 'FlutterPluginRegistrant' || | ||
| pluginSwiftDependencies.copiedPlugins.any((record) => record.name == binaryName))) { | ||
| // Flutter modules don't support SwiftPM and force all plugins to be built as CocoaPods. | ||
| // Since SwiftPM supported plugins are used as Swift packages in this command, they should | ||
| // be skipped and not included as CocoaPod framework dependencies. | ||
| // In addition, modules generate a FlutterPluginRegistrant framework. Since the | ||
| // FlutterPluginRegistrant is also being used as a Swift Package in this command, it should | ||
| // also be skipped. | ||
| // TODO(vashworth): Find a way to prevent CocoaPods from building SwiftPM plugins and | ||
| // FlutterPluginRegistrant when using a module in the first place. | ||
| // See https://github.com/flutter/flutter/issues/184590. | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Everything under dev/integration_tests/darwin_add2app_swiftpm is just native iOS/macOS projects with SwiftPM stuff pre-integrated. See go/swiftpm-add2app-draft-docs for explanation of how it get integrated. I also just realized I forgot a README. I'll add one shortly.
| // also be skipped. | ||
| // TODO(vashworth): Find a way to prevent CocoaPods from building SwiftPM plugins and | ||
| // FlutterPluginRegistrant when using a module in the first place. | ||
| // See https://github.com/flutter/flutter/issues/184590. |
There was a problem hiding this comment.
I think i need some help understanding this:
- is
_utils.project.isModulealways true here? is this file is only for add-to-app usage?
"Flutter modules don't support SwiftPM"
- Do you mean Flutter modules don't support using SwiftPM for plugins? (it isn't clear to me what "support SwiftPM" means - aren't we generating packages for flutter modules use case here?)
modules generate a FlutterPluginRegistrant framework.
- Is it generated by SwiftPM or Cocoapods?
There was a problem hiding this comment.
is _utils.project.isModule always true here? is this file is only for add-to-app usage?
No, it's only flutter projects created with flutter create --template module, which is specifically for add to app (via CocoaPods). We will likely deprecate that template eventually.
Do you mean Flutter modules don't support using SwiftPM for plugins? (it isn't clear to me what "support SwiftPM" means - aren't we generating packages for flutter modules use case here?)
Flutter modules have a different file structure (the directory is .ios instead of ios) and use a different podhelpher.rb. They are meant to be used with the flutter build ios-framework command, which does not support SwiftPM.
modules generate a FlutterPluginRegistrant framework.
CocoaPods
There was a problem hiding this comment.
It's not a Swift/ObjC module. It's a term we use to create a funky configured Flutter app
There was a problem hiding this comment.
We have a plan to migrate module apps to normal app structure eventually too: #98077
There was a problem hiding this comment.
No, it's only flutter projects created with flutter create --template module, which is specifically for add to app (via CocoaPods). We will likely deprecate that template eventually.
I thought all add-to-app are created using flutter create --template module? that's in our official instruction. am i getting it wrong?
There was a problem hiding this comment.
No you can do add to app without it being a module. Perhaps the docs were never updated, though
There was a problem hiding this comment.
Here's the PR where that was added: #70647
There was a problem hiding this comment.
Discussed offline -
flutter module setup relies on Cocoapods to build the frameworks, and we treat them as binaryTargets in package, so we have to filter it. The future plan is that we should be able to run flutter build swift-package on a normal flutter app, which is the part i was missing. (@vashworth correct me if wrong)
|
@stuartmorgan-g @hellohuanlin I decided to refactor and add a pre-action script 😞 I was hoping to avoid it, but I think we have to. While I was integration testing, I discovered an issue with CocoaPods plugins failing to build due to So I decided to introduce a pre-action. During the pre-action, it swaps the symlink to the correct build mode so during the build it uses the correct one. Sorry for the last minute switch up. I really wanted to avoid a pre-action |
| terminal: FakeTerminal(), | ||
| plistParser: FakePlistParser(), | ||
| processUtils: FakeProcessUtils(), | ||
| processManager: FakeProcessManager.any(), |
There was a problem hiding this comment.
This seems the only Linux specific change, is it required?
|
Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change). If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
flutter/flutter@9cd60b5...a0924c7 2026-04-07 dacoharkes@google.com Reland "[data_assets] Cleanup tests" (flutter/flutter#184714) 2026-04-07 matt.kosarek@canonical.com Use the WindowRegistry in the multiple_windows example app (flutter/flutter#184579) 2026-04-07 15619084+vashworth@users.noreply.github.com Introduce command to build a swift package for SwiftPM add to app integration (flutter/flutter#184660) 2026-04-07 sigurdm@google.com Have `flutter create` create a pubspec.lock to ensure pinned versions are being used. (flutter/flutter#175352) 2026-04-07 59215665+davidhicks980@users.noreply.github.com [widgets/raw_menu_anchor.dart] Always call onClose and onCloseRequested on descendants before parent. (flutter/flutter#182357) 2026-04-07 rmolivares@renzo-olivares.dev `WindowsPlugin` should not crash when ffiPlugin enabled (flutter/flutter#184695) 2026-04-06 97480502+b-luk@users.noreply.github.com Use full goto.google.com hostname for go/ links (flutter/flutter#184679) 2026-04-06 34871572+gmackall@users.noreply.github.com Apply rect clipping to surface views (flutter/flutter#184471) 2026-04-06 jhy03261997@gmail.com [A11y] Allow percentage strings like "50%" as `SemanticsValue` for `ProgressIndicator` (flutter/flutter#183670) 2026-04-06 louisehsu@google.com Fix invisible accessibility element before scroll view (flutter/flutter#184155) 2026-04-06 engine-flutter-autoroll@skia.org Roll Skia from 163dfdf500c7 to e264d870a380 (2 revisions) (flutter/flutter#184674) 2026-04-06 54688429+TrangLeQuynh@users.noreply.github.com Keep last character obscured when toggling obscureText (flutter/flutter#183488) 2026-04-06 15619084+vashworth@users.noreply.github.com Parse scheme file with XML parser for SwiftPM migrator (flutter/flutter#184525) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC bmparr@google.com,stuartmorgan@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…egration (flutter#184660) Enable the SwiftPM add to app command (`flutter build swift-package`) and add integration test to verify it works. Fixes flutter#181223. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Jenn Magder <magder@google.com>
…r#11463) flutter/flutter@9cd60b5...a0924c7 2026-04-07 dacoharkes@google.com Reland "[data_assets] Cleanup tests" (flutter/flutter#184714) 2026-04-07 matt.kosarek@canonical.com Use the WindowRegistry in the multiple_windows example app (flutter/flutter#184579) 2026-04-07 15619084+vashworth@users.noreply.github.com Introduce command to build a swift package for SwiftPM add to app integration (flutter/flutter#184660) 2026-04-07 sigurdm@google.com Have `flutter create` create a pubspec.lock to ensure pinned versions are being used. (flutter/flutter#175352) 2026-04-07 59215665+davidhicks980@users.noreply.github.com [widgets/raw_menu_anchor.dart] Always call onClose and onCloseRequested on descendants before parent. (flutter/flutter#182357) 2026-04-07 rmolivares@renzo-olivares.dev `WindowsPlugin` should not crash when ffiPlugin enabled (flutter/flutter#184695) 2026-04-06 97480502+b-luk@users.noreply.github.com Use full goto.google.com hostname for go/ links (flutter/flutter#184679) 2026-04-06 34871572+gmackall@users.noreply.github.com Apply rect clipping to surface views (flutter/flutter#184471) 2026-04-06 jhy03261997@gmail.com [A11y] Allow percentage strings like "50%" as `SemanticsValue` for `ProgressIndicator` (flutter/flutter#183670) 2026-04-06 louisehsu@google.com Fix invisible accessibility element before scroll view (flutter/flutter#184155) 2026-04-06 engine-flutter-autoroll@skia.org Roll Skia from 163dfdf500c7 to e264d870a380 (2 revisions) (flutter/flutter#184674) 2026-04-06 54688429+TrangLeQuynh@users.noreply.github.com Keep last character obscured when toggling obscureText (flutter/flutter#183488) 2026-04-06 15619084+vashworth@users.noreply.github.com Parse scheme file with XML parser for SwiftPM migrator (flutter/flutter#184525) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC bmparr@google.com,stuartmorgan@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Enable the SwiftPM add to app command (
flutter build swift-package) and add integration test to verify it works.Fixes #181223.
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.