Code Block dependencies: [ .package(url: "https://github.com/apple/swift-tools-support-core.git", from: "0.1.10"), .package(url: "https://github.com/apple/swift-argument-parser.git", from: "0.2.0"), ], targets: [ .target(name: "progress", dependencies: [ .product(name: "ArgumentParser", package: "swift-argument-parser"), .product(name: "SwiftToolsSupport", package: "swift-tools-support-core")]), ...
It runs fine via swift run. Here's what I'm doing to produce a release executable:
Code Block swift build -c release cp -f .build/release/progress /usr/local/bin/progress
However, when I run the executable, I get the issue:
Code Block dyld: Library not loaded: @rpath/libSwiftToolsSupport.dylib Referenced from: /usr/local/bin/progress Reason: image not found
I've run otool -L /usr/local/bin/progress, which outputs the paths:
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1677.104.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 1281.100.1)
@rpath/libSwiftToolsSupport.dylib (compatibility version 0.0.0, current version 0.0.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1677.104.0)
@rpath/libswiftCore.dylib (compatibility version 1.0.0, current version 1103.8.25)
@rpath/libswiftDarwin.dylib (compatibility version 1.0.0, current version 0.0.0)
@rpath/libswiftFoundation.dylib (compatibility version 1.0.0, current version 0.0.0)
I can get the release executable to work by copying libSwiftToolsSupport.dylib into /usr/local/lib/ and overriding its install path on the executable:
Code Block cp -f .build/release/libSwiftToolsSupport.dylib /usr/local/lib/ install_name_tool -change "@rpath/libSwiftToolsSupport.dylib" "/usr/local/lib/libSwiftToolsSupport.dylib" "/usr/local/bin/progress"
However, this is seems like a bad workaround. Is there a better way to do this, that doesn't require touching the local filesystem? Note that I'm not using Xcode, purely the Package.swift and command line arguments (e.g. swift build -c release).