Skip to content

Introduce command to build a swift package for SwiftPM add to app integration#184660

Merged
auto-submit[bot] merged 6 commits into
flutter:masterfrom
vashworth:enable_swiftpm_add2app
Apr 7, 2026
Merged

Introduce command to build a swift package for SwiftPM add to app integration#184660
auto-submit[bot] merged 6 commits into
flutter:masterfrom
vashworth:enable_swiftpm_add2app

Conversation

@vashworth

Copy link
Copy Markdown
Contributor

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-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.

@vashworth vashworth requested review from a team as code owners April 6, 2026 14:43
@github-actions github-actions Bot added tool Affects the "flutter" command-line tool. See also t: labels. team-ios Owned by iOS platform team team-macos Owned by the macOS platform team team-linux Owned by the Linux platform team labels Apr 6, 2026
@vashworth vashworth added CICD Run CI/CD and removed tool Affects the "flutter" command-line tool. See also t: labels. team-ios Owned by iOS platform team team-macos Owned by the macOS platform team team-linux Owned by the Linux platform team labels Apr 6, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment on lines +42 to +58
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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The constructor for BuildCommand has become quite large with many required parameters. Consider grouping these related dependencies into a configuration object or a service locator to improve maintainability and readability.

Comment on lines +1650 to +1663
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;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This logic for skipping plugins is complex and relies on specific naming conventions and project state. It would be cleaner to encapsulate this filtering logic into a dedicated method or a strategy pattern to make it more testable and readable.

Comment thread packages/flutter_tools/lib/src/commands/build_swift_package.dart
@vashworth vashworth changed the title Enable swiftpm add2app Introduce command to build a swift package for SwiftPM add to app integration Apr 6, 2026
@vashworth vashworth requested a review from stuartmorgan-g April 6, 2026 14:51

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

stuartmorgan-g
stuartmorgan-g previously approved these changes Apr 6, 2026

@stuartmorgan-g stuartmorgan-g left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Comment thread packages/flutter_tools/lib/src/commands/build_swift_package.dart Outdated
Comment thread packages/flutter_tools/lib/src/commands/build_swift_package.dart
// 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.

@hellohuanlin hellohuanlin Apr 6, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think i need some help understanding this:

  1. is _utils.project.isModule always true here? is this file is only for add-to-app usage?

"Flutter modules don't support SwiftPM"

  1. 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.

  1. Is it generated by SwiftPM or Cocoapods?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's not a Swift/ObjC module. It's a term we use to create a funky configured Flutter app

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We have a plan to migrate module apps to normal app structure eventually too: #98077

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No you can do add to app without it being a module. Perhaps the docs were never updated, though

@vashworth vashworth Apr 6, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Here's the PR where that was added: #70647

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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)

Comment thread packages/flutter_tools/lib/src/commands/build_swift_package.dart
@vashworth

Copy link
Copy Markdown
Contributor Author

@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 missing required module 'SwiftOnoneSupport'. This is because when switching build mode, we only swap the Flutter/FlutterMacOS.framework and App.framework. So I thought since we're planning to stop supporting CocoaPods eventually, we could just build in release. However, I realized that native assets could have this problem too.

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

@github-actions github-actions Bot added tool Affects the "flutter" command-line tool. See also t: labels. team-ios Owned by iOS platform team team-macos Owned by the macOS platform team team-linux Owned by the Linux platform team and removed CICD Run CI/CD labels Apr 6, 2026
@vashworth vashworth added the CICD Run CI/CD label Apr 6, 2026
@vashworth vashworth requested a review from stuartmorgan-g April 6, 2026 18:05
@vashworth vashworth added the CICD Run CI/CD label Apr 6, 2026
terminal: FakeTerminal(),
plistParser: FakePlistParser(),
processUtils: FakeProcessUtils(),
processManager: FakeProcessManager.any(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems the only Linux specific change, is it required?

@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 7, 2026
@jmagman jmagman added the CICD Run CI/CD label Apr 7, 2026
@flutter-dashboard

Copy link
Copy Markdown

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 package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #184660 at sha f2dae54

@flutter-dashboard flutter-dashboard Bot added the will affect goldens Changes to golden files label Apr 7, 2026
@vashworth vashworth added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 7, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Apr 7, 2026
Merged via the queue into flutter:master with commit 3bdf02c Apr 7, 2026
155 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Apr 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 7, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Apr 7, 2026
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
mbcorona pushed a commit to mbcorona/flutter that referenced this pull request Apr 15, 2026
…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>
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD team-ios Owned by iOS platform team team-linux Owned by the Linux platform team team-macos Owned by the macOS platform team tool Affects the "flutter" command-line tool. See also t: labels. will affect goldens Changes to golden files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SwiftPM Add2App] Add integration tests and allow command to be used

5 participants