Swift ABI Stability

ABI Stability

What is ABI?

At runtime, Swift program binaries interact with other libraries and components through an ABI. ABI stands for Application Binary Interface is the specification to which independently compiled library entities must conform to be linked together and executed. These binary entities must be consistent in low-level details like: how to call functions, how their data is represented in memory, and even where their metadata is and how to access it.

What is ABI Stability?

ABI stability means locking down the ABI to the point that future compiler versions can produce binaries conforming to the stable ABI. Once an ABI is stable, it tends to persist for the rest of the platform’s lifetime due to ever-increasing mutual dependencies.

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
Swift versions incompatibility

There were no embedded libraries so the app sizes got inflated by all the libraries, as whenever application was built, a Swift dynamic library got embedded into 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 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.

Also, since Swift libraries will not have to be embedded into the app, app bundle size will decrease which will lead to less memory consumption. Lowering overall app size is also an advantage for users since they now need to use fewer resources to download the app from the App Store.  

ABI Stability biggest advantages:

  • Reduced Bundle size

There is no longer need to include the Swift standard library in Framework folder as the stable Swift runtime is incorporated within the OS.

  • Source compatibility

No more cumbersome migrations – newer compilers can compile code written in an older version of Swift.

  • 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

Useful links:

https://github.com/apple/swift/blob/master/docs/ABIStabilityManifesto.md

https://swift.org/blog/abi-stability-and-more/

https://www.raywenderlich.com/1301449-what-s-new-in-swift-5-abi-stability

5 (100%) 2 vote[s]