This document provides context and guidelines for working with this codebase.
This is a gRPC-based LLVM Content-Addressable Storage (CAS) cache server compatible with Xcode 26's compilation cache system. It implements the LLVM remote caching protocol to cache build artifacts and speed up compilation.
-
Proto definitions (
proto/): gRPC service definitions from LLVMcompilation_caching_kv.proto- KeyValueDB service (action cache)compilation_caching_cas.proto- CASDBService (content-addressable storage)
-
Storage layer (
src/storage/):mod.rs- Trait definitions for CasStore and KvStorememory.rs- In-memory implementation (for testing)cas_file.rs- File-based CAS with SQLite metadatacas_sqlite.rs- Full SQLite CAS storagekv_sqlite.rs- SQLite KV storage
-
Services (
src/service/):cas.rs- CASDBService gRPC implementationkv.rs- KeyValueDB gRPC implementation
-
Supporting modules:
hash.rs- BLAKE3 hashing with domain separationeviction.rs- LRU/TTL cache eviction managerexport_cleanup.rs- Cleanup of exported filesconfig.rs- TOML configuration handlingerror.rs- Error types
-
Binaries (
src/bin/):server.rs- gRPC server daemoncli.rs- CLI management tool
Uses BLAKE3 with domain separation:
- Blobs:
BLAKE3("cas-build-cache:blob:v1:" || data) - Objects:
BLAKE3("cas-build-cache:object:v1:" || data || refs...)
- File-based CAS (default): Best for large files, uses OS page cache
- SQLite KV (default): Optimal for small action cache entries
- Multi-level directory structure (configurable 1-3 levels) for file CAS
- LRU-based with high/low water marks (95%/85% default)
- Evicts KV entries first, then CAS entries
- Optional TTL-based eviction
Lenient mode by default (strict mode optional):
- First value wins, subsequent mismatches are logged but not rejected
- Prevents build failures from legitimately non-deterministic actions
# Build
cargo build
cargo build --release
# Test
cargo test # All tests
cargo test --test integration_tests # Integration tests only
cargo test <test_name> # Specific test
# Run server
cargo run --bin cas-cache-server
cargo run --bin cas-cache-server -- --socket /path/to/socket.sock
# Run CLI
cargo run --bin cas-cache-cli -- status
cargo run --bin cas-cache-cli -- list
cargo run --bin cas-cache-cli -- evictLocated alongside the code they test (in #[cfg(test)] modules). Cover:
- Hash generation and verification
- Storage backends (file, SQLite, memory)
- Service request/response handling
- Eviction logic
Located in tests/integration_tests.rs. Spin up real gRPC servers on Unix sockets and test end-to-end flows.
Default locations checked:
~/.config/cas-build-cache/config.toml/etc/cas-build-cache/config.toml./config.toml
Key settings:
server.socket_path- Unix socket pathstorage.cas_backend- "file", "sqlite", or "memory"storage.kv_backend- "sqlite" or "memory"eviction.max_size- Cache size limiteviction.policy- "lru", "ttl", or "lru_ttl"
Configure Xcode with these build settings:
COMPILATION_CACHE_ENABLE_CACHING=YES
COMPILATION_CACHE_ENABLE_PLUGIN=YES
COMPILATION_CACHE_REMOTE_SERVICE_PATH=$HOME/.local/state/cas-build-cache/cache.sock
- Use standard Rust formatting (
cargo fmt) - Add
#[cfg(test)]tests alongside modules - Use
tracingfor logging (debug, info, warn, error levels) - Error handling via
thiserrorcustom error types - Async code uses
tokioruntime
- The cache handles thousands of requests per build
- Keep per-RPC overhead minimal
- Use read-optimized storage (file CAS leverages OS page cache)
- Avoid global locks; storage uses per-entry locking
- SQLite in WAL mode for concurrent access
- New storage backend: Implement
CasStoreand/orKvStoretraits - New eviction policy: Add variant to
EvictionPolicyenum in config.rs - New CLI command: Add subcommand in cli.rs using clap
If proto files need updates:
- Modify files in
proto/ - Proto compilation happens automatically via
build.rs - Generated code is in
target/(not committed)
- Socket permission denied: Check socket path permissions (mode 0600)
- Cache not working: Ensure server is running, check socket path in Xcode settings
- Slow builds: Check cache hit rate with
cas-cache-cli status - Disk space issues: Review eviction settings, run
cas-cache-cli evict