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]

Workspace Members

The members array includes crates such as:

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]

This section sets versioning and licensing metadata for the workspace.

Build Profiles

There are two profiles defined:

These profiles control optimization, debugging, and safety checks during compilation. They enable a release build with or without debug info.

[workspace.dependencies]

Path Dependencies

This signifies that these crates are developed within the workspace and are integrated tightly.

[patch.crates-io]


Important Implementation Details


Interaction with Other Parts of the System


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

[workspace]

Declares workspace members and resolver.

[package]

Defines version, edition, license info.

[profile.release]

Release build config with overflow checks.

[profile.release-with-debug]

Release with debug symbols and overflow checks.

[workspace.dependencies]

Centralized dependency declarations with versions and features.

[patch.crates-io]

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