Compilation
The Unit
is the primary data structure representing a single execution of
the compiler. It (mostly) contains all the information needed to determine
which flags to pass to the compiler.
The entry to the compilation process is located in the cargo_compile
module. The compilation can be conceptually broken into these steps:
- Perform dependency resolution (see the resolution chapter).
- Generate the root
Unit
s, the things the user requested to compile on the command-line. This is done ingenerate_targets
. - Starting from the root
Unit
s, generate theUnitGraph
by walking the dependency graph from the resolver. TheUnitGraph
contains all of theUnit
structs, and information about the dependency relationships between units. This is done in theunit_dependencies
module. - Construct the
BuildContext
with all of the information collected so far. This is the end of the "front end" of compilation. - Create a
Context
, a large, mutable data structure that coordinates the compilation process. - The
Context
will create aJobQueue
, a data structure that tracks which units need to be built. drain_the_queue
does the compilation process. This is the only point in Cargo that currently uses threads.- The result of the compilation is stored in the
Compilation
struct. This can be used for various things, such as running tests after the compilation has finished.