apache / cordova-ios

Apache Cordova iOS
https://cordova.apache.org/
Apache License 2.0
2.16k stars 989 forks source link

Add Swift Package Manager Support for iOS Plugins #1089

Open msmtamburro opened 3 years ago

msmtamburro commented 3 years ago

Feature Request

With recent versions of Xcode, including frameworks became problematic due to the introduction of the M1 Mac and the inclusion of certain simulator architectures within frameworks. To address this, framework consumers use Lipo to strip architectures, or (better) framework providers moved to XCFramework. Other framework providers jumped directly to offering their projects as Swift Packages to overcome this challenge. It would be nice to add a way for plugins to specify Swift Package Manager dependencies, just like they currently can specify frameworks.

Motivation Behind Feature

There are complicated or manually intensive ways to add Swift Packages to a Cordova project, so it would make sense to add real support, as this does appear the direction things are going.

https://swift.org/package-manager/ https://developer.apple.com/documentation/xcode/adding_package_dependencies_to_your_app

Feature Description

Plugins would be able to add a line something like this:

<package src="https://github.com/ReactiveX/RxSwift.git" branch="optional" version="6.0.0" revision="3920840923809482309482039"/>

Alternatives or Workarounds

You could write a hook that calls something on the command line to add this, or (worse) manually add the package each time through Xcode.

jpike88 commented 3 years ago

Cocoapods needs to be a thing of the past, downloading of the cocopaods repo step is pure lunacy and anything that improves on that is massive step forward.

j3k0 commented 1 year ago

@msmtamburro - I'm stuck with a project where I need to use an SDK distributed only with SPM. What would be the "complicated way" to install this SDK until proper support is added to Cordova?

msmtamburro commented 1 year ago

@j3k0 one approach would be to look at the Package.swift file, which is human readable, and then write yourself a similar plugin.xml.

j3k0 commented 1 year ago

Thanks, for later reference, the SDK being open source I included all source files and assets and packaged them with the plugin.xml as suggested. This solution works but does require some effort. Everything isn't possible with plugin.xml like bundling assets, which I had to do manually.

dpogue commented 1 year ago

I think we're definitely interested in Cordova-iOS and Cordova plugins supporting a way to add dependencies using Swift Package Manager.

Probably, we'd want dependencies declared in plugin.xml similar to how Android declares Gradle package dependencies:

<framework src="com.google.firebase:firebase-core:$FCM_VERSION" />

Swift packages are handled as git URLs with references to branches or tags, so we'd either need to take a complete package spec URL or a package URL and a version spec.

There are a few pre-requisites to this work:

  1. We probably need the flexibility provided by https://github.com/apache/cordova-common/pull/181 to more easily support parsing the dependency declarations from plugin.xml
  2. We're going to need to add the necessary support to https://github.com/apache/cordova-node-xcode to understand how to add the Swift Package references to the Xcode project and associate them with targets
  3. We're going to need to add code here to cordova-ios to glue all those pieces together
agoncalvesos commented 7 months ago

Hi team! Is this going to happen? Thanks!

jcesarmobile commented 6 months ago

A simpler alternative to point 2 could be to create a local SPM package as local dependency to the default iOS template and add it by default so no Xcode project modification is needed. Then make the Cordova CLI modify that local package's Package.swift file to add the plugins dependencies there.