@@ -13,6 +13,15 @@ use crate::core::compiler::{CompileMode, CompileTarget, CrateType, FileType, Uni
1313use crate :: core:: { Target , TargetKind , Workspace } ;
1414use crate :: util:: { self , CargoResult , StableHasher } ;
1515
16+ /// This is a generic version number that can be changed to make
17+ /// backwards-incompatible changes to any file structures in the output
18+ /// directory. For example, the fingerprint files or the build-script
19+ /// output files. Normally cargo updates ship with rustc updates which will
20+ /// cause a new hash due to the rustc version changing, but this allows
21+ /// cargo to be extra careful to deal with different versions of cargo that
22+ /// use the same rustc version.
23+ const METADATA_VERSION : u8 = 2 ;
24+
1625/// The `Metadata` is a hash used to make unique file names for each unit in a
1726/// build. It is also use for symbol mangling.
1827///
@@ -162,7 +171,7 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
162171 /// Used for the metadata when `metadata` returns `None`.
163172 pub fn target_short_hash ( & self , unit : & Unit ) -> String {
164173 let hashable = unit. pkg . package_id ( ) . stable_hash ( self . ws . root ( ) ) ;
165- util:: short_hash ( & hashable)
174+ util:: short_hash ( & ( METADATA_VERSION , hashable) )
166175 }
167176
168177 /// Returns the directory where the artifacts for the given unit are
@@ -483,14 +492,7 @@ fn compute_metadata(
483492 }
484493 let mut hasher = StableHasher :: new ( ) ;
485494
486- // This is a generic version number that can be changed to make
487- // backwards-incompatible changes to any file structures in the output
488- // directory. For example, the fingerprint files or the build-script
489- // output files. Normally cargo updates ship with rustc updates which will
490- // cause a new hash due to the rustc version changing, but this allows
491- // cargo to be extra careful to deal with different versions of cargo that
492- // use the same rustc version.
493- 2 . hash ( & mut hasher) ;
495+ METADATA_VERSION . hash ( & mut hasher) ;
494496
495497 // Unique metadata per (name, source, version) triple. This'll allow us
496498 // to pull crates from anywhere without worrying about conflicts.
0 commit comments