Bumble lem Dec 12, 2018

Bundling C Library in Swift Framework

Article Summary

lem from Bumble Tech tackles a tricky iOS challenge: how do you bundle legacy C libraries into modern Swift frameworks without breaking portability?

When Swift arrived in 2014, it created new friction for developers wanting to use C libraries. This Bumble Tech article walks through bundling giflib (a C library) into a Swift framework using explicit module maps—a technique that keeps your framework portable across machines and distribution methods like Carthage and CocoaPods.

Key Takeaways

Critical Insight

Explicit module maps solve the portability problem when embedding C libraries in Swift frameworks, keeping implementation details hidden while enabling external distribution.

The article includes a complete working example with giflib that reveals why the common approach fails for external users.

About This Article

Problem

When developers embedded C libraries like giflib into Swift frameworks, they ran into portability problems. Package managers would bind frameworks to local file paths on the developer's machine, making distribution difficult.

Solution

Lem from Bumble Tech created a GifSwift.modulemap file that declared C libraries as submodules within the framework's Build Settings. This explicit module map approach let the framework work across different machines and distribution methods.

Impact

The GifSwift framework could now wrap giflib's C APIs while keeping a pure Swift interface. It worked with Carthage, CocoaPods, and binary formats without running into path dependency issues.