Codebase Overview
This is a very high-level overview of the Cargo codebase.
-
src/bin/cargo— Cargo is split in a library and a binary. This is the binary side that handles argument parsing, and then calls into the library to perform the appropriate subcommand. Each Cargo subcommand is a separate module here. See SubCommands. -
src/cargo/ops— Every major operation is implemented here. This is where the binary CLI usually calls into to perform the appropriate action.src/cargo/ops/cargo_compile.rs— This is the entry point for all the compilation commands. This is a good place to start if you want to follow how compilation starts and flows to completion.
-
src/cargo/core/resolver— This is the dependency and feature resolvers. -
src/cargo/core/compiler— This is the code responsible for runningrustcandrustdoc.-
src/cargo/core/compiler/build_context/mod.rs— TheBuildContextis the result of the "front end" of the build process. This contains the graph of work to perform and any settings necessary forrustc. After this is built, the next stage of building is handled inContext. -
src/cargo/core/compiler/context— TheContextis the mutable state used during the build process. This is the core of the build process, and everything is coordinated through this. -
src/cargo/core/compiler/fingerprint.rs— Thefingerprintmodule contains all the code that handles detecting if a crate needs to be recompiled.
-
-
src/cargo/core/source— TheSourcetrait is an abstraction over different sources of packages. Sources are uniquely identified by aSourceId. Sources are implemented in thesrc/cargo/sourcesdirectory. -
src/cargo/util— This directory contains generally-useful utility modules. -
src/cargo/util/config— This directory contains the config parser. It makes heavy use of serde to merge and translate config values. TheConfigis usually accessed from theWorkspace, though references to it are scattered around for more convenient access. -
src/cargo/util/toml— This directory contains the code for parsingCargo.tomlfiles.src/cargo/ops/lockfile.rs— This is whereCargo.lockfiles are loaded and saved.
-
src/doc— This directory contains Cargo's documentation and man pages. -
src/etc— These are files that get distributed in theetcdirectory in the Rust release. The man pages are auto-generated by a script in thesrc/docdirectory. -
crates— A collection of independent crates used by Cargo.