Skip to content

Commit 41fb237

Browse files
committed
Add CLAUDE.md for project guidance and build commands
1 parent 3f5bbf5 commit 41fb237

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

CLAUDE.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is a Bazel Build Server Protocol (BSP) implementation for Swift and iOS projects that integrates with SourceKit LSP. It allows SourceKit to work with Bazel-based Swift projects, providing IDE features like syntax highlighting, jump to definition, auto-complete, etc.
8+
9+
## Build Commands
10+
11+
### Swift Package Manager Commands
12+
- `swift build` - Build the project in debug mode
13+
- `swift build --configuration release` - Build release version
14+
- `swift run bazel-build-server` - Run the build server executable
15+
- `swift test` - Run all tests using Swift Testing framework
16+
- `swift package clean` - Clean build artifacts
17+
18+
### Makefile Commands
19+
- `make build` - Build debug version (equivalent to `swift build`)
20+
- `make release` - Build release version
21+
- `make run` - Build and run the executable
22+
- `make clean` - Clean build artifacts
23+
- `make install` - Install release binary to `/usr/local/bin`
24+
- `make test-harness` - Build and copy binary to TestHarness directory
25+
26+
### Bazel Commands (in TestHarness directory)
27+
- `bazel build //App:App` - Build the test app
28+
- `bazel test //...` - Run all Bazel tests
29+
- `bazel query //...` - Query all targets
30+
31+
## Architecture
32+
33+
### Core Components
34+
35+
**Main Executable (`Sources/BazelBuildServer/`)**
36+
- `BazelBuildServer.swift` - Entry point with CLI argument parsing and logging setup
37+
38+
**Build Server Library (`Sources/BazelBuildServerLib/`)**
39+
- `BuildServer.swift` - JSON-RPC communication handler, reads from stdin/stdout
40+
- `RequestHandler.swift` - Processes BSP requests (initialize, compile, etc.)
41+
- `BSPTypes.swift` - Build Server Protocol type definitions
42+
- `StreamLogHandler.swift` - Custom logging implementation
43+
44+
**Action Query System (`Sources/ActionQuery/`)**
45+
- `ActionQuery.swift` - Executes Bazel aquery commands with caching
46+
- `BazelTarget.swift` - Represents Bazel build targets
47+
- `QueryResult.swift` - Parses Bazel query output
48+
49+
**Supporting Libraries**
50+
- `Sources/BSPError/` - Error handling types
51+
- `Sources/ShellCommand/` - Shell command execution utilities
52+
- `Sources/QueryParser/` - Protobuf-based query parsing
53+
54+
### Key Patterns
55+
56+
1. **JSON-RPC Communication**: The build server communicates via JSON-RPC over stdin/stdout following LSP patterns
57+
2. **Caching Strategy**: Bazel query results are cached in `~/.bazel-sourcekit-bsp/` with background refresh
58+
3. **Concurrent Processing**: Uses DispatchQueue for thread-safe target management
59+
4. **Structured Logging**: Dual logging to file (`~/bazel-build-server.log`) and activity log (`~/.bazel-sourcekit-bsp/activity.log`)
60+
61+
### Configuration
62+
63+
The build server is configured via `buildServer.json` files that specify:
64+
- Executable path and arguments
65+
- Target Bazel targets to track
66+
- Index database path
67+
- Additional aquery arguments
68+
69+
## Test Harness
70+
71+
The `TestHarness/` directory contains a complete Bazel workspace for testing:
72+
- iOS app target (`//App:App`)
73+
- Various Swift libraries with different dependency patterns
74+
- External dependencies managed via `MODULE.bazel`
75+
- Custom BUILD.bazel files for third-party dependencies
76+
77+
## Testing
78+
79+
Tests use the Swift Testing framework (not XCTest). Key test targets:
80+
- `ActionQueryTests` - Tests query parsing with JSON/text fixtures
81+
- `ShellCommandTests` - Tests shell command execution
82+
- `QueryParserTests` - Tests protobuf query parsing
83+
84+
Run tests with `swift test` or target specific tests like `swift test --filter ActionQueryTests`.

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ This allows you to get SourceKit working for Swift projects that use the Bazel b
66

77
SourceKit is a language server that provides syntax highlight, jump to definition, auto complete, etc.
88

9+
## Installation
10+
11+
1. clone the project and run swift build, the server executable will be store in the `.build/arm64-apple-macosx/debug/bazel-build-server`
12+
2. edit the buildServer.json under the TestHarness folder by changing the executable path
13+
3. if you use global_index_store, be sure the change the path to the `.index-db`
14+
4. open TestHarness folder with `code TestHarness`
15+
5. the bazel-build-server.log is stored at the user home directory `~/bazel-build-server.log`
16+
17+
You can use the example buildServer.json inside the TestHarness for your project and make sure you specify the target name `//YourTarget:YourTarget`
18+
919
### Recommended plugins
1020

1121
- [Swift format](https://github.com/nicklockwood/SwiftFormat). Formats your swift code "on save".

0 commit comments

Comments
 (0)