Bazel implemention for build server protocol and mainly working with sourcekit-lsp.
- Xcode 16.3
- Swift toolchain 6.1.0
- Enable global_index_store in .bazelrc
- Disable
build --features=swift.use_explicit_swift_module_map
- Creating a buildServer.json at the root of your project shown below.
- The
argv
need to point at the buildserver executable - The
target
will be used byaquery
to get all the compiler arguments and targets. - The
sdk
is what will be replaced for__BAZEL_XCODE_SDKROOT__
- The
indexStorePath
is the location where all indexstore files are. - The
indexDatabasePath
is the location for index.db output - The
aqueryArgs
are additional arguments you can supply to the bazel aquery command - The
extraIncludes
are adding to the compiler arguments with option-I
for addtional swiftmodule search paths - The
extraFrameworks
are adding to the copmiler arguments with option-F
for framework search apth
- The
{
"name": "example-app",
"argv": ["/Users/sean7218/bazel-build-server/target/debug/buildserver"],
"version": "1.0.0",
"bspVersion": "2.0.0",
"languages": ["swift"],
"target": "//App:App",
"sdk": "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.4.sdk",
"indexStorePath": "/Users/sean7218/bazel/buildserver/example-app/bazel-out/_global_index_store",
"indexDatabasePath": "/Users/sean7218/bazel/buildserver/example-app/.index-db",
"aqueryArgs": [],
"extraIncludes": [],
"extraFrameworks": []
}
- Compile the build server by running
cargo build
, and the executable will be inbazel-build-server/target/debug/buildserver
, and change theargv
in the buildServer.json file as well.
cargo build
- Before compile your project with bazel, you need to set the global index in
.bazelrc
file, then compile your project based on the target specified in thebuildServer.json
such asbazel build //App:App
# either this
build --features swift.use_global_index_store
build --features swift.index_while_building
# or
build --features swift.use_global_index_store
build --swiftcopt=-index-store-path
build --swiftcopt=$(OUTPUT_BASE)/indexstore
-
Open your project in vscode or neovim, you should be see logs both in sourcekit-lsp and bsp.log
-
Once the server is started Logging is stored in
~/.sourcekit-bsp/bsp.log
, it is recommended to open it and see any issues.
Here are some of the common errors:
standard library failed to load
- this means your path to sdk is wrong
execution_root not found
- when build server first start, it will run
bazel info execution_root
if the command fails, the build server will shutdown.
👻 handle_initialize_request failed -> JsonError
- this usually means your buildServer.json is malformatted