Skip to content

Commit ff1e4eb

Browse files
committed
Auto merge of #11850 - epage:file, r=weihanglo
docs(contrib): Create a file overview in the nightly docs This is a follow up to #11809. On top of what was in the old contrib, I added links out for `.cargo/config.toml`. I'm assuming there are more files that would be worth indexing here but we can add those over time. My focus was on linking to the high-detail documentation. In some cases, this meant increasing visibility to make rustdoc happy. In the registry case, `sources::registry` is a great document to link to so I instead dropped links that rustdoc couldn't handle as they were to details covered in the bigger document or can easily be derived from it. The rest of the file docs will need to be handled in a different way as they are details for people implementing file system interactions.
2 parents 4a3c588 + 9836deb commit ff1e4eb

File tree

4 files changed

+28
-45
lines changed

4 files changed

+28
-45
lines changed

src/cargo/core/compiler/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ mod custom_build;
4343
pub(crate) mod fingerprint;
4444
pub mod future_incompat;
4545
pub(crate) mod job_queue;
46-
mod layout;
46+
pub(crate) mod layout;
4747
mod links;
4848
mod lto;
4949
mod output_depinfo;

src/cargo/core/resolver/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub use self::version_prefs::{VersionOrdering, VersionPreferences};
7878
mod conflict_cache;
7979
mod context;
8080
mod dep_cache;
81-
mod encode;
81+
pub(crate) mod encode;
8282
pub(crate) mod errors;
8383
pub mod features;
8484
mod resolve;

src/cargo/lib.rs

+25
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
//!
2323
//! ## Overview
2424
//!
25+
//! Major components of cargo include:
26+
//!
2527
//! - [`ops`]:
2628
//! Every major operation is implemented here. Each command is a thin wrapper around ops.
2729
//! - [`ops::cargo_compile`]:
@@ -96,6 +98,29 @@
9698
//! This is a dedicated package that defines tests for the [dependency
9799
//! resolver][core::resolver].
98100
//!
101+
//! ### File Overview
102+
//!
103+
//! Files that interact with cargo include
104+
//!
105+
//! - Package
106+
//! - `Cargo.toml`: User-written project manifest, loaded with [`util::toml::TomlManifest`] and then
107+
//! translated to [`core::manifest::Manifest`] which maybe stored in a [`core::Package`].
108+
//! - This is editable with [`util::toml_mut::manifest::LocalManifest`]
109+
//! - `Cargo.lock`: Generally loaded with [`ops::resolve_ws`] or a variant of it into a [`core::resolver::Resolve`]
110+
//! - At the lowest level, [`ops::load_pkg_lockfile`] and [`ops::write_pkg_lockfile`] are used
111+
//! - See [`core::resolver::encode`] for versioning of `Cargo.lock`
112+
//! - `target/`: Used for build artifacts and abstracted with [`core::compiler::layout`]. `Layout` handles locking the target directory and providing paths to parts inside. There is a separate `Layout` for each build `target`.
113+
//! - `target/debug/.fingerprint`: Tracker whether nor not a crate needs to be rebuilt. See [`core::compiler::fingerprint`]
114+
//! - `$CARGO_HOME/`:
115+
//! - `registry/`: Package registry cache which is managed in [`sources::registry`]. Be careful
116+
//! as the lock [`util::Config::acquire_package_cache_lock`] must be manually acquired.
117+
//! - `index`/: Fast-to-access crate metadata (no need to download / extract `*.crate` files)
118+
//! - `cache/*/*.crate`: Local cache of published crates
119+
//! - `src/*/*`: Extracted from `*.crate` by [`sources::registry::RegistrySource`]
120+
//! - `git/`: Git source cache. See [`sources::git`].
121+
//! - `**/.cargo/config.toml`: Environment dependent (env variables, files) configuration. See
122+
//! [`util::config`]
123+
//!
99124
//! ## Contribute to Cargo documentations
100125
//!
101126
//! The Cargo team always continues improving all external and internal documentations.

src/doc/contrib/src/architecture/files.md

+1-43
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,6 @@
11
# Files
22

3-
This chapter gives some pointers on where to start looking at Cargo's on-disk
4-
data file structures.
5-
6-
* [`Layout`] is the abstraction for the `target` directory. It handles locking
7-
the target directory, and providing paths to the parts inside. There is a
8-
separate `Layout` for each "target".
9-
* [`Resolve`] contains the contents of the `Cargo.lock` file. See the [`encode`]
10-
module for the different `Cargo.lock` formats.
11-
* [`TomlManifest`] contains the contents of the `Cargo.toml` file. It is translated
12-
to a [`Manifest`] object for some simplification, and the `Manifest` is stored
13-
in a [`Package`].
14-
* The [`fingerprint`] module deals with the fingerprint information stored in
15-
`target/debug/.fingerprint`. This tracks whether or not a crate needs to be
16-
rebuilt.
17-
* `cargo install` tracks its installed files with some metadata in
18-
`$CARGO_HOME`. The metadata is managed in the
19-
[`common_for_install_and_uninstall`] module.
20-
* Git sources are cached in `$CARGO_HOME/git`. The code for this cache is in
21-
the [`git`] source module.
22-
* Registries are cached in `$CARGO_HOME/registry`. There are three parts, the
23-
index, the compressed `.crate` files, and the extracted sources of those
24-
crate files.
25-
* Management of the registry cache can be found in the [`registry`] source
26-
module. Note that this includes an on-disk cache as an optimization for
27-
accessing the git repository.
28-
* Saving of `.crate` files is handled by the [`RemoteRegistry`].
29-
* Extraction of `.crate` files is handled by the [`RegistrySource`].
30-
* There is a lock for the package cache. Code must be careful, because
31-
this lock must be obtained manually. See
32-
[`Config::acquire_package_cache_lock`].
33-
34-
[`Layout`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/core/compiler/layout.rs
35-
[`Resolve`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/core/resolver/resolve.rs
36-
[`encode`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/core/resolver/encode.rs
37-
[`TomlManifest`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/util/toml/mod.rs
38-
[`Manifest`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/core/manifest.rs
39-
[`Package`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/core/package.rs
40-
[`common_for_install_and_uninstall`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/ops/common_for_install_and_uninstall.rs
41-
[`git`]: https://github.com/rust-lang/cargo/tree/master/src/cargo/sources/git
42-
[`registry`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/sources/registry/mod.rs
43-
[`RemoteRegistry`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/sources/registry/remote.rs
44-
[`RegistrySource`]: https://github.com/rust-lang/cargo/blob/master/src/cargo/sources/registry/mod.rs
45-
[`Config::acquire_package_cache_lock`]: https://github.com/rust-lang/cargo/blob/e4b65bdc80f2a293447f2f6a808fa7c84bf9a357/src/cargo/util/config/mod.rs#L1261-L1266
3+
See [nightly docs](https://doc.rust-lang.org/nightly/nightly-rustc/cargo/index.html)
464

475
## Filesystems
486

0 commit comments

Comments
 (0)