Swift 5 Linking Swift Standard Libraries from command line application

Hi there!
Recently I've migrated my project from Swift 4.2 to Swift 5 with XCode 10.2. While the app itself works fine, the command line application which I use as privileged helper tool(e.g. not in the app itself) can't link against swift standard libraries.
The exact error message that I have:

dyld: Library not loaded: @rpath/libswiftCore.dylib
Referenced from: /Library/PrivilegedHelperTools/./com.myawesomeprogram.internal.HelperTool
Reason: image not found

Before upgrading everything worked as intended.
Has anyone faced similar problem?

There is a way for me to embed swift standard libraries inside the main user app and reference them from here, but it will make the helper depend on the location of the app. Probably the solution is to static link Swift standard libraries, but I cant find enough info how to do this.

You need to install the Swift 5 Runtime Support package: https://support.apple.com/kb/DL1998

Starting with Xcode 10.2, Swift 5 command line programs you build require the Swift 5 runtime support libraries built into macOS. These libraries are included in the OS starting with macOS Mojave 10.14.4. When running on earlier versions of macOS, this package must be installed to provide the necessary Swift 5 libraries. This package is not necessary for apps with graphical user interfaces.

The problem is distributing the app to the users who might not have latest Mojave. On my machine I can just update/install support package.
Im searching the way to distribute command line application and embed the libraries inside of it, if it is possible.

Yeah, it's a bit annoying at the moment, but in the long run this won't really be much of a problem. There was a thread on this topic a while ago, you might find some tips: Command line applications crashes with Xcode 10.2

Solving this for a privileged helper tool is tricky. I’m aware of four options:

  • Increase your deployment target (A)

  • Install, or require the user to install, the Swift 5 Runtime Support on older OS releases (B)

  • Install your own copy of the Swift runtime libraries in a fixed, secure location and reference them from your tool (C)

  • Stick with an older Xcode until A or B becomes more appealing (D)

None of these are particularly appealing. My guess is that you’re going to rule out A and B, which suggests C as the best option. Alas, I don’t think C is viable in your case, and that’s because of a chicken and egg problem. For your tool to use these libraries safely, they must be in a secure location. Without that, a non-privileged user could replace the libraries and hijack your tool. That’s the chicken. The egg is that to put these libraries in a secure location, you need your privileged helper tool to be functioning.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

4 Likes
Terms of Service

Privacy Policy

Cookie Policy