Skip to content

Commit 0b2c38f

Browse files
committed
Auto merge of #11669 - weihanglo:doc, r=epage
doc: more doc comments and intra-doc links
2 parents efd3733 + 679b160 commit 0b2c38f

File tree

6 files changed

+153
-74
lines changed

6 files changed

+153
-74
lines changed

src/cargo/core/compiler/build_context/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ pub use self::target_info::{
4040
/// since it is often too lower-level.
4141
/// Instead, [`ops::create_bcx`] is usually what you are looking for.
4242
///
43+
/// After a `BuildContext` is built, the next stage of building is handled in [`Context`].
44+
///
4345
/// [`Context`]: crate::core::compiler::Context
4446
/// [`ops::create_bcx`]: crate::ops::create_bcx
4547
pub struct BuildContext<'a, 'cfg> {

src/cargo/core/compiler/context/compilation_files.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! See [`CompilationFiles`].
2+
13
use std::collections::HashMap;
24
use std::env;
35
use std::fmt;
@@ -16,7 +18,9 @@ use crate::util::{self, CargoResult, StableHasher};
1618
/// This is a generic version number that can be changed to make
1719
/// backwards-incompatible changes to any file structures in the output
1820
/// directory. For example, the fingerprint files or the build-script
19-
/// output files. Normally cargo updates ship with rustc updates which will
21+
/// output files.
22+
///
23+
/// Normally cargo updates ship with rustc updates which will
2024
/// cause a new hash due to the rustc version changing, but this allows
2125
/// cargo to be extra careful to deal with different versions of cargo that
2226
/// use the same rustc version.
@@ -41,7 +45,7 @@ const METADATA_VERSION: u8 = 2;
4145
///
4246
/// This also acts as the main layer of caching provided by Cargo.
4347
/// For example, we want to cache `cargo build` and `cargo doc` separately, so that running one
44-
/// does not invalidate the artifacts for the other. We do this by including `CompileMode` in the
48+
/// does not invalidate the artifacts for the other. We do this by including [`CompileMode`] in the
4549
/// hash, thus the artifacts go in different folders and do not override each other.
4650
/// If we don't add something that we should have, for this reason, we get the
4751
/// correct output but rebuild more than is needed.
@@ -170,7 +174,9 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
170174

171175
/// Gets the metadata for the given unit.
172176
///
173-
/// See module docs for more details.
177+
/// See [`Metadata`] and [`fingerprint`] module for more.
178+
///
179+
/// [`fingerprint`]: ../../fingerprint/index.html#fingerprints-and-metadata
174180
pub fn metadata(&self, unit: &Unit) -> Metadata {
175181
self.metas[unit].meta_hash
176182
}
@@ -421,6 +427,9 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
421427
Some(uplift_path)
422428
}
423429

430+
/// Calculates the filenames that the given unit will generate.
431+
/// Should use [`CompilationFiles::outputs`] instead
432+
/// as it caches the result of this function.
424433
fn calc_outputs(
425434
&self,
426435
unit: &Unit,
@@ -537,6 +546,11 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
537546
}
538547
}
539548

549+
/// Gets the metadata hash for the given [`Unit`].
550+
///
551+
/// Whne a metadata hash doesn't exist for the given unit,
552+
/// this calls itself recursively to compute metadata hashes of all its dependencies.
553+
/// See [`compute_metadata`] for how a single metadata hash is computed.
540554
fn metadata_of<'a>(
541555
unit: &Unit,
542556
cx: &Context<'_, '_>,
@@ -552,6 +566,7 @@ fn metadata_of<'a>(
552566
&metas[unit]
553567
}
554568

569+
/// Computes the metadata hash for the given [`Unit`].
555570
fn compute_metadata(
556571
unit: &Unit,
557572
cx: &Context<'_, '_>,
@@ -632,6 +647,7 @@ fn compute_metadata(
632647
}
633648
}
634649

