What is ABI & ABI Stability and why does it matter?

Naveen Sharma
4 min readApr 14, 2020

--

Now Swift 5 is ABI stable. Let's learn what does it mean?

Introduction:
Before Swift 5, Swift was not ABI stable, so each binary(App), bundles its own version of the Swift Dynamic Library. ABI does not leave on the iOS operating system.
Now Swift 5 is ABI Stable, which means ABI will be embedded within the iOS Operating System and this ABI will be compatible with every version of Swift.
So from now, Swift will have a smaller footprint on the system.

What is ABI?
-
ABI stands for Application Binary Interface.
- ABI is an interface between two binary program modules; often, one of these modules is a library or operating system facility, and the other is a program that is being run by a user. — Wikipedia
- At runtime, Swift compiled code (App’s binaries or Libraries) interact with other libraries through an ABI. So, ABI defines how compiled code interacts with other compiled code.
- It also defines many low-level details for binary entities like how to call functions, how their data is represented in memory, where metadata is and how to access it.

What is lack of ABI Stability mean?
A lack of ABI Stability means that compiled code would not be able to interact with other compiled code at runtime. Before Swift 5, Swift was not ABI stable, so each binary was bundling its own version of the Swift Dynamic Library. This leads to bigger app sizes, and version incompatibility issues.

Without ABI Stability

What is ABI Stability?
-
When a language is ABI Stable, that means it is packaged and linked with the operating system itself, in our case: iOS. The Swift code we compile on our computer has a binary interface into the operating system itself rather than any dynamic library, we bundle with our application.
- ABI stability means locking down the ABI to the point that future compiler versions can produce binaries conforming to the stable ABI. It enables binary compatibility between applications and libraries compiled with different Swift versions.
- Once an ABI is stable, it tends to persist for the rest of the platform’s lifetime due to ever-increasing mutual dependencies.

With ABI Stability

Why ABI stability is so important for Swift Developers?
Before Swift 5 developers had to be aware of version compatibility issues since previous versions of Swift differed from each other. There were no agreed-upon binaries to communicate with each other. These led to many migration problems. It was necessary to migrate the entire code to the latest Swift version to ensure it would not break.

Swift Versions Incompatibility

There were no embedded libraries so the app sizes got inflated by all the libraries, as whenever the application was built, a Swift dynamic library got embedded into the app bundle to support a specific version of Swift which the app was built in.
With Swift 5 ABI stability was introduced and from then on all following would be packed and linked directly into the operating system. This means that if any changes occur in future Swift versions it will come with the OS on which the developer is working on and gets automatically used by the app when it is running on that OS without the need to recompile and redeliver app.

Why does ABI Stability matter?
- Reduced Bundle size:
The size of our application will decrease because we will no longer have to include the Swift Standard Library in our Frameworks folder which will lead to less memory consumption.
- Source compatibility: Newer compilers can compile code, written in an older version of Swift. This aims to reduce the migration pain that Swift developers face when migrating to a newer Swift version.
- Binary compatibility: An app built with one version of the Swift compiler will be able to talk to a library built with another version.
- Less frequent language changes: Fewer changes lead to fewer efforts in migration.

Useful Links:

https://swift.org/blog/abi-stability-and-more/
https://github.com/apple/swift/blob/master/docs/ABIStabilityManifesto.md
https://spec.fm/podcasts/swift-unwrapped/154699

Thank you for reading! If you liked this article, please clap to get this article seen by more people.
Please follow me on Medium by clicking Follow.
I’m also active on LinkedIn, Twitter and GitHub.

--

--

Naveen Sharma
Naveen Sharma

Written by Naveen Sharma

iOS Developer [Objective-C] [Swift]

Responses (1)