如何预构建库以与未来 swift 版本兼容

How to prebuilt libraries to be compatible with future swift versions

我们正在为我们的一些项目预构建一些库(主要是 carthage)以减少开发时间。这些库不经常更新,但我们希望快速更新我们的 XCode 版本。

现在每次 XCode 带来新的 swift 版本时,我们都会看到这个不兼容问题

File.swift:4:8: error: module compiled with Swift 5.3.2 cannot be imported by the Swift 5.4 compiler: /......./Debug-iphoneos/Alamofire.framework/Modules/Alamofire.swiftmodule/arm64-apple-ios.swiftmodule

如何以 swift 更新不会影响它的方式预先构建我的依赖项,并且我不必在每次 xcode 更新时重新构建依赖项 (我以为这就是 ABI 稳定性的目的?我该如何激活它?)

听起来您误解了 ABI 稳定性的含义。主要的好处是它允许 OS 只包含一个版本的 Swift 标准库,并且所有 Swift 二进制文件都可以共享它。你想要的是“模块稳定性”。来自 docs 关于 ABI 稳定性的文章:

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.

Swift 的任何版本尚不支持此功能。