Skip to content

Commit e148231

Browse files
committed
docs(contrib): Point compilation docs to doc comments
I also verified that `src/cargo/lib.rs` points people to this location for learning about compilation.
1 parent 9855f92 commit e148231

File tree

3 files changed

+20
-48
lines changed

3 files changed

+20
-48
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ mod crate_type;
4242
mod custom_build;
4343
pub(crate) mod fingerprint;
4444
pub mod future_incompat;
45-
mod job_queue;
45+
pub(crate) mod job_queue;
4646
mod layout;
4747
mod links;
4848
mod lto;

src/cargo/ops/cargo_compile/mod.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,35 @@
66
//! The [`compile`] function will do all the work to compile a workspace. A
77
//! rough outline is:
88
//!
9-
//! - Resolve the dependency graph (see [`ops::resolve`]).
10-
//! - Download any packages needed (see [`PackageSet`](crate::core::PackageSet)).
11-
//! - Generate a list of top-level "units" of work for the targets the user
9+
//! 1. Resolve the dependency graph (see [`ops::resolve`]).
10+
//! 2. Download any packages needed (see [`PackageSet`](crate::core::PackageSet)).
11+
//! 3. Generate a list of top-level "units" of work for the targets the user
1212
//! requested on the command-line. Each [`Unit`] corresponds to a compiler
1313
//! invocation. This is done in this module ([`UnitGenerator::generate_root_units`]).
14-
//! - Build the graph of `Unit` dependencies (see [`unit_dependencies`]).
15-
//! - Create a [`Context`] which will perform the following steps:
16-
//! - Prepare the `target` directory (see [`Layout`]).
17-
//! - Create a job queue (see `JobQueue`). The queue checks the
14+
//! 4. Starting from the root [`Unit`]s, generate the [`UnitGraph`] by walking the dependency graph
15+
//! from the resolver. See also [`unit_dependencies`].
16+
//! 5. Construct the [`BuildContext`] with all of the information collected so
17+
//! far. This is the end of the "front end" of compilation.
18+
//! 6. Create a [`Context`] which oordinates the compilation process a
19+
//! and will perform the following steps:
20+
//! 1. Prepare the `target` directory (see [`Layout`]).
21+
//! 2. Create a [`JobQueue`]. The queue checks the
1822
//! fingerprint of each `Unit` to determine if it should run or be
1923
//! skipped.
20-
//! - Execute the queue. Each leaf in the queue's dependency graph is
21-
//! executed, and then removed from the graph when finished. This
22-
//! repeats until the queue is empty.
24+
//! 3. Execute the queue via [`drain_the_queue`]. Each leaf in the queue's dependency graph is
25+
//! executed, and then removed from the graph when finished. This repeats until the queue is
26+
//! empty. Note that this is the only point in cargo that currently uses threads.
27+
//! 7. The result of the compilation is stored in the [`Compilation`] struct. This can be used for
28+
//! various things, such as running tests after the compilation has finished.
2329
//!
2430
//! **Note**: "target" inside this module generally refers to ["Cargo Target"],
2531
//! which corresponds to artifact that will be built in a package. Not to be
2632
//! confused with target-triple or target architecture.
2733
//!
2834
//! [`unit_dependencies`]: crate::core::compiler::unit_dependencies
2935
//! [`Layout`]: crate::core::compiler::Layout
36+
//! [`JobQueue`]: crate::core::compiler::job_queue
37+
//! [`drain_the_queue`]: crate::core::compiler::job_queue
3038
//! ["Cargo Target"]: https://doc.rust-lang.org/nightly/cargo/reference/cargo-targets.html
3139
3240
use std::collections::{HashMap, HashSet};
Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,3 @@
11
# Compilation
22

3-
The [`Unit`] is the primary data structure representing a single execution of
4-
the compiler. It (mostly) contains all the information needed to determine
5-
which flags to pass to the compiler.
6-
7-
The entry to the compilation process is located in the [`cargo_compile`]
8-
module. The compilation can be conceptually broken into these steps:
9-
10-
1. Perform dependency resolution (see [the resolution chapter]).
11-
2. Generate the root `Unit`s, the things the user requested to compile on the
12-
command-line. This is done in the [`unit_generator`] module.
13-
3. Starting from the root `Unit`s, generate the [`UnitGraph`] by walking the
14-
dependency graph from the resolver. The `UnitGraph` contains all of the
15-
`Unit` structs, and information about the dependency relationships between
16-
units. This is done in the [`unit_dependencies`] module.
17-
4. Construct the [`BuildContext`] with all of the information collected so
18-
far. This is the end of the "front end" of compilation.
19-
5. Create a [`Context`], a large, mutable data structure that coordinates the
20-
compilation process.
21-
6. The [`Context`] will create a [`JobQueue`], a data structure that tracks
22-
which units need to be built.
23-
7. [`drain_the_queue`] does the compilation process. This is the only point in
24-
Cargo that currently uses threads.
25-
8. The result of the compilation is stored in the [`Compilation`] struct. This
26-
can be used for various things, such as running tests after the compilation
27-
has finished.
28-
29-
[`cargo_compile`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/ops/cargo_compile/mod.rs
30-
[`unit_generator`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/ops/cargo_compile/unit_generator.rs
31-
[`UnitGraph`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/core/compiler/unit_graph.rs
32-
[the resolution chapter]: packages.md
33-
[`Unit`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/core/compiler/unit.rs
34-
[`unit_dependencies`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/core/compiler/unit_dependencies.rs
35-
[`BuildContext`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/core/compiler/build_context/mod.rs
36-
[`Context`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/core/compiler/context/mod.rs
37-
[`JobQueue`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/core/compiler/job_queue.rs
38-
[`drain_the_queue`]: https://github.com/rust-lang/cargo/blob/e4b65bdc80f2a293447f2f6a808fa7c84bf9a357/src/cargo/core/compiler/job_queue.rs#L623-L634
39-
[`Compilation`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/core/compiler/compilation.rs
3+
See [nightly docs](https://doc.rust-lang.org/nightly/nightly-rustc/cargo/ops/cargo_compile/index.html)

0 commit comments

Comments
 (0)