Tech News
← Back to articles

Automatically Packaging a Haskell Library as a Swift Binary XCFramework

read original related products more articles

Announcing xcframework or: the happy path for wiring a Haskell dependency to your Swift app

I’ve written about Haskell x Swift interoperability before. Calling Haskell from Swift is about marshalling and the foreign function interface. But Creating a macOS app with Haskell and Swift tells the much messier tale of hijacking XCode to vodoo together the Haskell library, its headers, and two handfuls of other magic ingredients into one buildable SwiftUI application.

Stop! Don’t click on the last link. No, it turns out that my XCode sallies strayed very far from the yellow brick road. The IDE is confused. Recompilation bugs abound. Complexity is through the roof juggling .modulemap s, .xcconfig dynamic settings, and sketchy .sh scripts.

Let’s walk the happy path.

1 Announcing: xcframework

Perhaps obvious in retrospect, the demon-less way to add a Haskell library to the dependencies of a Swift application is to build an independent Swift Package wrapping the Haskell library – something that can be done without XCode in sight. Easy peasy:

Build the Haskell library using Cabal Create a Swift package from the Haskell artifacts Add the Swift package as a dependency to the project

And it turns out that (1) and (2) can be merged together using Cabal SetupHooks!

Moreover, I’m happy to announce I’ve neatly packaged and released that build process automation as a Haskell library called xcframework on Hackage.

Onwards! – for what it does and how to use it.

... continue reading