From 3487bdd23d34af9331e1d0aa5d5f868fa52c1de3 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 15 Nov 2024 15:31:20 -0600 Subject: [PATCH] docs(fingerprint): Track each use of Metadata separately --- .../build_runner/compilation_files.rs | 8 +-- src/cargo/core/compiler/fingerprint/mod.rs | 66 ++++++++++--------- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/cargo/core/compiler/build_runner/compilation_files.rs b/src/cargo/core/compiler/build_runner/compilation_files.rs index 4203a0d46b5a..a65bf1540e0f 100644 --- a/src/cargo/core/compiler/build_runner/compilation_files.rs +++ b/src/cargo/core/compiler/build_runner/compilation_files.rs @@ -41,10 +41,10 @@ impl fmt::Debug for UnitHash { } } -/// The `Metadata` is a hash used to make unique file names for each unit in a -/// build. It is also used for symbol mangling. +/// [`Metadata`] tracks several [`UnitHash`]s, including +/// [`Metadata::unit_id`], [`Metadata::c_metadata`], and [`Metadata::c_extra_filename`]. /// -/// For example: +/// [`Metadata::c_extra_filename`] is needed for cases like: /// - A project may depend on crate `A` and crate `B`, so the package name must be in the file name. /// - Similarly a project may depend on two versions of `A`, so the version must be in the file name. /// @@ -52,7 +52,7 @@ impl fmt::Debug for UnitHash { /// the same build. This is absolutely required or we override things before /// we get chance to use them. /// -/// It is also used for symbol mangling, because if you have two versions of +/// [`Metadata::c_metadata`] is used for symbol mangling, because if you have two versions of /// the same crate linked together, their symbols need to be differentiated. /// /// We use a hash because it is an easy way to guarantee diff --git a/src/cargo/core/compiler/fingerprint/mod.rs b/src/cargo/core/compiler/fingerprint/mod.rs index d994830c6309..9b0b4d3707a6 100644 --- a/src/cargo/core/compiler/fingerprint/mod.rs +++ b/src/cargo/core/compiler/fingerprint/mod.rs @@ -47,46 +47,48 @@ //! reliable and reproducible builds at the cost of being complex, slow, and //! platform-dependent. //! -//! ## Fingerprints and Metadata +//! ## Fingerprints and [`UnitHash`]s +//! +//! [`Metadata`] tracks several [`UnitHash`]s, including +//! [`Metadata::unit_id`], [`Metadata::c_metadata`], and [`Metadata::c_extra_filename`]. +//! See its documentation for more details. //! -//! The [`Metadata`] hash is a hash added to the output filenames to isolate -//! each unit. See its documentationfor more details. //! NOTE: Not all output files are isolated via filename hashes (like dylibs). //! The fingerprint directory uses a hash, but sometimes units share the same //! fingerprint directory (when they don't have Metadata) so care should be //! taken to handle this! //! -//! Fingerprints and Metadata are similar, and track some of the same things. -//! The Metadata contains information that is required to keep Units separate. +//! Fingerprints and [`UnitHash`]s are similar, and track some of the same things. +//! [`UnitHash`]s contains information that is required to keep Units separate. //! The Fingerprint includes additional information that should cause a //! recompile, but it is desired to reuse the same filenames. A comparison //! of what is tracked: //! -//! Value | Fingerprint | Metadata -//! -------------------------------------------|-------------|---------- -//! rustc | ✓ | ✓ -//! [`Profile`] | ✓ | ✓ -//! `cargo rustc` extra args | ✓ | ✓ -//! [`CompileMode`] | ✓ | ✓ -//! Target Name | ✓ | ✓ -//! `TargetKind` (bin/lib/etc.) | ✓ | ✓ -//! Enabled Features | ✓ | ✓ -//! Declared Features | ✓ | -//! Immediate dependency’s hashes | ✓[^1] | ✓ -//! [`CompileKind`] (host/target) | ✓ | ✓ -//! `__CARGO_DEFAULT_LIB_METADATA`[^4] | | ✓ -//! `package_id` | | ✓ -//! authors, description, homepage, repo | ✓ | -//! Target src path relative to ws | ✓ | -//! Target flags (test/bench/for_host/edition) | ✓ | -//! -C incremental=… flag | ✓ | -//! mtime of sources | ✓[^3] | -//! RUSTFLAGS/RUSTDOCFLAGS | ✓ | -//! [`Lto`] flags | ✓ | ✓ -//! config settings[^5] | ✓ | -//! `is_std` | | ✓ -//! `[lints]` table[^6] | ✓ | -//! `[lints.rust.unexpected_cfgs.check-cfg]` | ✓ | +//! Value | Fingerprint | `Metadata::unit_id` | `Metadata::c_metadata` | `Metadata::c_extra_filename` +//! -------------------------------------------|-------------|---------------------|------------------------|---------- +//! rustc | ✓ | ✓ | ✓ | ✓ +//! [`Profile`] | ✓ | ✓ | ✓ | ✓ +//! `cargo rustc` extra args | ✓ | ✓ | ✓ | ✓ +//! [`CompileMode`] | ✓ | ✓ | ✓ | ✓ +//! Target Name | ✓ | ✓ | ✓ | ✓ +//! `TargetKind` (bin/lib/etc.) | ✓ | ✓ | ✓ | ✓ +//! Enabled Features | ✓ | ✓ | ✓ | ✓ +//! Declared Features | ✓ | | | +//! Immediate dependency’s hashes | ✓[^1] | ✓ | ✓ | ✓ +//! [`CompileKind`] (host/target) | ✓ | ✓ | ✓ | ✓ +//! `__CARGO_DEFAULT_LIB_METADATA`[^4] | | ✓ | ✓ | ✓ +//! `package_id` | | ✓ | ✓ | ✓ +//! authors, description, homepage, repo | ✓ | | | +//! Target src path relative to ws | ✓ | | | +//! Target flags (test/bench/for_host/edition) | ✓ | | | +//! -C incremental=… flag | ✓ | | | +//! mtime of sources | ✓[^3] | | | +//! RUSTFLAGS/RUSTDOCFLAGS | ✓ | | | +//! [`Lto`] flags | ✓ | ✓ | ✓ | ✓ +//! config settings[^5] | ✓ | | | +//! `is_std` | | ✓ | ✓ | ✓ +//! `[lints]` table[^6] | ✓ | | | +//! `[lints.rust.unexpected_cfgs.check-cfg]` | ✓ | | | //! //! [^1]: Build script and bin dependencies are not included. //! @@ -348,6 +350,10 @@ //! //! [`check_filesystem`]: Fingerprint::check_filesystem //! [`Metadata`]: crate::core::compiler::Metadata +//! [`Metadata::unit_id`]: crate::core::compiler::Metadata::unit_id +//! [`Metadata::c_metadata`]: crate::core::compiler::Metadata::c_metadata +//! [`Metadata::c_extra_filename`]: crate::core::compiler::Metadata::c_extra_filename +//! [`UnitHash`]: crate::core::compiler::UnitHash //! [`Profile`]: crate::core::profiles::Profile //! [`CompileMode`]: crate::core::compiler::CompileMode //! [`Lto`]: crate::core::compiler::Lto