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 Swift Package Manager docs #10827

Merged
merged 76 commits into from
Jul 16, 2024
Merged

Conversation

loic-sharma
Copy link
Member

@loic-sharma loic-sharma commented Jun 28, 2024

Flutter iOS/macOS is migrating to Swift Package Manager for native dependencies. This is an experimental feature this isn't ready yet for app developers. However, plugin authors should add Swift Package Manager support to their packages.

The faster plugin authors add SwiftPM support, the sooner we can drop CocoaPods (and make it easier to install Flutter iOS!). There's ~10K Flutter iOS plugins that'll need to migrate, so we really need the plugin migration docs to be as easy to follow as possible. Any and all feedback is appreciated! :)
 
This is based off @vashworth's guide.

Question for reviewers: What do you think of the doc structure? Should we rearrange things to make it clearer that some sections are to be followed when things go wrong? Or is the current structure clear enough?

Preview URLs:

  1. Swift Package Manager for app developers
  2. Swift Package Manager for plugin authors

Part of flutter/flutter#126005

Presubmit checklist

  • This PR is marked as draft with an explanation if not meant to land until a future stable release.
  • This PR doesn’t contain automatically generated corrections (Grammarly or similar).
  • This PR follows the Google Developer Documentation Style Guidelines — for example, it doesn’t use i.e. or e.g., and it avoids I and we (first person).
  • This PR uses semantic line breaks of 80 characters or fewer.

@flutter-website-bot
Copy link
Collaborator

flutter-website-bot commented Jun 28, 2024

Visit the preview URL for this PR (updated for commit 32a0c1c):

https://flutter-docs-prod--pr10827-spm-compatibility-ilxd3b00.web.app

@sfshaza2 sfshaza2 self-assigned this Jun 29, 2024
Package Manager yet.
:::

## How to disable Swift Package Manager
Copy link
Member Author

@loic-sharma loic-sharma Jun 29, 2024

Choose a reason for hiding this comment

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

Ideally app developers enable SwiftPM and never disable it.

However, plugin developers need to enable/disable SwiftPM to test their plugin works with both package managers.


[flutter#146957]: https://github.com/flutter/flutter/issues/146957

## How to add Swift Package Manager integration to a project manually
Copy link
Member Author

@loic-sharma loic-sharma Jun 29, 2024

Choose a reason for hiding this comment

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

Our hope is that the automatic migration will migrate most projects. Most users shouldn't need to follow these steps.

However, users might have modified their project in a way that breaks out automatic migration. Ideally these users would let us know about these modifications so that we can improve our automatic migration.

Question for reviewers: Is it clear that most people can skip these steps?

Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Remove manually. If the reader is doing something, then it's manual by definition.

Suggested change
## How to add Swift Package Manager integration to a project manually
## How to add Swift Package Manager integration to a project

Copy link
Member Author

@loic-sharma loic-sharma Jul 16, 2024

Choose a reason for hiding this comment

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

I removed manually from the section header but clarified the section intro to clarify these steps are only necessary if the automatic migration fails.

Edit: After feedback from Seth, I restructured the page and re-added the manually qualifier. See: #10827 (comment)

{% endtab %}
{% endtabs %}

## How to use a Swift Package Manager Flutter plugin that requires a higher OS version
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a new kind of error that users can hit when using SwiftPM.

image:"development/packages-and-plugins/swift-package-manager/minimum-deployments.png",
caption:"The target's Minimum Deployments setting" %}

## How to add Swift Package Manager integration to a custom target
Copy link
Member Author

@loic-sharma loic-sharma Jun 29, 2024

Choose a reason for hiding this comment

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

This is for less common scenarios where users have heavily modified their project. Most users won't need these steps. Please let me know if there's a better way to call out this special case without making the "manual migration" docs overly convoluted.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe "to a custom Xcode target" and then explain what that means in the first sentence?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added!


In Step 2, list item 6 use your custom target instead of the Flutter target.

## How to remove Swift Package Manager integration
Copy link
Member Author

@loic-sharma loic-sharma Jun 29, 2024

