Cargo.toml
Overview
This Cargo.toml file serves as the manifest and configuration file for a Rust workspace project. It defines workspace members (individual Rust packages/crates), workspace-wide settings including the Rust edition, Rust compiler version, licensing, and profiles for different build configurations. Furthermore, it specifies shared dependencies used across the workspace, including version numbers, features, and source information (crates.io, git repositories, or local paths). The file also includes patches for overriding specific crate sources.
This manifest is essential for managing compilation, dependency resolution, and project structure in the Rust ecosystem.
Sections and Their Functionality
[workspace]
Purpose: Declares the workspace configuration.
Key fields:
resolver: Defines the dependency resolver version ("3" is used here).members: Lists the relative paths to workspace member crates. These members correspond to sub-projects or modules that compose the overall system.
Usage: This section organizes multiple crates that share a common dependency graph and allows building them together.
Workspace Members
The members array includes crates such as:
block-managerchitchatdatabasegossipgql-serverSeveral helpers and shared components like helpers/block-state-helper,
shared/sdk-wrapperNetworking, telemetry, transport layers, node-related crates, and contracts
Each member is a separate crate that contributes specific functionality to the overall system. The members represent modular components that can be developed, built, and tested independently but are linked as part of the workspace.
[package]
Fields:
version:"0.10.1"- The version of the overall package/workspace.edition:"2021"- Specifies Rust edition compatibility.rust-version:"1.86.0"- Minimum Rust compiler version required.license:"Acki Nacki Node License"- License under which the project is released.license-file: "LICENSE.md" - File containing the full license text.
This section sets versioning and licensing metadata for the workspace.
Build Profiles
There are two profiles defined:
[profile.release-with-debug]Inherits from
devprofile.debug = trueenables debug symbols in release builds.Enables
overflow-checksto detect arithmetic overflows at runtime.
[profile.release]Enables
overflow-checkswithout debug symbols.
These profiles control optimization, debugging, and safety checks during compilation. They enable a release build with or without debug info.
[workspace.dependencies]
Defines shared dependencies used by the entire workspace.
Dependencies specify:
Name: e.g.,
actix-web,anyhow,serde.Version: Semver versions or git references.
Features: Optional feature flags to enable crate capabilities.
Source: crates.io, git repositories (e.g.,
https://github.com/tvmlabs/tvm-sdk.git), or local paths.
Some dependencies are pinned to specific git commits or tags for reproducible builds and to ensure compatibility.
Examples of important dependencies:
actix-webfor web server functionality.serdeandserde_jsonfor serialization.tokiofor async runtime.tracingand related crates for logging and telemetry.tvm-*crates fromtvmlabs/tvm-sdkfor blockchain virtual machine integration.rustlsandquinnfor TLS and QUIC network transport.salvoas an HTTP server framework with multiple features enabled.
Path Dependencies
Some dependencies refer to local workspace crates via relative
pathfields, e.g.,chitchat = { path = "chitchat" } database = { path = "database" }
This signifies that these crates are developed within the workspace and are integrated tightly.
[patch.crates-io]
Overrides the source for the
libsqlite3-syscrate, pointing it to a local path"libsqlite3-sys".This is used to patch or replace crates.io dependencies with local versions, often for custom fixes or modifications.
Important Implementation Details
Dependency Management: By defining dependencies in
[workspace.dependencies], this file centralizes versioning and feature selection, reducing duplication and preventing conflicts among workspace members.Version Pinning: Git dependencies are pinned to specific commit hashes or tags, ensuring reproducible builds and consistency across developer environments and CI pipelines.
Profiles: Custom profiles allow fine-tuning of build parameters such as debugging and overflow checks, balancing performance and safety.
Local Crate Integration: Path dependencies indicate modular design with crates split into distinct components, facilitating maintainability and scalability.
Licensing: The use of a custom license ("Acki Nacki Node License") is explicitly declared.
Interaction with Other Parts of the System
Workspace Members: Each member crate listed under
[workspace]is a self-contained Rust crate that implements parts of the system's functionality. They rely on the dependencies defined here and are built together.Shared Dependencies: The dependencies specified here are imported into the member crates. For example,
http-servermay useactix-weborsalvofor HTTP serving, whiledatabasemay userusqlite.Patching: The patch overrides the
libsqlite3-syscrate used byrusqliteor other crates, affecting all crates that depend on it.External SDK Integration: The
tvm-*crates from thetvmlabs/tvm-sdkrepository are used across the workspace for blockchain-related functionality.Feature Coordination: Feature flags on dependencies ensure that necessary traits or capabilities are enabled for the workspace's use cases.
Visual Diagram of Workspace Structure and Dependency Relationships
flowchart TD
Workspace["Cargo.toml Workspace"]
subgraph Members["Workspace Members"]
BM["block-manager"]
CC["chitchat"]
DB["database"]
GSP["gossip"]
GQL["gql-server"]
HH["helpers/*"]
HS["http-server"]
MR["message-router"]
MT["migration-tool"]
NW["network"]
ND["node"]
SDK["shared/sdk-wrapper"]
TL["telemetry_utils"]
TLay["transport-layer"]
TVM["tvm_contracts"]
end
subgraph Dependencies["Workspace Dependencies"]
Actix["actix-web"]
Serde["serde"]
Tokio["tokio"]
Tracing["tracing"]
Rustls["rustls"]
Quinn["quinn"]
TVM_SDK["tvm-sdk (git)"]
Salvo["salvo"]
Rusqlite["rusqlite"]
end
Workspace --> Members
Workspace --> Dependencies
BM --> Actix
BM --> Serde
BM --> Tokio
CC --> Tokio
CC --> Serde
DB --> Rusqlite
DB --> Serde
GQL --> Actix
GQL --> Serde
GQL --> Tokio
HS --> Salvo
HS --> Rustls
HS --> Quinn
SDK --> TVM_SDK
TVM --> TVM_SDK
ND --> Tokio
ND --> Tracing
TL --> Tracing
TLay --> Quinn
TLay --> Rustls
MT --> Rusqlite
%% Patch indication
Rusqlite -.->|patch| "libsqlite3-sys (local path)"
Summary of Key Elements
Section | Purpose |
|---|---|
| Declares workspace members and resolver. |
| Defines version, edition, license info. |
| Release build config with overflow checks. |
| Release with debug symbols and overflow checks. |
| Centralized dependency declarations with versions and features. |
| Overrides specific crate sources with local paths. |
Usage Examples
Adding a New Workspace Member
To add a new module to the workspace:
[workspace]
members = [
# existing members...
"new-crate"
]
Then create the new-crate directory with its own Cargo.toml.
Using Shared Dependency in Member Crate
In a member crate's Cargo.toml, omit version specification if dependency is declared in workspace:
[dependencies]
serde = { workspace = true }
tokio = { workspace = true }
This aligns the crate’s dependencies with the versions in the workspace.
Reference
For detailed information on Rust workspace configuration, dependency management, build profiles, and patching, see the official Cargo Book and Cargo Manifest Format.