|
| 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`. |
0 commit comments