Choose a reason for hiding this comment

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

In theory no one needs to do these steps unless there's a horrible bug in our SwiftPM integration. If you want to use CocoaPods to download native dependencies, you can disable the SwiftPM feature (the SwiftPM integration will still be there but it won't add any native dependencies to your project).

It is currently only available on the [`master` channel][].
Flutter will continue to support CocoaPods until further notice.

Swift Package Manager adoption will be gradual.
Copy link
Contributor

Choose a reason for hiding this comment

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

if we don't know how the qualify this, not sure we need to say this. I get the sense we want to migrate the ecosystem faster than slower (but, not recklessly)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah did you read this as: "Feel free to take your time, no rush on this migration"?

The intent behind this sentence was slightly different: plugin authors should not make plugins that only support SwiftPM. This would break users that haven't updated their projects yet. Plugin should support both CocoaPods and SwiftPM until further notice.

I'll rephrase to make this clearer :)

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 tweaked this intro, let me know if it's clearer now.

Swift Package Manager adoption will be gradual.

Flutter recommends that Flutter plugins support _both_ Swift Package Manager
and CocoaPods until further notice.
Copy link
Contributor

Choose a reason for hiding this comment

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

if that's not easy to do, should we link to guidance for how to support both?

Copy link
Member Author

Choose a reason for hiding this comment

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

This guidance does make your plugin support both package managers. I'll add a blurb to clarify this.

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 tweaked this intro, let me know if it's clearer now.

@atsansone atsansone added the review.copy Awaiting Copy Review label Jul 1, 2024
@loic-sharma loic-sharma marked this pull request as ready for review July 1, 2024 17:11
Copy link
Contributor

@sfshaza2 sfshaza2 left a comment

Choose a reason for hiding this comment

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

Hi, @loic-sharma! Thanks so much for this PR. I have reviewed a chunk of it, but some pages have the same text (and therefore require the same edits). Let me know when you are ready for me to take another look.

Comment on lines 24 to 27
:::note
Flutter will fallback to CocoaPods for dependencies that do not support Swift
Package Manager yet.
:::
Copy link
Contributor

@sfshaza2 sfshaza2 Jul 1, 2024

Choose a reason for hiding this comment

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

Suggested change
:::note
Flutter will fallback to CocoaPods for dependencies that do not support Swift
Package Manager yet.
:::
:::secondary Plugin authors
A Flutter app can have a dependencies from both CocoaPods and
SwiftPM at the same time. However, mixing dependencies from both
package managers can cause issues so, ideally, all iOS plugin authors
add SwiftPM support ASAP.
:::

Copy link
Member Author

Choose a reason for hiding this comment

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

This isn't quite right. A Flutter app can have a dependencies from both CocoaPods and SwiftPM at the same time. However, mixing dependencies from both package managers can cause issues so ideally everyone adds SwiftPM support ASAP.

Copy link
Member Author

@loic-sharma loic-sharma Jul 3, 2024

Choose a reason for hiding this comment

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

Additional context: an app could have a dependency that only supports SwiftPM and another dependency that only supports CocoaPods. We have to use both package managers in this scenario.

Copy link
Contributor

Choose a reason for hiding this comment

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

I defer to you on the wording...

Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

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

Thank you so much for tackling this!

Comment on lines +508 to +509
- title: For app developers
permalink: /packages-and-plugins/swift-package-manager/for-app-developers
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure app developers would think to go into Packages & plugins
Maybe this should move into Platform integration? Though it would make sense under iOS and macOS, and we don't have a shared category. Whatever you and the tech writers think works best.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, good idea!

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry for the slow response, I'd like to test if I can link to this page twice: once from the packages & plugin section and once from the platform integration section. Will loop back soon!

@@ -0,0 +1,84 @@
Once you [turn on Swift Package Manager][] support, the Flutter CLI tries to
migrate your project to add Swift Package Manager integration.
This makes your project download the Swift packages that your Flutter
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe a bit more clear to say "the Flutter tooling downloads the Swift packages" ?

Copy link
Member Author

