What is ABI Stability in Swift 5?
As we already know that Swift is fast emerging programming language. Those who are working on Swift have witness the growth.
It’s been a chronic goal to stabilize Swift’s ABI on macOS, iOS, watchOS, and tvOS. The eventual benefit to the Swift ecosystem to enable binary compatibility for apps and libraries, as long as stable ABI is an important milestone for the maturity of any language.
So, What does this actually mean though? Let’s discuss.
What it mean by ABI?
When we want to use already compiled binaries in our current code, at runtime our current compiled binaries interacts with already compiled binaries using ABI (Application Binary Interface).
ABI defines so many low level details for compiled binaries like function signature to call it, how and where metadata can be access and data representation in memory.
What it mean by ABI Stability?
Before Swift 5, Swift was not ABI Stable. So, each compiled binary (App) bundles its own Swift Dynamic Library (can check by open any ipa file, will find swift standard libraries (.dylib) in SwiftSupport or Frameworks).
Without stable ABI, the OS would need to include a copy of every library compiled with every version of swift because of this stable ABI is most important milestone for Swift.
As shown, with each compiled version we are having ABI also. So, before Swift 5 when we get new version and we try to update our existing application code to new version most the things broken.
It means, ABI doesn’t live on the iOS operating system, lives with in each app.
Now after Swift 5, Swift Dynamic Library will be embedded in iOS operating system and ABI will be compiled with each version on swift.
As show, Now onwards ABI will be embedded with iOS and each upcoming version will be able to access the all old compiled binaries, and it’s ABI will be compatible with each version of Swift.
It provides binary compatibility for apps: a guarantee that going forward, an app built with one version of the Swift compiler will be able to talk to a library built with another version.
Why ABI Stability matter?
So, there are some benefits with stable ABI.
- Version Compatibility: The app built in one version of swift compiler will adopt the library or apps built in other versions of swift.
- Reduce bundle size: Now, we don’t need to include swift standard library in framework folder for each version. so it will automatically reduce bundle size.
- Less frequent language changes: Less changes leads to less efforts in migration.
📣 Note: all version numbers past Swift 5.0 in this post are hypothetical, of course
👩💻 !!! HAPPY CODING !!! 👨💻
Thank you for reading, please hit the recommend icon if like this collection 😊 . Questions? Leave them in the comment.