Closed mickael-menu-mantano closed 3 years ago
It might still be too early unfortunately... There's still no support for packaging resources, but a proposal is under discussion.
Readium relies on resources, for example localized strings in LCP and the navigator, and scripts in the navigator.
Looks like resources in SPM are finally supported in Swift 5.3:
We might be able to deprecate CocoaPods and Carthage 🕺
@mickael-menu I've been patiently awaiting resource bundle equivalents in SPM. This is great news.
Any progress on support for SPM? 🤞
@Truck3r Nope, personally I didn't have time to start with SPM. If you would like to help, I think we need to tackle these things:
Package.swift
for each R2 module.@mickael-menu I'd love to work on this, but being on a tight schedule I don't think I'll be able to put much time into it until Q3 this year.
I went through the Cartfiles in all of the Swift modules and the results are below. Everything that is checked has a Package.swift
file and supports iOS 10.0+, and the link goes directly to said Package.swift file.
There are two packages that are not SPM ready: edrlab/GCDWebServer and dexman/Minizip. For the latter, https://github.com/marmelroy/Zip might be a good option as it's also built on top of minizip
@stevenzeck Outstanding, thanks!
GCDWebServer
is already a fork under the EDRLab umbrella so we could make it SPM ready. There is this PR to get rid of the HTTP server but it requires iOS 11+. However, we could let apps needing to support iOS 10 manage the HTTP server themselves.
For marmelroy/Zip, that's a good lead. It doesn't expose the advanced functions we need in its Swift API, but if we can access the bundled minizip, we could reuse our own MinizipArchive
.
There is also the private R2LCPClient.framework
, but it's non-blocking for R2 modules since r2-lcp-swift
doesn't depend on it anymore.
The original GCDWebServer
repo is currently working on SPM.
I added marmelroy/Zip as a Swift package in place of dexman/Minizip, it worked without having to change a thing.
That just leaves edrlab/GCDWebServer. As @mickael-menu mentioned there is a PR in the original repository to support SPM that could be used. Another option is replacing it with something like https://github.com/apple/swift-nio.
I added marmelroy/Zip as a Swift package in place of dexman/Minizip, it worked without having to change a thing.
Nice, great news!
That just leaves edrlab/GCDWebServer. As @mickael-menu mentioned there is a PR in the original repository to support SPM that could be used. Another option is replacing it with something like https://github.com/apple/swift-nio.
The GCDWebServer PR is small enough to be worth backporting into our fork to settle this quickly. Although down the line I think it would be interesting to replace it with swift-nio for iOS 10, since it's maintained by Apple AND written in Swift (GCDWebServer uses Objective-C).
Yeah I think this is going to take a lot of trial and error. A "typical" Swift package doesn't have an workspace or proj at all, it relies completely on the Package.swift to know what it depends on. But in order to continue supporting Carthage and Cocoapods, I believe they require one or both of those.
Ultimately in the end, we want a standalone testapp that can add the individual modules as Swift packages rather than relying on Carthage or gitmodules (other than for development).
.framework
references out of Frameworks and Libraries and replace with each one's corresponding Swift package. I had tried this and had no issues whatsoeverfile:///..path..to...submodule...with....swiftpackage
.I would be in favor of switching from Carthage to SPM, as we get recurring issues with it.
I also noticed a few popular projects (like GRDB) dropped Carthage in favor of SPM because of issues integrating both.
So far I think SPM is a fine alternative to Carthage, but we will probably still need CocoaPods support because I believe it is used with React native and Flutter.
If we don't, then we can consider removing the need for a xcodeproj for the submodules and making them "true" Swift packages. But I don't know how to integrate them that way for development purposes.
You should be able to drag and drop the whole submodule folder in your xcworkspace to integrate it without a xcodeproj. But I think we might still need an xcodeproj for CocoaPods, not 100% sure.
I think CocoaPods doesn't require an Xcode project since it generates a global one containing the sources declared in the Podspec.
From there, could we have something like this?
Cartfile
and Xcode project as-is and declare the .xcodeproj
file as Carthage-related only.Package.swift
in each module, which should (?) ignore the Xcode project by default, as CocoaPods do.From there, people could install the modules with SPM while still being able to integrate with Carthage since the dependencies declared in the xcodeproj will be the ones from the Cartfile
.
The end goal should still be to deprecate Carthage, but leave some time for integrators to migrate and identify any issues with SPM.
I just tried with GEOSwift which has everything, and drag and dropping the repo folder ignores the Xcodeproj 👍
Our GCDWebServer fork is now SPM-ready with the new 3.7.0 release.
SPM support is merged in all modules, under the develop
branch. It will be part of the upcoming 2.1 release.
We still miss a sample integration in the test app (see https://github.com/readium/swift-toolkit/issues/188), but it's pretty straightforward. Just add the Swift Packages in Xcode using our Git repo URLs.
Thanks again to @stevenzeck who did an amazing job at clearing the path!
Xcode 11 finally brought native support for SPM, including iOS!
As the official package manager for iOS development, this should be the default choice used in Readium projects.
I think this could also simplify the build settings of the test app, that are right now split between Carthage and submodules. We could maybe use only SPM, setup either with a direct path to the submodules or with the URLs to the Git repositories.