Module cargo::ops::cargo_compile

source ·
Expand description

The entry point for starting the compilation process for commands like build, test, doc, rustc, etc.

The compile function will do all the work to compile a workspace. A rough outline is:

  1. Resolve the dependency graph (see ops::resolve).
  2. Download any packages needed (see PackageSet.
  3. Generate a list of top-level “units” of work for the targets the user requested on the command-line. Each Unit corresponds to a compiler invocation. This is done in this module (UnitGenerator::generate_root_units).
  4. Starting from the root Units, generate the UnitGraph by walking the dependency graph from the resolver. See also unit_dependencies.
  5. Construct the BuildContext with all of the information collected so far. This is the end of the “front end” of compilation.
  6. Create a Context which coordinates the compilation process and will perform the following steps:
    1. Prepare the target directory (see Layout).
    2. Create a JobQueue. The queue checks the fingerprint of each Unit to determine if it should run or be skipped.
    3. Execute the queue via drain_the_queue. Each leaf in the queue’s dependency graph is executed, and then removed from the graph when finished. This repeats until the queue is empty. Note that this is the only point in cargo that currently uses threads.
  7. 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.

Note: “target” inside this module generally refers to “Cargo Target”, which corresponds to artifact that will be built in a package. Not to be confused with target-triple or target architecture.

Re-exports

Modules

Structs

  • Contains information about how a package should be compiled.

Functions