Building and Deployment
Relevant source files
The following files were used as context for generating this wiki page:
The building and deployment system of rust-code-analysis is centered around the Rust ecosystem, leveraging cargo for dependency management and compilation. The project is structured as a workspace containing a core library, a command-line interface (CLI), and a web server. Deployment follows a standard Rust pattern where binaries are compiled for specific platforms (Linux, macOS, and Windows) and distributed via GitHub releases or Crates.io.
Sources: rust-code-analysis-book/src/developers/README.md:1-5, README.md:1-15, rust-code-analysis-book/src/README.md:15-20
Building Process
The project uses a Cargo workspace to manage its sub-packages. Developers can build specific components or the entire project using standard cargo build commands.
Build Targets
| Component | Command | Description |
|---|---|---|
| Library | cargo build | Builds the core rust-code-analysis library. |
| CLI Tool | cargo build -p rust-code-analysis-cli | Builds the command-line interface. |
| Web Server | cargo build -p rust-code-analysis-web | Builds the REST API web server. |
| Workspace | cargo build --workspace | Builds all components in the repository. |
Sources: rust-code-analysis-book/src/developers/README.md:30-45, README.md:35-50
Build Configuration
The workspace is configured in the root Cargo.toml. It includes specific optimization profiles for releases, such as Link Time Optimization (LTO) and codegen-units reduction to improve performance.
[profile.release]
opt-level = 3
lto = true
codegen_units = 1
panic = "unwind"
strip = "debuginfo"
Sources: Cargo.toml:57-67
Development Workflow and Quality Assurance
The project enforces a strict quality assurance workflow before code can be integrated. This includes automated testing, formatting, and linting.
The diagram above illustrates the sequential steps required for a developer to prepare a contribution for deployment.
Sources: rust-code-analysis-book/src/developers/README.md:10-90, README.md:52-70
Testing and Documentation
- Unit & Integration Tests: Executed via
cargo test --workspace --all-features. Sources: rust-code-analysis-book/src/developers/README.md:47-50 - Snapshot Testing: The project uses
instafor snapshot testing, which requirescargo insta test --reviewfor updates. Sources: README.md:62-68 - Documentation: API documentation is generated using
cargo doc --open --no-deps. Sources: rust-code-analysis-book/src/developers/README.md:81-85
Grammar Management
A critical part of the build process involves the Tree Sitter grammars. These are categorized into third-party and internal grammars.
Grammar Update Lifecycle
Updating grammars requires refreshing structures via shell scripts and resolving any breakages in the AST parsing logic.
Sources: rust-code-analysis-book/src/developers/update-grammars.md:1-50
New Language Integration
Adding support for a new language requires a multi-step integration between the enums crate and the main library:
- Add language crate to
enums/Cargo.toml. - Update
enums/src/languages.rsandenums/src/macros.rs. - Run
recreate-grammars.sh. - Register the new grammar in the main project's
src/languages/mod.rsandsrc/langs.rs.
Sources: rust-code-analysis-book/src/developers/new-language.md:10-50
Deployment and Runtime
The software is deployed in three primary forms: as a library (Crate), as a standalone CLI tool, and as a containerized or standalone web server.
CLI Execution
The CLI can be run directly from source or via compiled binaries:
cargo run -p rust-code-analysis-cli -- [parameters]
Sources: rust-code-analysis-book/src/developers/README.md:94-96
Web Server Deployment
The rust-code-analysis-web component provides a REST API. It is deployed to listen on specific host/port configurations.
| Parameter | Default | Description |
|---|---|---|
--host | 127.0.0.1 | IP address for the server. |
--port | 8080 | Port for the server. |
-j | N/A | Number of parallel jobs. |
Sources: rust-code-analysis-book/src/commands/rest.md:10-20
Continuous Integration (CI)
CI scripts like check-grammars-crates.sh automate the validation of grammar updates by comparing metrics computed on the gecko-dev repository before and after changes.
This process ensures that grammar updates do not introduce regressions in metric calculations.
Sources: check-grammars-crates.sh:1-60, check-grammar-crate.py:1-50
Conclusion
Building and deployment for rust-code-analysis is a robust process involving Rust-native tools for compilation and specialized shell scripts for grammar synchronization. By combining standard Cargo workspace management with automated metric validation against large-scale repositories like gecko-dev, the project maintains high technical accuracy across its library, CLI, and web distributions.