Make sure to read my article on Swift concurrency in a commandline tool before exploring this sample project.
Minimal sample to demonstrates executables using Swift concurrency crash when running on macOS 10.15 Catalina and macOS 11 Big Sur out of the box.
swift build -c release --arch x86_64 --arch arm64
The resulting binary can be found at .build/apple/Products/Release/concurrency-cli-sample
and can run on both Intel and Apple Silicon Macs.
Running the build product will work as expected on macOS 12+, but will crash on macOS 10.15 and 11. The error reports that libswift_Concurrency.dylib
can't be loaded:
dyld: lazy symbol binding failed: can't resolve symbol _swift_task_create in ./concurrency-cli-sample because dependent dylib @rpath/libswift_Concurrency.dylib could not be loaded
dyld: can't resolve symbol _swift_task_create in ./concurrency-cli-sample because dependent dylib @rpath/libswift_Concurrency.dylib could not be loaded
Abort trap: 6
Copy $(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/macosx/libswift_Concurrency.dylib
next to the executable. This works because of the extra rpath set using the linker flag in Package.swift. The dylib has to be shipped with the executable.
We explain this issue in depth on our blog.
Nonstrict B.V., Mathijs Kadijk & Tom Lokhorst, released under MIT License.