owensd / vscode-swift

An extension for VS Code which provides support for the Swift language.
MIT License
147 stars 5 forks source link

Error linking to sourcekitd #4

Closed zachwaugh closed 7 years ago

zachwaugh commented 7 years ago

Thanks for this extension! I had been wanting to build this myself. I just installed v0.5.4 it to try it out and getting a linker issue on my machine with a crash warning in VS Code:

image

The error in the debug console is:

dyld: Library not loaded: /Users/owensd/Projects/swift-langsrv/.build/release/libsourcekitd.dylib
  Referenced from: /Users/zach/.vscode/extensions/kiadstudios.apous-0.5.4/lib/usr/bin/langsrv
  Reason: image not found
[Info  - 5:38:11 PM] Connection to server got closed. Server will restart.

I tried to build the language server from source so I could swap out the binary from the extension version, but that failed to build as well:

~/code/tmp/swift-langsrv(master)
> make
./Scripts/genvers.sh
./Scripts/genskmap.sh
swift build -c debug -Xswiftc -framework -Xswiftc sourcekitd -Xswiftc -F -Xswiftc /Library/Developer/Toolchains/swift-3.1.1-RELEASE.xctoolchain/usr/lib -Xlinker -rpath -Xlinker /Library/Developer/Toolchains/swift-3.1.1-RELEASE.xctoolchain/usr/lib -Xlinker -rpath -Xlinker /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib -Xlinker -rpath -Xlinker /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/
Compile Swift Module 'JSONLib' (10 sources)
Compile Swift Module 'ParserTestHarness' (1 sources)
Compile Swift Module 'ParserPerfTestHarness' (1 sources)
Compile Swift Module 'LanguageServerProtocol' (15 sources)
Linking ./.build/debug/ParserTestHarness
ld: warning: directory not found for option '-F/Library/Developer/Toolchains/swift-3.1.1-RELEASE.xctoolchain/usr/lib'
ld: framework not found sourcekitd
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
/Users/zach/code/tmp/swift-langsrv/.build/checkouts/swift-lsp.git-7792384379381311818/Sources/LanguageServerProtocol/Initialization.swift:10:14: warning: 'rootPath' is deprecated: The `rootUri` member should be used instead.
        self.rootPath = rootPath
             ^
<unknown>:0: error: build had 1 command failures
error: exit(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/zach/code/tmp/swift-langsrv/.build/debug.yaml
make: *** [debug] Error 1

I'm running macOS 10.12.4 and Xcode 8.3.2 without any of the separate Swift toolchains installed. After I installed the latest toolchain from swift.org, I was able to build the language server locally.

owensd commented 7 years ago

The development of the language server requires to the toolchains. That probably won't be changing anytime soon.

However, you should be able to run the extension with only Xcode 8.3.2 installed. I thought I fixed that in v0.5.3... it seemed to work for me locally. I'll take another look.

owensd commented 7 years ago

Oh, I see... I did fix the previous error, but it exposes another one... look at the library path I see that one is being hardcoded as my user directory for some reason instead of using @rpath.

zachwaugh commented 7 years ago

Thanks! Requiring the toolchain is no problem, just wanted to give the full picture about my setup in case it helps tracking down any config issues.

I noticed that too when I looked with otool -L, make sense why it works for you :)

> otool -L langsrv
langsrv:
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1349.64.0)
    @rpath/sourcekitd.framework/Versions/A/sourcekitd (compatibility version 0.0.0, current version 0.0.0)
    /Users/owensd/Projects/swift-langsrv/.build/release/libsourcekitd.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/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1349.63.0)
    @rpath/libswiftCore.dylib (compatibility version 0.0.0, current version 0.0.0)
    @rpath/libswiftCoreGraphics.dylib (compatibility version 0.0.0, current version 0.0.0)
    @rpath/libswiftDarwin.dylib (compatibility version 0.0.0, current version 0.0.0)
    @rpath/libswiftDispatch.dylib (compatibility version 0.0.0, current version 0.0.0)
    @rpath/libswiftFoundation.dylib (compatibility version 0.0.0, current version 0.0.0)
    @rpath/libswiftIOKit.dylib (compatibility version 0.0.0, current version 0.0.0)
    @rpath/libswiftObjectiveC.dylib (compatibility version 0.0.0, current version 0.0.0)
    @rpath/libswiftXPC.dylib (compatibility version 0.0.0, current version 0.0.0)
    @rpath/libswiftos.dylib (compatibility version 0.0.0, current version 0.0.0)
owensd commented 7 years ago

Yeah... it seems the Swift PM is doing this, so I'm looking into a script to strip it and replace it with the correct version.

owensd commented 7 years ago

Ok... the language server project has been updated to replace the incorrect value using install_name_tool. I've renamed my local Toolchains directory and deleted all of my built output for the language server.

Everything seems to be working properly on my side now in as clean a state as I can get it. Thanks for logging this and sorry for the troubles.

Fixed with 200abf2784929876e859bb526abb903a65266a39.

zachwaugh commented 7 years ago

No problem at all! Thanks for the quick fix.