Introduction
Cargo.toml is the manifest of a Rust package, read by
Cargo, Rust’s build tool and package
manager. It names the package, its version and the Rust edition it is written for, and
lists the crates (Rust libraries) it depends on, which Cargo downloads from crates.io
and builds. Cargo writes the exact versions it chose to Cargo.lock beside
it.
A manifest can also describe a workspace: several packages in one repository that share a lock file and build folder.
Structure
The file is written in TOML, a simple configuration format of tables in square
brackets and key = value lines. The [package] table gives the
name, version and edition, and optionally a
description, licence and authors. [dependencies] maps crate names to
version requirements, or to tables giving a version, a Git repository or a local path
and the optional features to turn on. Other tables include
[dev-dependencies], [features], [profile.release]
and [workspace]. Every table and key is listed on the
manifest keys page.
[package]
name = "hello"
version = "0.1.0"
edition = "2021"
[dependencies]
serde = { version = "1.0", features = ["derive"] }
rand = "0.8"
Not described
Known, not yet covered
- Reference: the unstable manifest keys (
public,artifact, the contents ofcargo-featuresand[hints]), in the Cargo Book; they belong on the manifest page. The count of package keys in the page notes should also be rechecked. - Viewer: there is no viewer for
Cargo.tomlyet, so manifests are not opened, checked or shown.
Also used for
- Tom’s Obvious Minimal Language – Configuration text: tables in brackets, then key = value lines.
Links
Software
- Cargo – Rust’s build tool and package manager, which reads the manifest (Windows, macOS, Linux)
- rustup – installs Rust and Cargo (Windows, macOS, Linux)
- rust-analyzer – the Rust language server used by most editors (Windows, macOS, Linux)
- RustRover – JetBrains’ Rust IDE (Windows, macOS, Linux)
Developers
- toml – crates that read and write TOML, including
toml_edit, which keeps formatting (Rust)
Reference
- The Manifest Format – The Cargo Book’s reference for every table and key
- TOML – the configuration language’s specification