terhechte/SourceKittenDaemon

Release 0.1.6 from SourceKittenDaemon.pkg is incorrectly linked

Closed this issue · 3 comments

sourcekittendaemon crashes when launched because of a missing library dependency.

Here is the output of sourcekittendaemon --help:

dyld: Library not loaded: /Users/nathan/Development/src/github.com/terhechte/SourceKittenDaemon/.build/release/libCYaml.dylib
  Referenced from: /usr/local/bin/sourcekittendaemon
  Reason: image not found
[1]    55261 abort      sourcekittendaemon --help

Oops! Sorry I'll upload a new release

After some digging, looks like realm/SwiftLint#1395 is a related issue that describes a fix in sourcekitten

For some reason it's still dynamically linking those libraries:

~/D/s/g/t/SourceKittenDaemon (master) $ otool -L /usr/local/bin/sourcekittendaemon
/usr/local/bin/sourcekittendaemon:
        /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1349.64.0)
        /Users/nathan/Development/src/github.com/terhechte/SourceKittenDaemon/.build/release/libCYaml.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/nathan/Development/src/github.com/terhechte/SourceKittenDaemon/.build/release/libCLibreSSL.dylib (compatibility version 0.0.0, current version 0.0.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 1238.50.2)
        /System/Library/Frameworks/CFNetwork.framework/Versions/A/CFNetwork (compatibility version 1.0.0, current version 811.4.18)
        /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 775.19.0)
        /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1349.63.0)
        @rpath/libswiftCore.dylib (compatibility version 1.0.0, current version 802.0.53)
        @rpath/libswiftCoreGraphics.dylib (compatibility version 1.0.0, current version 802.0.53)
        @rpath/libswiftDarwin.dylib (compatibility version 1.0.0, current version 802.0.53)
        @rpath/libswiftDispatch.dylib (compatibility version 1.0.0, current version 802.0.53)
        @rpath/libswiftFoundation.dylib (compatibility version 1.0.0, current version 802.0.53)
        @rpath/libswiftIOKit.dylib (compatibility version 1.0.0, current version 802.0.53)
        @rpath/libswiftObjectiveC.dylib (compatibility version 1.0.0, current version 802.0.53)

I've removed the package from the release for now, and will look into this again a bit later!

The proposed solution seems to statically link libCYaml into the binary. However, this is not yet supported by the actual version of Swift Package Manager.

The alternative is to install dylibs (libCYaml and libCLibreSSL) along with the binary (sourcekittendaemon). Dynamic library references must be updated so that sourcekittendaemon can load the dylibs correctly. install_name_tool does this. Here is an output of otool -L sourcekittendaemon after updating references:

dist/bin/sourcekittendaemon:
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1349.64.0)
	@executable_path/../lib/libCYaml.dylib (compatibility version 0.0.0, current version 0.0.0)
	@executable_path/../lib/libCLibreSSL.dylib (compatibility version 0.0.0, current version 0.0.0)
	/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
[...]

Here is an updated version of Makefile + a utility script to update sourcekittendaemon correctly.
MakefileAndUils.zip

I don't propose a PR because my "Makefile" is a bit rusty. The updated version needs refactoring and add a step to update dylib references differently when installing sourcekittendaemon: when in the dist folder, references can be relative, but when installed they should be absolute (for instance /usr/local/lib/libCYaml.dylib).