Swift 5 brought us ABI stability, which is a major milestone in helping the language grow beyond Apple’s walled garden. With version 5.1, we have module stability... but what does that mean? More to the point, should you care?
ABI stability allows the Swift Standard Library to be included at runtime within any operating system, including Linux and Windows (eventually). In lay-terms, this means if an app or service is written in Swift, the OS can support it without workarounds.
In late 2018, Swift manager Ted Kremenek said ABI stability was “only one of two pieces needed to support binary frameworks,” adding: “The second half is module stability.” If ABI stability helped operating systems and platforms support Swift, what was module stability’s role?
Module stability is a separate-but-equal component for the overall stability and usability of Swift. It allows a Swift module (which is any source-level code, often realized in other apps as APIs) to be usable across the board. In Apple’s view, you’ll write one main app or service, then make it available across platforms.
Xcode 11 has a new “Build Libraries for Distribution” option under the “Build Options” menu you’ll want to check when creating modules for use elsewhere.
The new Swift Module Interfaces in Xcode 11 has a list of the public APIs used in an app, and is enabled with the “Build Libraries for Distribution” option. This helps Xcode avoid version-locking, so modules can be used when newer versions of Xcode or the Swift compiler are released.
This is a great example of Swift’s evolution. While some major releases of the language were not reverse-compatible, ABI and module stability are examples of the tooling looking forward. With 5.1 and beyond, module stability is usable, and you won’t have to compile with a newer version every time.
In a blog post discussing module stability, developer Donny Wals says: “Now that we have Module Stability and ABI Stability in Swift, the language is likely to change at a slower rate than we’re used to. We should see less radical, source breaking changes and the language should slowly mature into a beautiful, fast and stable language that will be a great basis for your applications for years to come.” This is fair, and hopefully accurate.
Apple has work to do. Swift has undoubtedly reached a level of maturity and stability that make it a great option, and helps avoid reverse-engineering Objective-C tooling and wrapping it up for use in Swift. But it’s still imperfect for those with apps using older versions of Swift. It’s a massive step in the right direction (and hopefully our last big move) but a lot rides on Apple getting things right, too. ABI and module stability are both features that will play vital roles in cross-platform apps and services, as well as SwiftUI, and Apple hasn’t yet hit the mark on any of those fronts (yet).