Building, testing, and contributing to CodeGraph.
- Rust stable ≥ 1.85 (edition 2024 used in
codegraph-graph) cargo(from rustup)- Optional:
clangfor some tree-sitter grammars (usually bundled)
# Verify toolchain
rustc --version
cargo --version# Build everything
cargo build --workspace
# Build release binary (what users get)
cargo build --release -p codegraph
# Run all tests
cargo test --workspace
# Lint (CI gate)
cargo clippy --workspace --all-targets -- -D warnings
# Format
cargo fmt --all
# Check all feature combinations
cargo check --workspace --features sqlite
cargo check -p codegraph-graph --features redis
cargo check -p codegraph --features rdbms
cargo check -p codegraph --features fastembedcrates/
codegraph-core/ Error types + semgraph model (Symbol, Chain, CallRecord, markers)
codegraph-extract/ tree-sitter native + 14 LangSpec extractors + 5 hand-written
codegraph-graph/ GraphIndex: registry + 2 engines + pluggable storage + embeddings
codegraph-context/ Markdown/JSON context formatter
codegraph-api/ GraphApi wrapper on SharedGraphIndex (async queries)
codegraph-sboxes/ Behavior sandbox: Cranelift JIT + Rhai mock runtime
codegraph-mcp/ MCP server (rmcp SDK) + 24 tools + session management
codegraph-bench/ Benchmarks (criterion, codspeed, storage comparison)
codegraph/ CLI (init/deinit/embed/serve) + watcher (notify + debounce)
# Core model tests
cargo test -p codegraph-core
# Extraction: 30 tests (10 lib + 16 chains + 2 cpp + 2 extract)
cargo test -p codegraph-extract
# Graph: 60+ tests (search, storage, ingest, flow, reopen)
cargo test -p codegraph-graph
# API layer
cargo test -p codegraph-api
# MCP server + tools
cargo test -p codegraph-mcp
# Sandbox JIT: control flow + end-to-end traces
cargo test -p codegraph-sboxes
# Bench pipeline integration
cargo test -p codegraph-bench
# Installer
cargo test -p codegraph-installer| Feature | Languages |
|---|---|
all-langs (default) |
All 14 |
lang-rust |
Rust |
lang-go |
Go |
lang-python |
Python |
lang-typescript |
TypeScript |
lang-javascript |
JavaScript |
lang-java |
Java |
lang-c |
C |
lang-cpp |
C++ |
lang-csharp |
C# |
lang-ruby |
Ruby |
lang-php |
PHP |
lang-scala |
Scala |
lang-swift |
Swift |
lang-lua |
Lua |
# Test single language
cargo test -p codegraph-extract --features lang-python| Feature | Description | Default on codegraph |
|---|---|---|
sqlite |
SQLite storage | ✅ |
lmdb |
LMDB storage | ✅ |
redis |
Redis storage (compile verify) | ❌ |
postgres |
PostgreSQL storage | via rdbms |
mysql |
MySQL storage | via rdbms |
bloom-search |
Bloom filter for chain search | ✅ |
fastembed |
ONNX embedding backend | ✅ (via codegraph-api) |
apple-accel |
macOS CoreML for ONNX | ❌ (macOS only) |
| Feature | Description | Default |
|---|---|---|
rdbms |
Enable postgres + mysql |
✅ |
fastembed |
Compile codegraph embed CLI |
❌ |
apple-accel |
macOS CoreML | ❌ |
| Feature | Description | Default |
|---|---|---|
rdbms |
Enable postgres + mysql |
❌ |
# This does NOT produce a slimmer binary — all storage drivers
# and embedding backend are still compiled in via codegraph-api
cargo build -p codegraph --no-default-featuresTo actually reduce binary size, you must build with minimal features on codegraph-graph AND avoid depending on codegraph-api (not practical for the main binary).
# Works
cargo build --features fastembed,apple-accel --target x86_64-apple-darwin
cargo build --features fastembed,apple-accel --target aarch64-apple-darwin
# Fails
cargo build --features fastembed,apple-accel --target x86_64-unknown-linux-gnu# Criterion benchmarks (statistical)
cargo bench -p codegraph-bench
# Single-pass measurement (JSON output)
cargo run -p codegraph-bench -- --json
# Storage backend comparison
cargo run -p codegraph-bench -- --storage sqlite,lmdb,memory
# CodSpeed (CI only — see .github/workflows/codspeed.yml)
cargo codspeed build -p codegraph-bench --features codspeedHandled by CI (.github/workflows/release.yml):
- Tag pushed:
vX.Y.Z - Builds for all targets:
x86_64-unknown-linux-muslaarch64-unknown-linux-gnux86_64-apple-darwinaarch64-apple-darwinx86_64-pc-windows-msvc
- Signs with cosign (keyless, GitHub OIDC)
- Attaches
.sig+.crtto release - Publishes to Homebrew tap, AUR, .deb/.rpm
Local release build:
cargo build --release -p codegraph
# Binary at target/release/codegraph.
├── crates/ # Workspace members
├── docs/ # Documentation (this file + others)
│ ├── architecture.md
│ ├── comparison.md
│ ├── configuration.md
│ ├── development.md # This file
│ ├── semantic-search.md
│ ├── storage-backends.md
│ ├── why-rust.md
│ └── specs/ # Detailed spec docs
├── scripts/ # Install scripts (sh/ps1)
├── sql/ # Postgres/MySQL schemas
├── packaging/ # .deb/.rpm packaging
├── .github/workflows/ # CI/CD
├── Cargo.toml # Workspace root
└── README.md # Main entry point
- Fork & branch
cargo fmt --all && cargo clippy --workspace --all-targets -- -D warningscargo test --workspace- Add tests for new functionality
- Update relevant docs in
docs/ - PR with clear description
Commit style: Conventional commits (feat:, fix:, docs:, refactor:, test:)
# Verbose logging
RUST_LOG=codegraph=debug codegraph init
# Specific crate
RUST_LOG=codegraph_graph=trace codegraph init
# MCP server debug
RUST_LOG=codegraph_mcp=debug codegraph serve --mcp
# Watcher debug
RUST_LOG=codegraph=debug codegraph serve --mcp- Architecture — Pipeline and crate relationships
- Why Rust — Rewrite rationale and benchmarks
- Configuration — Config reference
- Storage Backends — Backend deep-dive
- Semantic Search — Embedding setup
- README — Quick start