Bundling C Library in Swift Framework
Article Summary
Lem from Bumble's engineering team tackles a tricky iOS challenge: how do you bundle legacy C libraries into modern Swift frameworks without breaking portability? The common approaches fail when you need to ship via Carthage or CocoaPods.
When Swift launched in 2014, it created new headaches for developers wanting to use C libraries. This deep dive walks through bundling giflib (a C library) into a Swift framework using explicit module maps, a technique that keeps frameworks portable across machines and distribution channels.
Key Takeaways
- Standard module maps break portability: frameworks bind to local file paths
- Explicit modules act like private headers, imported only when needed
- Custom modulemap files override Xcode defaults for clean C library encapsulation
- Result: pure Swift interface with hidden C implementation details
Critical Insight
Explicit module maps solve the C library portability problem, letting you ship Swift frameworks with embedded C code that works across Carthage, CocoaPods, and binary distribution.