How to `Always Embed Swift Standard Libraries`?

We have CLI tool written in Swift for common usage (Android and iOS developers) on macOS. Android developers without Xcode installation get the following error:

dyld: Library not loaded: @rpath/libswiftCore.dylib
Referenced from: ~/git/myClITool/macosBin Reason: image not found
Abort trap: 6

We found that enabling Always Embed Swift Standard Libraries in Xcode would most likely help, but this CLI tool is exported with SPM, ignoring all Xcode settings.

How can I achieve this build behaviour using SPM only?

If your developers are using at least macOS 10.14.4, those binaries should be linked against the libswiftCore.dylib in the OS, which doesn't need Xcode. What version of macOS are they using?

1 Like

10.14.4 was the first version to have the Swift libraries built into the OS. For older macOS versions, they will need to install the Swift 5 Runtime Support package:

https://support.apple.com/kb/DL1998?locale=en_US

2 Likes

I ran into a similar problem recently when I rebuilt protoc-gen-swift with the Xcode 11.1 toolchain. (That is the Protocol Buffers compiler plugin to generate Swift bindings.)

Previously I built it with Xcode 9.3 on macOS 10.13 using the command swift build -c release -Xswiftc -static-stdlib. This gave me an executable that I could copy around and run from any directory on any host.

When I rebuilt it using the Xcode 11.1 toolchain with the same command, I could no longer run it:

:; .build/x86_64-apple-macosx/release/protoc-gen-swift
dyld: Library not loaded: @rpath/libswiftCore.dylib
  Referenced from: /Users/rmayoff/P/clarity/protobuf/src/swift-protobuf-1.7.0/.build/x86_64-apple-macosx/release/protoc-gen-swift
  Reason: image not found
Abort trap: 6

I had to remove the -Xswiftc -static-stdlib flags to get a working executable.

1 Like

-static-stdlib is no longer supported, yeah.

They have various versions of macOS (10.14.0 and above).
Should I add a package dependency to "libswiftCore.dylib"? Is that even possible?

My goal is to create a single executable that I can distribute to the team, without additional installation requirements. If "-static-stdlib" is no longer supported, maybe should I add an explicit macOS version requirement? Or is there a better way to achieve the goal?

You'll either need to require macOS 10.14.4 or later, or ask your clients to install the Swift Runtime Libraries package on their older macOS versions.

2 Likes
Terms of Service

Privacy Policy

Cookie Policy