[ContributorDoc] Add detailed docs for using a local build of SourceKit#2580
[ContributorDoc] Add detailed docs for using a local build of SourceKit#2580Steffeeen wants to merge 2 commits intoswiftlang:mainfrom
Conversation
1d485f6 to
51392e9
Compare
|
I understand having
Yes this is the correct way to do it. We might want to briefly discuss this internally, but feel free to open a PR for it now. |
51392e9 to
81ff39d
Compare
|
I have opened swiftlang/swift#88159 for the CMake change. |
| To force SourceKit-LSP to run SourceKit in process, set the `SOURCEKIT_LSP_RUN_SOURCEKITD_IN_PROCESS` environment variable. | ||
|
|
||
| ```bash | ||
| SOURCEKIT_LSP_RUN_SOURCEKITD_IN_PROCESS=1 swift test |
There was a problem hiding this comment.
Since you mentioned above, is it worth to add SOURCEKIT_LOGGING=1 here as well?
There was a problem hiding this comment.
I guess it would make sense to note in the docs that one probably wants to also specify SOURCEKIT_LOGGING when using SOURCEKIT_LSP_RUN_SOURCEKITD_IN_PROCESS even tough it is not strictly required.
The SOURCEKIT_LOGGING environment variables also does not seem to documented anywhere. In SourceKit-LSP I only found it in my docs and in the swift repo the only reference I found was in the actual code where it is read. It should probably be documented somewhere (in the SourceKit readme?), and we can then also link to that documentation in the SourceKit-LSP docs.
| This is due to a multitude of factors: | ||
|
|
||
| - `SwiftPMTestProject` requires a toolchain that contains `clang` and `clangd`, which are not present in the local build of swift | ||
| - TODO: expand on this with more details about the issues and potential solutions |
There was a problem hiding this comment.
(Haven't tried)
Maybe this can be resolved by build-script -r --install-llvm --install-swift (which installs clangd, clang, swiftc etc into e.g. ${build_dir}/toolchain-macosx-arm64/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain.
SOURCEKIT_TOOLCHAIN_PATH="$PWD/../build/Ninja-RelWithDebInfoAssert/toolchain-macosx-arm64/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr" \
swift testThere was a problem hiding this comment.
Building the toolchain works, I now also finally got ninja to correctly update the toolchain. I currently just set the DESTDIR environment variable to point to the toolchain directory before calling ninja:
DESTDIR=../toolchain-macosx-arm64 ninja sourcekitd sourcekit-inproc install-sourcekit-xpc-service install-sourcekit-inprocBut it should probably also be possible to make the install-sourcekit-xpc-service and install-sourcekit-inproc targets install into the toolchain if a toolchain was created. But I currently don't know how.
81ff39d to
b61e956
Compare
| package init(xcodeToolchains toolchainPaths: [URL]) { | ||
| let toolchainsAndReasons: [(toolchain: Toolchain, reason: ToolchainRegisterReason)] = toolchainPaths.compactMap { | ||
| path in | ||
| guard let toolchain = Toolchain(path) else { |
There was a problem hiding this comment.
When this initializer is used, the environment variable would not work currently, as it is not passed to the Toolchain initializer. However, as far as I can tell, this initializer is currently never used and could be removed entirely.
This environment variable can be used to force SourceKit-LSP to run SourceKitD in-process on macOS. This can be useful for debugging.
b61e956 to
bffe619
Compare
bffe619 to
76f76bc
Compare
As I have struggled a lot with this, I decided to add dedicated documentation for using a local build of SourceKit. As I haven't been able to get tests which use
SwiftPMTestProjectto run I'm also looking for input on that. Ideally, I would like to change the documentation to include general instructions which work for all tests or if that's not easily possible, at least layout the steps to get these tests to work.I have already worked out that the toolchain needs to have
clangandclangd. The default swift build does not have them inswift-macosx-arm64/bin. However, creating symlinks to the Xcode toolchainclangandclangdworks. Another issue is that the swift build does not have thePackageDescriptionmodule which causes the parsing of thePackage.swiftto fail.Both of these issues can be fixed by including
--swift-testing,--swift-testing-macros,--llbuild,--llbuild,--install-allin thebuild-scriptinvocation. This creates atoolchain-macosx-arm64directory which contains an Xcode toolchain withclang,clangdand thePackageDescription. When using this toolchain, the tests work. However, I have not been able to figure how to get ninja to update this toolchain when I recompile SourceKit.New Environment Variable to force in-process Sourcekit
I added a new environment variable
SOURCEKIT_LSP_RUN_SOURCEKIT_IN_PROCESSto explicitly force SourceKit to be run in-process on macOS. For this to work correctly, we also have to make a small change in the cmake setup in the main Swift repo. https://github.com/swiftlang/swift/blob/main/cmake/modules/SwiftComponents.cmake#L87-L91 needs to be changed to be:instead of
This is because we need
sourcekit-inproc, even when using XPC. Without this change we don't get a.frameworkdirectory forsourcekitdInProc. I haven't opened a PR for this yet, as I'm unsure if this is the correct place and/or way to fix this.In my opinion, this is better than forcing this in the
build-scriptinvocation by adding--extra-cmake-options='-DSWIFT_SOURCEKIT_USE_INPROC_LIBRARY:BOOL=FALSE'as the environment variable approach avoids a reconfigure. Thebuild-scriptapproach would also need a few changes to differentCMakeLists.txtto make it work correctly.I can also move the commit for the environment variable to a new PR, if that's preferred.