Skip to content

feat(cli): support SPM package traits in generated Package.swift#8351

Draft
robingenz wants to merge 5 commits intoionic-team:mainfrom
robingenz:feat/spm-package-traits
Draft

feat(cli): support SPM package traits in generated Package.swift#8351
robingenz wants to merge 5 commits intoionic-team:mainfrom
robingenz:feat/spm-package-traits

Conversation

@robingenz
Copy link
Contributor

@robingenz robingenz commented Feb 19, 2026

Summary

  • Add ios.spm.packageTraits config option to pass package traits to SPM plugin dependencies
  • Use swift-tools-version: 6.1 when traits are configured, otherwise keep 5.9
  • Append traits: [...] to .package() dependency lines for plugins with configured traits

Close #8335

@OS-pedrogustavobilro
Copy link
Contributor

OS-pedrogustavobilro commented Feb 23, 2026

Hey @robingenz thanks for the PR, tested here and it's working pretty well. I did a few minor changes, most notably to allow to set the .defaults attribute (was being written in quotes).

I'll ask for an additional review of the team as well. For reference - Tested with https://github.com/OS-pedrogustavobilro/test-capacitor-pr8351-spm-traits

@OS-pedrogustavobilro OS-pedrogustavobilro requested a review from a team February 23, 2026 12:40
@robingenz
Copy link
Contributor Author

@OS-pedrogustavobilro Thank you so much! We are really looking forward to the release as we have 2-3 plugins that are just waiting for it. Let me know if I can help in any way.

@jcesarmobile
Copy link
Member

Since the feature requires swift-tools-version: 6.1, even if that version will only be used if traits are present, I would prefer not merging this until Capacitor uses Swift 6.

My understanding is that having swift-tools-version: 6.1 in the Package.swift has implications for the dependencies being fetched and could cause issues if some of the dependencies have xcframeworks built with previous versions

@robingenz
Copy link
Contributor Author

@jcesarmobile Good point—I totally understand the concern. Is there a timeline for Swift 6 support in Capacitor?

The reason this feature is somewhat time-sensitive is that while it was supported in CocoaPods, SPM is now the default package manager. This has created restrictions for our plugin users who have transitioned to SPM.

To mitigate the risk, I have two suggestions:

  1. Log a warning when traits are configured and the tools version is bumped to 6.1, so users are aware of potential compatibility issues with certain dependencies.
  2. Add a separate ios.spm.swiftToolsVersion config option instead of auto-bumping, so users have to explicitly opt in. Traits would only kick in when this is set to 6.1 or higher.

Let me know what you think!

@OS-pedrogustavobilro
Copy link
Contributor

OS-pedrogustavobilro commented Mar 3, 2026

Hey @robingenz, getting back to you on your points. They're both reasonable, but we feel they might not be enough so we went a step further.

We're planning on going with essentially an "extension" of the second option you provided: adding an experimental setting for swift-tools-version in this PR.

Users will need to set that config explicitly to be able to use the package traits feature from this PR, which we will be also place under the experimental object.

Unfortunately we can't yet provide a timeline for when Capacitor will support Swift 6, but I think I can say it won't be Capacitor 8, only in a future major. As such, we think placing these settings in an experimental block is a fair compromise between having this functionality available in the near future, while also making sure users are aware of the change their making in their apps, that can cause issues.

We hope this doesn't entirely dissuade users of your plugin to not use the feature, as I think as long they properly test their apps after making this change and find everything is still working, they should be alright.

The other PR is still going to be reviewed, but if/when it's merged, we will also be doing a few updates in this PR, particularly to mark the config option as experimental.

Feel free to share your feedback on this option, thank you!

@robingenz
Copy link
Contributor Author

Hey @OS-pedrogustavobilro, thank you! That looks like a good approach. I do think there will be some developers who will be put off by a setting labeled experimental, but as long as the possibility to use traits exists at all, it would be a good step forward. I really hope Swift 6 makes it into Capacitor 9.

@OS-pedrogustavobilro OS-pedrogustavobilro marked this pull request as draft March 5, 2026 09:39
@OS-pedrogustavobilro
Copy link
Contributor

Temporarily placing this PR in draft until #8372 is merged.

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.

[Feature]: Support SPM package traits for plugin dependencies

3 participants