650+
/// Hash the version of rustc being used during the build process.
635651
fn hash_rustc_version(bcx: &BuildContext<'_, '_>, hasher: &mut StableHasher) {
636652
let vers = &bcx.rustc().version;
637653
if vers.pre.is_empty() || bcx.config.cli_unstable().separate_nightlies {

src/cargo/core/compiler/context/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! [`Context`] is the mutable state used during the build process.
2+
13
use std::collections::{BTreeSet, HashMap, HashSet};
24
use std::path::{Path, PathBuf};
35
use std::sync::{Arc, Mutex};
@@ -27,6 +29,11 @@ use self::compilation_files::CompilationFiles;
2729
pub use self::compilation_files::{Metadata, OutputFile};
2830

2931
/// Collection of all the stuff that is needed to perform a build.
32+
///
33+
/// Different from the [`BuildContext`], `Context` is a _mutable_ state used
34+
/// throughout the entire build process. Everything is coordinated through this.
35+
///
36+
/// [`BuildContext`]: crate::core::compiler::BuildContext
3037
pub struct Context<'a, 'cfg> {
3138
/// Mostly static information about the build task.
3239
pub bcx: &'a BuildContext<'a, 'cfg>,
@@ -126,6 +133,10 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
126133

127134
/// Starts compilation, waits for it to finish, and returns information
128135
/// about the result of compilation.
136+
///
137+
/// See [`ops::cargo_compile`] for a higher-level view of the compile process.
138+
///
139+
/// [`ops::cargo_compile`]: ../../../ops/cargo_compile/index.html
129140
pub fn compile(mut self, exec: &Arc<dyn Executor>) -> CargoResult<Compilation<'cfg>> {
130141
let mut queue = JobQueue::new(self.bcx);
131142
let mut plan = BuildPlan::new();
@@ -413,7 +424,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
413424
self.primary_packages.contains(&unit.pkg.package_id())
414425
}
415426

416-
/// Returns the list of filenames read by cargo to generate the `BuildContext`
427+
/// Returns the list of filenames read by cargo to generate the [`BuildContext`]
417428
/// (all `Cargo.toml`, etc.).
418429
pub fn build_plan_inputs(&self) -> CargoResult<Vec<PathBuf>> {
419430
// Keep sorted for consistency.
@@ -436,6 +447,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
436447
}
437448
}
438449

450+
/// Check if any output file name collision happens.
451+
/// See <https://github.com/rust-lang/cargo/issues/6313> for more.
439452
fn check_collisions(&self) -> CargoResult<()> {
440453
let mut output_collisions = HashMap::new();
441454
let describe_collision = |unit: &Unit, other_unit: &Unit, path: &PathBuf| -> String {
@@ -608,6 +621,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
608621
self.rmeta_required.contains(unit)
609622
}
610623

624+
/// Used by `-Zjobserver-per-rustc`.
611625
pub fn new_jobserver(&mut self) -> CargoResult<Client> {
612626
let tokens = self.bcx.jobs() as usize;
613627
let client = Client::new(tokens).with_context(|| "failed to create jobserver")?;

src/cargo/core/compiler/crate_type.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
use std::fmt;
22

3+
/// Types of the output artifact that the compiler emits.
4+
/// Usually distributable or linkable either statically or dynamically.
5+
///
6+
/// See <https://doc.rust-lang.org/nightly/reference/linkage.html>.
37
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
48
pub enum CrateType {
59
Bin,
@@ -57,6 +61,12 @@ impl CrateType {
5761
}
5862
}
5963

64+
/// Returns whether production of this crate type requires the object files
65+
/// from dependencies to be available.
66+
///
67+
/// See also [`TargetKind::requires_upstream_objects`].
68+
///
69+
/// [`TargetKind::requires_upstream_objects`]: crate::core::manifest::TargetKind::requires_upstream_objects
6070
pub fn requires_upstream_objects(&self) -> bool {
6171
// "lib" == "rlib" and is a compilation that doesn't actually
6272
// require upstream object files to exist, only upstream metadata

0 commit comments

Comments
 (0)