Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
# Bazel Build Server

Bazel implemention for [build server protocol](https://build-server-protocol.github.io/) and mainly working with [sourcekit-lsp](https://github.com/swiftlang/sourcekit-lsp).
Bazel implemention for [build server protocol](https://build-server-protocol.github.io/) and mainly working with [sourcekit-lsp](https://github.com/swiftlang/sourcekit-lsp).

![Screen Recording 2025-05-26 at 9 10 28 AM](https://github.com/user-attachments/assets/a5d7e248-9f5a-4149-bfe3-065a592d5fba)

## Requirements

- Xcode 16.3
- Xcode 16.3
- Swift toolchain 6.1.0
- Enable global_index_store in .bazelrc

## Getting Started

1. 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 by `aquery` 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
1. 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 by `aquery` 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 `bazelOut` is useful for mapping `bazel-out/` to some other other symlink prefix
- The `externalPath` is useful for mapping paths that start with `external/` to some other path

```json
{
"name": "example-app",
"argv": [
"/Users/sean7218/bazel/buildserver/target/debug/buildserver"
],
"version": "1.0.0",
"argv": ["/Users/sean7218/bazel/buildserver/target/debug/buildserver"],
"version": "1.0.0",
"bspVersion": "2.0.0",
"languages": ["swift"],
"target": "//App:App",
Expand All @@ -37,8 +38,8 @@ Bazel implemention for [build server protocol](https://build-server-protocol.git
}
```

2. Compile the build server by running `cargo build`, and the executable will be in `bazel-build-server/target/debug/buildserver`,
and change the `argv` in the buildServer.json file as well.
2. Compile the build server by running `cargo build`, and the executable will be in `bazel-build-server/target/debug/buildserver`,
and change the `argv` in the buildServer.json file as well.

```bash
cargo build
Expand All @@ -50,7 +51,7 @@ cargo build
# either this
build --features swift.use_global_index_store
build --features swift.index_while_building
# or
# or
build --features swift.use_global_index_store
build --swiftcopt=-index-store-path
build --swiftcopt=$(OUTPUT_BASE)/indexstore
Expand All @@ -63,4 +64,3 @@ build --swiftcopt=$(OUTPUT_BASE)/indexstore
## Debugging

todo!

16 changes: 13 additions & 3 deletions src/aquery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ pub fn aquery(
current_dir: &PathBuf,
sdk: &str,
aquery_args: Vec<String>,
bazel_out: Option<String>
bazel_out: Option<String>,
external_path: Option<String>
) -> Result<Vec<BazelTarget>> {
let mut command_args: Vec<String> = vec![];
let mnemonic = format!("mnemonic(\"SwiftCompile\", deps({}))", target);
Expand Down Expand Up @@ -118,14 +119,23 @@ pub fn aquery(
}

if let Some(bazel_out) = bazel_out.to_owned() {
if arg.starts_with("bazel-out") {
let _arg = arg.replace("bazel-out", &bazel_out);
if arg.contains("bazel-out/") {
let _arg = arg.replace("bazel-out/", &bazel_out);
compiler_arguments.push(_arg);
index += 1;
continue
}
}

if let Some(external_path) = external_path.to_owned() {
if arg.starts_with("external/") {
let _arg = arg.replace("external/", &external_path);
compiler_arguments.push(_arg);
index += 1;
continue;
}
}

compiler_arguments.push(arg);
index += 1;
}
Expand Down
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ impl RequestHandler {
&dir,
&self.config.sdk,
self.config.aquery_args.clone(),
self.config.bazel_out.clone()
self.config.bazel_out.clone(),
self.config.external_path.clone()
)?;

let mut build_targets: Vec<BuildTarget> = vec![];
Expand Down Expand Up @@ -322,7 +323,8 @@ impl RequestHandler {
&self.root_path,
&self.config.sdk,
self.config.aquery_args.clone(),
self.config.bazel_out.clone()
self.config.bazel_out.clone(),
self.config.external_path.clone()
)?;

self.targets = targets;
Expand Down
1 change: 1 addition & 0 deletions src/support_types/build_server_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct BuildServerConfig {
pub index_store_path: String,
pub index_database_path: String,
pub bazel_out: Option<String>,
pub external_path: Option<String>,
pub aquery_args: Vec<String>
}

Expand Down