Swift Package Manager builds iOS frameworks(Updated.
2 Beta)Artem LoenkoBlockedUnblockFollowFollowingFeb 25Swift Package Manager doesn’t work with iOS.
That’s probably all you can say about the current state of SPM, but insomnia forced me to expand on the issue and compile the following essay.
TL;DRYes, you can build iOS frameworks with Swift Package Manager;Yes, you can adjust settings via .
xcconfig and reuse generated .
xcodeproj in a real iOS application without 3rd party tools to parse a project structure, scripts on Ruby, etc.
;Yes, you can use swift build to build your package but only as a library (but with some additional limitations);No, you cannot use swift test because you have to spawn a simulator to run them.
Current State of Swift Package ManageriOS support is a hot topic in the Swift Package Manager community, and from time to time someone raises this same question again but the following comments sum up the community’s reactions (full thread on forums.
org):@Rick BallardI think that this will be best provided by native IDE integration.
However, in the meantime, I’d welcome contributions to help improve Xcode’s project generation support.
@Adrian KashivskyyThe last thing I want from a platform-agnostic open-source package manager is built-in integration with a single-platform commercial closed-source IDE.
:confused: I think this should be done independently by the DT team, without any special favouritism by SPM.
And you know what?.I agree with these statements.
Especially after some research.
In general, SPM is a very ‘young’ and inflexible project.
There are a lot of limitations, especially around generate-xcodeproj options of the swift package tool.
And this is understandable given that Swift is a language, and all related tools need to be platform-agnostic as far as possible.
Yeah, iOS is the biggest Swift consumer, and Apple contributes to Swift mostly because of iOS, but…It’s going to be almost impossible to grow Swift into a mature technology if you’re limited and restricted by Xcode / iOS specific things / etc.
And, it seems, this is the primary goal for Swift to remain just be a language.
The fate of Objective C is a good example of why the Apple and Swift’s communities are trying to be agnostic.
They are trying to build something big, and lack of iOS support is the price (among many others) at the moment.
:kiss:Having said this, we have exciting news about SPM and iOS friendship.
SE-0236: Package Manager Platform Deployment Settings is accepted with some modifications.
And the implementation of this proposal will help a lot to move forward in the case of iOS.
The main goal is clear and straightforward:Packages should be able to declare the minimum required platform deployment target version.
SwiftPM currently uses a hardcoded value for the macOS deployment target.
This creates friction for packages which want to use APIs that were introduced after the hardcoded deployment target version.
Why will it completely fail to solve the problem with iOS?.Just read the “This option doesn’t resolve these problems” section.
2 BetaSE-0236 was accepted and implemented in Swift 5, and Apple shipped it with the latest Xcode 10.
This means that you can specify an iOS as a deployment target for your packages with a simple line in your Package.
swift file:See an example in xcode_10_2_beta branch in the example repository.
It is still a beta implementation, and you will have a lot of issues with build command, and run doesn’t work either, but it is a step toward eventual iOS support.
I hope that Apple will announce something good at WWDC’19.
A new IDE for Swift, perhaps?.Or open-sourced xcodebuild?.Or xcodebuild replacement based on llbuild?.We’ll see.
The current state is as complicated as it can be.
We are trying to inject open-sourced platform-agnostic tools into a legacy (?) world of Xcode, and this problem can only be solved in one of two ways: either iOS specific build tools go open source, or Xcode team supports Swift infrastructure.
Is it possible to build an iOS framework with SPM?.Yes!.Absolutely!Search for solutions for building iOS frameworks with SPM on DuckDuckGo and you will find some instructions (1, 2).
But all of them have this one step that I hate: sudo gem install xcodeproj :disgusting:.
Can we do any better?.Let’s give it a try.
First of all, let’s generate a template:Now we have to convince SPM that we want an iOS project when it generates xcodeproj.
How?.With xcconfig, of course.
Create a file ios.
xcconfig and add it to .
For example, let’s start with a basic version:Looks good.
Let’s see what SPM thinks of it:Didn’t know about xcconfig-overrides?.Me neither.
It’s a hidden and undocumented feature (commit), thanks to @Daniel Dunbar!.Time to ask Xcode what it thinks of it.
Note: You do not have to specify a custom .
xcconfig file if you are using Xcode 10.
2 Beta with Swift 5 Toolchain.
Check the branch for more details.
It works!. More details