Swift Compatibility Between Versions for a Library

How to prebuilt libraries to be compatible with future swift versions

It sounds like you're misunderstanding what ABI stability enables. The main benefit is that it allows the OS to include only one version of the Swift standard library, and for all Swift binaries to share it. What you want is "module stability". From the docs on ABI stability:

ABI stability is about mixing versions of Swift at run time. What
about compile time? Right now, Swift uses an opaque archive format
called “swiftmodule” to describe the interface of a library, such as a
framework “MagicKit”, rather than manually-written header files.
However, the “swiftmodule” format is also tied to the current version
of the compiler, which means an app developer can’t import MagicKit if
MagicKit was built with a different version of Swift. That is, the app
developer and the library author have to be using the same version of
the compiler.

To remove this restriction, the library author needs a feature
currently being implemented called module stability. This involves
augmenting the opaque format with a textual summary of a module,
similar to what you see in Xcodeʼs “Generated Interface” view, so that
clients can use a module without having to care what compiler it was
built with.

This is not yet supported in any version of Swift.

Are Swift dynamic libraries backward compatible with older swift version projects

Simply put, the first quoted statement is false (currently).

The Swift ABI (application binary interface) is not finalised. The ABI is the set of conventions for how function calls look, how variables and references are stored in a real machine etc. Until it is finalised, all Swift modules in an application have to be compiled with the same version of Swift.

For more information on the Swift ABI, see the Swift ABI Manifesto.

Is Swift ABI compatible between minor versions?

Update 3

We also have module stability, starting with Xcode 11, with the help of the newly introduced .swiftinterface files. One caveat, though, is that the code will have to be build with the -enable-library-evolution flag. More details here.


Update 2 Module stability is scheduled for Swift 6: https://swift.org/blog/abi-stability-and-more/#module-stability

This is an excerpt from the Swift evolution repo.


Update Swift 5 comes with some ABI stability:

The Swift 5 release will provide ABI stability for the Swift Standard Library.


Unfortunately, not yet. For Swift 4, they state this here: https://swift.org/blog/swift-4-1-release-process/.

Swift 4.1 is not binary compatible with 4.0. It contains a variety of under-the-hood changes that are part of the effort to stabilize the Swift ABI in Swift 5.

Hopefully we'll get ABI stability in Swift 5

Is it possible to use libraries written in an old version of swift in a project with a newer version of swift?

Maybe this reference from Apple answers the question:

unfortunately it would seem to be impossible:

First, Swift 2.3 and Swift 3 are not binary compatible so your app's entire code base needs to pick one version of Swift.

https://developer.apple.com/swift/blog/?id=36

Compilation issue : Incompatibility of Swift versions between two packages

I think that the only solution is to convert code of your Pods from 2.3 to 3.0 and then modify the things that did not changed automatically by xcode.
Maybe you could force your pod version in the podfile with :

pod'~> 3.0.1'

and then re-install the pods with

 pod install

Swift Package Manager compatible with which iOS versions?

Yes.

The Swift Package Manager is included in Xcode 8.0 and all subsequent
releases.

Xcode 8, iOS SDK version is 10.0

Would Swift 5 apps be able to run only on specific iOS versions?

You're on the right track, but the point is that the app would only run on a specific iOS version or later. The whole goal of ABI stability is to allow a Swift binary (i.e. an app) that was compiled with one version of Swift to be able to interoperate with a binary (i.e. a framework) that was compiled with a different version of Swift.

But yes, to make use of ABI stability, your app would only be able to run on iOS 13 (or whatever version it turns out to be), or later.

This is how things work in ObjC (and C and C++ and most languages). I can build my Objective-C app on iOS 10 and expect that it will link with Foundation and UIKit on iOS 11 without trouble. You can't do that with a Swift library today.



Related Topics



Leave a reply



Submit