pub struct Metadata {
unit_id: UnitHash,
c_metadata: UnitHash,
c_extra_filename: Option<UnitHash>,
}
Expand description
Metadata
tracks several UnitHash
s, including
Metadata::unit_id
, Metadata::c_metadata
, and Metadata::c_extra_filename
.
We use a hash because it is an easy way to guarantee that all the inputs can be converted to a valid path.
Metadata::unit_id
is used to uniquely identify a unit in the build graph.
This serves as a similar role as Metadata::c_extra_filename
in that it uniquely identifies output
on the filesystem except that its always present.
Metadata::c_extra_filename
is needed for cases like:
- A project may depend on crate
A
and crateB
, 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.
This also acts as the main layer of caching provided by Cargo so this must include all things that need to be distinguished in different parts of the same build. This is absolutely required or we override things before we get chance to use them.
For example, we want to cache cargo build
and cargo doc
separately, so that running one
does not invalidate the artifacts for the other. We do this by including CompileMode
in the
hash, thus the artifacts go in different folders and do not override each other.
If we don’t add something that we should have, for this reason, we get the
correct output but rebuild more than is needed.
Some things that need to be tracked to ensure the correct output should definitely not
go in the Metadata
. For example, the modification time of a file, should be tracked to make a
rebuild when the file changes. However, it would be wasteful to include in the Metadata
. The
old artifacts are never going to be needed again. We can save space by just overwriting them.
If we add something that we should not have, for this reason, we get the correct output but take
more space than needed. This makes not including something in Metadata
a form of cache invalidation.
Note that the Fingerprint
is in charge of tracking everything needed to determine if a
rebuild is needed.
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.
You should avoid anything that would interfere with reproducible
builds. For example, any absolute path should be avoided. This is one
reason that RUSTFLAGS
is not in Metadata::c_metadata
, because it often has
absolute paths (like --remap-path-prefix
which is fundamentally used for
reproducible builds and has absolute paths in it). Also, in some cases the
mangled symbols need to be stable between different builds with different
settings. For example, profile-guided optimizations need to swap
RUSTFLAGS
between runs, but needs to keep the same symbol names.
Fields§
§unit_id: UnitHash
§c_metadata: UnitHash
§c_extra_filename: Option<UnitHash>
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Metadata
impl RefUnwindSafe for Metadata
impl Send for Metadata
impl Sync for Metadata
impl Unpin for Metadata
impl UnwindSafe for Metadata
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 32 bytes