Statically linking Swift Package dependencies

I'm using a Swift package that depends on libopus and libsodium, for which I've created modulemaps and system library targets. I'm using the package in a macOS application. The application runs fine on my computer, but on others it crashes because libopus and libsodium aren't installed.

Can I statically link those dylibs so that people using the app don't have to have them installed?

What does the SPM package build, a library/framework, or an application? Are you the author of the package? What are you delivering, the package itself or the macOS application?

If you are delivering the macOS application, you could embed the dynamic libraries into the application bundle as part of the build process, and they would be available to your application whether the client has them installed or not.

The package builds a library. I'm not the author, but the package hasn't been maintained for about a year and I've been modifying it locally for a while. I'm delivering the application.

I ended up using the new .binaryTarget option in Swift 5.3; I just created the xcframeworks with xcodebuild -create-xcframework. After doing that, the package and the app both compile fine, and setting DYLD_SHARED_REGION to avoid and then opening the app leads to dyld not finding Foundation, which means it statically linked the frameworks.

Terms of Service

Privacy Policy

Cookie Policy