@loic-sharma loic-sharma Jul 15, 2024

Choose a reason for hiding this comment

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

I agree this sentence is a little opaque. I was hoping to hand-wavy explain why your project needs to be migrated without going too deep in the weeds. I'll see if I can add a little more detail here.


Swift packages are downloaded by Xcode, not the Flutter tool.

The process is roughly:

  1. The Flutter tool downloads pub packages
  2. The Flutter tool generates a Swift package that depends on each iOS/macOS plugin
  3. Xcode's build step resolves packages. This starts with the generated Swift package, and then downloads each iOS/macOS plugin's dependencies.

The "Swift Package Manager integration" is your project's dependency on the Swift package that is generated by step 2. The Flutter tool migrates your Xcode project to add this dependency.

This makes your project download the Swift packages that your Flutter
plugins depend on.

However, the Flutter CLI might be unable to migrate your project if you've
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we mean "even if you've modified it significantly" ?

Note: "even" here?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can migrate projects unless they've received heavy modifications.

We match do "match and replace" in your Xcode project to migrate it. This should work fine if your project is based off Flutter's templates. However, our matching logic can break if you've modified your Xcode project. The bigger your modifications, the more likely our matching logic breaks.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess I'm wondering if we need the "significantly" qualifier?

ideas:

"The Flutter CLI attempts to migrate your project to Swift Package Manager, even if you have made changes to . If the Flutter CLI tool is unable to migrate your project (for example, if there are unexpected modifications to Foo or Bar), then the Flutter CLI tool will ."

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah gotcha, I dropped the "significantly" qualifier and switched to wording similar to what you suggested.

Copy link
Contributor

@atsansone atsansone left a comment

Choose a reason for hiding this comment

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

@loic-sharma : I suggested changes to one file. Review and accept/decline and apply those you accept to the other pages. Thanks!

Comment on lines 7 to 11
Flutter is migrating to [Swift Package Manager][] to manage iOS and macOS native
dependencies.
This is an experimental feature that might change in the future.
It is currently only available on the [`main` channel][].
Flutter will continue to support CocoaPods until further notice.
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: Condition, then instruction per GSG.
Keep the documentation timeless per GSG.

Suggested change
Flutter is migrating to [Swift Package Manager][] to manage iOS and macOS native
dependencies.
This is an experimental feature that might change in the future.
It is currently only available on the [`main` channel][].
Flutter will continue to support CocoaPods until further notice.
To manage iOS and macOS native dependencies,
Flutter is migrating to [Swift Package Manager][] .
Flutter's support of SPM as described in this guide is under development.
The implementation might change in the future.
SPM support can be found on the [`main` channel][] only.
Flutter continues to support CocoaPods.

Copy link
Member Author

Choose a reason for hiding this comment

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

Normally I agree that "condition, then instruction" is better, but I think it makes the first sentence choppy. I personally prefer the original first sentence. How strongly do you feel about this?

I updated the remaining sentences!

macOS.

If you find a bug in Flutter's Swift Package Manager support,
please [open an issue][].
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: Remove please per GSG.

Suggested change
please [open an issue][].
[open an issue][].

Copy link
Member Author

Choose a reason for hiding this comment

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

This feels curt to me, but updated :(


[flutter#146957]: https://github.com/flutter/flutter/issues/146957

## How to add Swift Package Manager integration to a project manually
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Remove manually. If the reader is doing something, then it's manual by definition.

Suggested change
## How to add Swift Package Manager integration to a project manually
## How to add Swift Package Manager integration to a project

Comment on lines 16 to 21
1. **Access to the Swift package ecosystem**.
Flutter plugins can use the growing ecosystem of [Swift packages][]!
2. **Simplifies Flutter installation**.
Swift Package Manager is bundled with Xcode.
In the future, you won’t need to install Ruby and CocoaPods to target iOS or
macOS.
Copy link
Contributor

Choose a reason for hiding this comment

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

issue:

  • Use parallel structure in your list sentences.
  • Remove the exclamation point per GSG.
  • Keep the documentation timeless.
  • Use present tense.
Suggested change
1. **Access to the Swift package ecosystem**.
Flutter plugins can use the growing ecosystem of [Swift packages][]!
2. **Simplifies Flutter installation**.
Swift Package Manager is bundled with Xcode.
In the future, you won’t need to install Ruby and CocoaPods to target iOS or
macOS.
1. **Provides access to the Swift package ecosystem**.
Flutter plugins can use the growing ecosystem of [Swift packages][]!
1. **Simplifies Flutter installation**.
Xcode includes Swift Package Manager.
Targeting iOS or macOS doesn't require Ruby and CocoaPods.

Copy link
Member Author

Choose a reason for hiding this comment

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

This sounds good but I tweaked the last sentence:

- Targeting iOS or macOS doesn't require Ruby and CocoaPods.
+ You don't need to install Ruby and CocoaPods if your project uses
+ Swift Package Manager.

Let me know what you think!

Plugins that don't support CocoaPods won't be usable by projects that haven't
migrated to Swift Package Manager yet.
Plugins that don't support Swift Package Manager can cause problems for projects
that have migrated.
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be nice to explicitly say here that we expect to remove support for CocoaPods at some point in the future, so adding SPM support will future-proof plugins. That will make it more clear why a plugin author should do this work.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed.

@atsansone What would be the best way to state this while following the timeless GSG?

Flutter expects to remove support for CocoaPods. Adding Swift Package Manager support future-proofs your plugins.

I think this would be a valuable sentence to add, but it goes against the GSG guidance.

Comment on lines +508 to +509
- title: For app developers
permalink: /packages-and-plugins/swift-package-manager/for-app-developers
Copy link
Contributor

Choose a reason for hiding this comment

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

oh, good idea!

This makes your project download the Swift packages that your Flutter
plugins depend on.

However, the Flutter CLI might be unable to migrate your project if you've
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess I'm wondering if we need the "significantly" qualifier?

ideas:

"The Flutter CLI attempts to migrate your project to Swift Package Manager, even if you have made changes to . If the Flutter CLI tool is unable to migrate your project (for example, if there are unexpected modifications to Foo or Bar), then the Flutter CLI tool will ."


{% include docs/swift-package-manager/how-to-enable-disable.md %}

## How to add Flutter to an existing app (add-to-app)
Copy link
Contributor

Choose a reason for hiding this comment

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

this was a surprising header in this file, and it was surprising to see this first before "how to add SPM to a project".

Consider:

  • How to add SPM to a full Flutter app
  • How to migrate to SPM for a Flutter add-to-app scenario

Not yet supported, follow this bug, etc...

In this way, the headers rhyme and are clear about their scenarios. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is excellent feedback. The guide was misleading: hopefully no one needs to do the manual steps. I restructured the page and added a guide dedicated to the auto migration. I also renamed these headers to align better. See: #10827 (comment)

Copy link
Contributor

@johnpryan johnpryan left a comment

Choose a reason for hiding this comment

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

LGTM - i was able to get the pedometer sample up and running with these instructions.

@loic-sharma
Copy link
Member Author

loic-sharma commented Jul 16, 2024

@sfshaza2 @atsansone @sethladd Hey there, I re-structured the "For app developers page":

Screenshot 2024-07-16 at 1 09 20 PM

Summary of changes:

  1. I added a new How to add Swift Package Manager Integration section. I moved other existing guides to this section (the add-to-app guide, and the manual process guide)
  2. I created a new guide How to add Swift Package Manager Integration > Add to a Flutter app. This section is entirely new content that covers the automatic migration to add SPM integration to a Flutter app.

This was in response to Seth's comment here: #10827 (comment)

Please let me know what you think!

Copy link
Contributor

@sethladd sethladd left a comment

Choose a reason for hiding this comment

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

lgtm - thank you!

@sfshaza2
Copy link
Contributor

@loic-sharma, thanks for all of these updates and hanging in there! I'm going to land this. If there are further tweaks, they can be handled in another PR.

@sfshaza2 sfshaza2 merged commit e762902 into flutter:main Jul 16, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants