Thanks for the tip, Joe, I hadn't seen that PR. It sounds like it should work, but it doesn't for me, I'm still getting the same error:
$ echo $DYLD_LIBRARY_PATH
/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-11-17-a.xctoolchain/usr/lib/swift/macosx
$ xcrun --toolchain org.swift.50202011171a \
swift run \
-Xswiftc -Xfrontend -Xswiftc -enable-experimental-concurrency
dyld: Library not loaded: /usr/lib/swift/libswift_Concurrency.dylib
Referenced from: /Users/elo/code/AsyncAwait/.build/x86_64-apple-macosx/debug/AsyncAwait
Reason: image not found
(I tried using swift run --toolchain … instead of xcrun --toolchain … swift run, with the same result.)
Thank you too, Alejandro. Your idea didn't work right away, but it got me on the right track. Turns out that the toolchain's lib/swift directory is present in my executable's @rpath (I checked this with otool -l). But here's otool -L for the executable, showing that libswift_Concurrency.dylib doesn't use @rpath and is hardcoded to /usr/lib/swift instead:
otool -L .build/x86_64-apple-macosx/debug/AsyncAwait
.build/x86_64-apple-macosx/debug/AsyncAwait:
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1770.106.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.0.0)
/System/Library/Frameworks/CFNetwork.framework/Versions/A/CFNetwork (compatibility version 1.0.0, current version 1207.0.0)
/usr/lib/swift/libswift_Concurrency.dylib (compatibility version 1.0.0, current version 0.0.0)
@rpath/libswiftCore.dylib (compatibility version 1.0.0, current version 0.0.0)
@rpath/libswiftCoreFoundation.dylib (compatibility version 1.0.0, current version 0.0.0, weak)
@rpath/libswiftCoreGraphics.dylib (compatibility version 1.0.0, current version 0.0.0, weak)
@rpath/libswiftDarwin.dylib (compatibility version 1.0.0, current version 0.0.0, weak)
@rpath/libswiftDispatch.dylib (compatibility version 1.0.0, current version 0.0.0)
@rpath/libswiftFoundation.dylib (compatibility version 1.0.0, current version 0.0.0)
@rpath/libswiftIOKit.dylib (compatibility version 1.0.0, current version 1.0.0, weak)
@rpath/libswiftObjectiveC.dylib (compatibility version 1.0.0, current version 0.0.0, weak)
@rpath/libswiftSwiftOnoneSupport.dylib (compatibility version 1.0.0, current version 0.0.0)
@rpath/libswiftXPC.dylib (compatibility version 1.0.0, current version 1.1.0, weak)
I was able to fix the path with this command:
install_name_tool -change \
/usr/lib/swift/libswift_Concurrency.dylib \
/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-11-17-a.xctoolchain/usr/lib/swift/macosx/libswift_Concurrency.dylib \
.build/x86_64-apple-macosx/debug/AsyncAwait
Is it a bug that libswift_Concurrency.dylib isn't linked using @rpath?