I am trying to build an .xcframework from a Swift package that I want to distribute to my customers. My package has multiple dependencies, some of which (like SwiftNIO) are not ABI stable.
To prepare it for distribution, I set BUILD_LIBRARY_FOR_DISTRIBUTION = YES. However, the build fails due to the non-ABI-stable nature of some dependencies.
My understanding is that BUILD_LIBRARY_FOR_DISTRIBUTION requires all dependencies to be built with module stability. But since some of mine (e.g., SwiftNIO) are not ABI stable, the build cannot succeed.
I saw multiple posts on the forum and online (github/stackoverflow) for the same issue but can’t find a proper solution to this yet.
Are there any workarounds or best practices for this use case? My main goal is to distribute the swift package without exposing the source code.
Any advice or guidance would be greatly appreciated!
I run into the same problem, but I use cocoapod and then use a script to force the BUILD_LIBRARY_FOR_DISTRIBUTION that depends on the library target to YES
then use a script to force the BUILD_LIBRARY_FOR_DISTRIBUTION that depends on the library target to YES
I did not get it. Do you mean you build all your dependencies using BUILD_LIBRARY_FOR_DISTRIBUTION = YES and then convert your package to .xcframework?
As the spectacular Corey Benfield recently reminded me, setting BUILD_LIBRARY_FOR_DISTRIBUTION when using xcodebuild will use this setting for all targets, even if internal to your framework.
What you really want is to make only your top level module has this setting applied. This is easy when you use an Xcode project, where you would set this on the target level in the build settings.
For a Swift package, you will need to use the equivalent Swift compiler options as explained here
You would add them to your target in the Package.swift manifest like so: