-
Notifications
You must be signed in to change notification settings - Fork 364
[ContributorDoc] Add detailed docs for using a local build of SourceKit #2580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Steffeeen
wants to merge
2
commits into
swiftlang:main
Choose a base branch
from
Steffeeen:local-sourcekit-build-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
Contributor Documentation/Using a Local Build of SourceKit.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # Using a Local Build of SourceKit | ||
|
|
||
| This guide explains how to run SourceKit-LSP against a local build of SourceKit from the Swift monorepo. | ||
|
|
||
| Examples in this document use the checkout layout from Swift's [How to Set Up an Edit-Build-Test-Debug Loop](https://github.com/swiftlang/swift/blob/main/docs/HowToGuides/GettingStarted.md), ie.`swift-project/swift` and `swift-project/sourcekit-lsp` as sibling directories. | ||
| This layout is only for convenience. | ||
| `sourcekit-lsp` and `swift` can live in different directories as long as you pass the correct absolute paths. | ||
|
|
||
| ## 1. Build Swift | ||
|
|
||
| Follow the [How to Set Up an Edit-Build-Test-Debug Loop](https://github.com/swiftlang/swift/blob/main/docs/HowToGuides/GettingStarted.md) guide to clone Swift and get the required dependencies. Then, add the following additional flags to the `build-script` invocation: `--swift-testing`, `--swift-testing-macros`, `--llbuild`, `--swiftpm` and `--install-all`. | ||
| These flags are necessary to build the components of Swift that SourceKit-LSP depends on, and to ensure that a toolchain with all the necessary components is created. | ||
| When using the `build-script` command from the guide the entire command becomes: | ||
|
|
||
| - macOS: | ||
|
|
||
| ```sh | ||
| utils/build-script --skip-build-benchmarks \ | ||
| --swift-darwin-supported-archs "$(uname -m)" \ | ||
| --release-debuginfo --swift-disable-dead-stripping \ | ||
| --bootstrapping=hosttools \ | ||
| --swift-testing \ | ||
| --swift-testing-macros \ | ||
| --llbuild \ | ||
| --swiftpm \ | ||
| --install-all | ||
| ``` | ||
|
|
||
| - Linux: | ||
|
|
||
| ```sh | ||
| utils/build-script --release-debuginfo \ | ||
| --swift-testing \ | ||
| --swift-testing-macros \ | ||
| --llbuild \ | ||
| --swiftpm \ | ||
| --install-all | ||
| ``` | ||
|
|
||
| ## 2. Point SourceKit-LSP to that toolchain | ||
|
|
||
| Set the `SOURCEKIT_TOOLCHAIN_PATH` environment variable when running | ||
| tests or launching SourceKit-LSP to point to the `.xctoolchain` directory of the locally built toolchain. | ||
| The path should look something like this: `.../swift-project/build/Ninja-RelWithDebInfoAssert/toolchain-macosx-arm64/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain`. | ||
| You may need to adjust the path based on the build configuration and platform. | ||
|
|
||
| Example (assuming `sourcekit-lsp` and `swift` are sibling directories): | ||
|
|
||
| ```bash | ||
| SOURCEKIT_TOOLCHAIN_PATH="$PWD/../build/Ninja-RelWithDebInfoAssert/toolchain-macosx-arm64/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain" \ | ||
| swift test | ||
| ``` | ||
|
|
||
| (you may need to adjust the path based on the build configuration and platform) | ||
|
|
||
| ## 3. Making Changes to SourceKit | ||
|
|
||
| When making changes to SourceKit, you can iterate faster by only rebuilding SourceKit and its dependencies instead of rebuilding the entire Swift toolchain. | ||
| You need to ensure that the toolchain gets updated with the new build artifacts. | ||
| This can be done by running the following command from the `build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64` directory after building Swift with the `build-script` command from step 1: | ||
|
|
||
| ```bash | ||
| DESTDIR=../toolchain-macosx-arm64 ninja sourcekitd sourcekit-inproc install-sourcekit-xpc-service install-sourcekit-inproc | ||
| ``` | ||
|
|
||
| (you may need to adjust the path based on the build configuration and platform) | ||
|
|
||
| ## SourceKit modes on macOS | ||
|
|
||
| Normally, SourceKit-LSP uses XPC on macOS to communicate with SourceKit, while on Linux SourceKit runs in the same process as SourceKit-LSP. | ||
| However, sometimes it may be desirable to run SourceKit in-process on macOS as well. | ||
| Running SourceKit in-process can be useful when using the `SOURCEKIT_LOGGING` environment variable, as the output will include the log messages from SourceKit itself instead of just the messages from the SourceKit wrapper in SourceKit-LSP. | ||
| Additionally, running SourceKit in-process can be useful for profiling as the SourceKit symbols will be directly visible in the profile. | ||
|
|
||
| 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 | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you mentioned above, is it worth to add
SOURCEKIT_LOGGING=1here as well?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it would make sense to note in the docs that one probably wants to also specify
SOURCEKIT_LOGGINGwhen usingSOURCEKIT_LSP_RUN_SOURCEKITD_IN_PROCESSeven tough it is not strictly required.The
SOURCEKIT_LOGGINGenvironment 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.