# Automatically Packaging a Haskell Library as a Swift Binary XCFramework

DevFeed: [Automatically Packaging a Haskell Library as a Swift Binary XCFramework](<https://devfeed.tech/articles/automatically-packaging-a-haskell-library-as-a-swift-binary-xcframework-27918.md>)

Original publisher: [Read original article](<http://alt-romes.github.io/posts/2025-07-05-packaging-a-haskell-library-as-a-swift-binary-xcframework.html>)

Published: 2025-07-05T00:00:00Z

Content type: tutorial

Language: en

Sources: [Romes' Musings](<https://devfeed.tech/sources/romes-musings.md>)

Topics: [Haskell](<https://devfeed.tech/topics/haskell.md>), [Swift](<https://devfeed.tech/topics/swift.md>), [interoperability](<https://devfeed.tech/topics/interoperability.md>), [Library](<https://devfeed.tech/topics/library.md>), [Automation](<https://devfeed.tech/topics/automation.md>), [Framework](<https://devfeed.tech/topics/framework.md>), [macOS](<https://devfeed.tech/topics/macos.md>)

Tags: [apple](<https://devfeed.tech/tags/apple.md>), [automation](<https://devfeed.tech/tags/automation.md>), [build](<https://devfeed.tech/tags/build.md>), [building](<https://devfeed.tech/tags/building.md>), [framework](<https://devfeed.tech/tags/framework.md>), [haskell](<https://devfeed.tech/tags/haskell.md>), [interoperability](<https://devfeed.tech/tags/interoperability.md>), [library](<https://devfeed.tech/tags/library.md>), [macos](<https://devfeed.tech/tags/macos.md>), [swift](<https://devfeed.tech/tags/swift.md>)

## AI overview

This tutorial presents xcframework, a Haskell library released on Hackage that automates packaging Haskell code as a Swift binary XCFramework. It explains how to build the Haskell library with Cabal, create a Swift package from the resulting artifacts, and use the package from Swift projects through XCFramework bundles and headers.

## Source excerpt

Contents 1 Announcing: xcframework 1.1 XCFrameworks 1.2 How to install xcframework 1.3 How to use the XCFramework in XCode 1.4 Building simple Swift package 1.5 Must use Cabal Foreign Library stanza 1.6 Conclusion 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 .modulemaps, .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. 1.1 XCFrameworks Apple introduced XCFramework bundles back in a WWDC19 session. An XCFramework is a multiplatform binary framework bundle. For our purposes, that means we can create a Swift Package just from a binary linkable artifact and a couple of header files. Then, any Swift project can depend on this binary Swift package and call the functions exposed to the headers and make sure the bundled library will