How to not copy Swift Standard Library to additional app targets within a single macOS bundle

I have not been able to find the solution to this anywhere. I would like to have a single app bundle that could contain one or more "helper" apps, but only have a single Frameworks folder for the Swift Standard Library. I can easily do this with Swift Command Line Tools by changing "Runpath Search Paths" to look to the Frameworks folder within the main application bundle (even easier now with Swift 5 since you can't include the libraries in your executable anyway), but I have not figured out how to have Xcode not run CopySwiftLibs during the build process for a Cocoa App target. If I change "Link With Standard Libraries" to NO, the build fails. What am I missing? I know this is possible because I have seen app bundles from other devs that have achieved what I am looking for.

In case anyone else is wasting time trying to find an answer, the official word from Apple is that there is no supported way of achieving this. I now assume what I had been seeing were ObjC apps containing some Swift code.


I guess we just wait for ABI stability. Hopefully around the corner for macOS.

I don’t know the answer, alas. As no one else has chimed in, my recommendation is that you open a DTS tech support incident and discuss this with our tools specialist.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Accepted Answer

In case anyone else is wasting time trying to find an answer, the official word from Apple is that there is no supported way of achieving this. I now assume what I had been seeing were ObjC apps containing some Swift code.


I guess we just wait for ABI stability. Hopefully around the corner for macOS.

I'm sorry I'm a bit late to this question but I had the same problem with one of my apps that is completely written in Swift. I have an agent in LoginItems in the main app bundle and Xcode duplicated all Swift dylibs.
I didn't find a solution to stop Xcode from copying the dylibs but I found a workaround that works well for me when having an extra app with a Frameworks folder. After changing the rpath for the agent to point to the main Frameworks folder, I simply included a Build Phase Run Script in my main app that removed the unnecessary dylibs, like this:
find "${CODESIGNING_FOLDER_PATH}/Contents/Library/LoginItems/MyAgent.app/Contents/Frameworks/" -name "*.dylib" -delete
And I set it to only run when installing and it does run the deleting before the final signing so there isn't any problem with changing the bundle after it has been signed.
Cheers,
Peter

Don’t know if a relevant option was added later or maybe it’s not considered supported, but I’ve found a way to skip copying the libraries.

  • Define a custom build setting for a target: OTHER_SWIFT_STDLIB_TOOL_FLAGS

  • Set it to:

    --source-libraries /dev/null

This will effectively disable copying the Swift libraries.

I’ve found the option by running this in Terminal:

xcrun swift-stdlib-tool --help
How to not copy Swift Standard Library to additional app targets within a single macOS bundle
 
 
Q