51
51
//! Immediate dependency’s hashes | ✓[^1] | ✓
52
52
//! Target or Host mode | | ✓
53
53
//! __CARGO_DEFAULT_LIB_METADATA[^4] | | ✓
54
- //! authors, description, homepage | | ✓[^2]
55
54
//! package_id | | ✓
55
+ //! authors, description, homepage, repo | ✓ |
56
56
//! Target src path | ✓ |
57
57
//! Target path relative to ws | ✓ |
58
58
//! Target flags (test/bench/for_host/edition) | ✓ |
59
- //! Edition | ✓ |
60
59
//! -C incremental=… flag | ✓ |
61
60
//! mtime of sources | ✓[^3] |
62
61
//! RUSTFLAGS/RUSTDOCFLAGS | ✓ |
63
62
//!
64
63
//! [^1]: Build script and bin dependencies are not included.
65
64
//!
66
- //! [^2]: This is a bug, see https://github.com/rust-lang/cargo/issues/6208
67
- //!
68
65
//! [^3]: The mtime is only tracked for workspace members and path
69
66
//! dependencies. Git dependencies track the git revision.
70
67
//!
@@ -175,7 +172,7 @@ use serde::de;
175
172
use serde:: ser;
176
173
use serde:: { Deserialize , Serialize } ;
177
174
178
- use crate :: core:: { Edition , Package } ;
175
+ use crate :: core:: Package ;
179
176
use crate :: util;
180
177
use crate :: util:: errors:: { CargoResult , CargoResultExt } ;
181
178
use crate :: util:: paths;
@@ -337,17 +334,34 @@ struct DepFingerprint {
337
334
/// graph.
338
335
#[ derive( Serialize , Deserialize ) ]
339
336
pub struct Fingerprint {
337
+ /// Hash of the version of `rustc` used.
340
338
rustc : u64 ,
339
+ /// Sorted list of cfg features enabled.
341
340
features : String ,
341
+ /// Hash of the `Target` struct, including the target name,
342
+ /// package-relative source path, edition, etc.
342
343
target : u64 ,
344
+ /// Hash of the `Profile`, `CompileMode`, and any extra flags passed via
345
+ /// `cargo rustc` or `cargo rustdoc`.
343
346
profile : u64 ,
347
+ /// Hash of the path to the base source file. This is relative to the
348
+ /// workspace root for path members, or absolute for other sources.
344
349
path : u64 ,
350
+ /// Fingerprints of dependencies.
345
351
deps : Vec < DepFingerprint > ,
352
+ /// Information about the inputs that affect this Unit (such as source
353
+ /// file mtimes or build script environment variables).
346
354
local : Vec < LocalFingerprint > ,
355
+ /// Cached hash of the `Fingerprint` struct. Used to improve performance
356
+ /// for hashing.
347
357
#[ serde( skip_serializing, skip_deserializing) ]
348
358
memoized_hash : Mutex < Option < u64 > > ,
359
+ /// RUSTFLAGS/RUSTDOCFLAGS environment variable value (or config value).
349
360
rustflags : Vec < String > ,
350
- edition : Edition ,
361
+ /// Hash of some metadata from the manifest, such as "authors", or
362
+ /// "description", which are exposed as environment variables during
363
+ /// compilation.
364
+ metadata : u64 ,
351
365
}
352
366
353
367
impl Serialize for DepFingerprint {
@@ -407,8 +421,8 @@ impl Fingerprint {
407
421
deps : Vec :: new ( ) ,
408
422
local : Vec :: new ( ) ,
409
423
memoized_hash : Mutex :: new ( None ) ,
410
- edition : Edition :: Edition2015 ,
411
424
rustflags : Vec :: new ( ) ,
425
+ metadata : 0 ,
412
426
}
413
427
}
414
428
@@ -463,8 +477,8 @@ impl Fingerprint {
463
477
if self . local . len ( ) != old. local . len ( ) {
464
478
bail ! ( "local lens changed" ) ;
465
479
}
466
- if self . edition != old. edition {
467
- bail ! ( "edition changed" )
480
+ if self . metadata != old. metadata {
481
+ bail ! ( "metadata changed" )
468
482
}
469
483
for ( new, old) in self . local . iter ( ) . zip ( & old. local ) {
470
484
match ( new, old) {
@@ -546,12 +560,12 @@ impl hash::Hash for Fingerprint {
546
560
profile,
547
561
ref deps,
548
562
ref local,
549
- edition ,
563
+ metadata ,
550
564
ref rustflags,
551
565
..
552
566
} = * self ;
553
567
(
554
- rustc, features, target, path, profile, local, edition , rustflags,
568
+ rustc, features, target, path, profile, local, metadata , rustflags,
555
569
)
556
570
. hash ( h) ;
557
571
@@ -678,6 +692,9 @@ fn calculate<'a, 'cfg>(
678
692
bcx. rustflags_args ( unit) ?
679
693
} ;
680
694
let profile_hash = util:: hash_u64 ( & ( & unit. profile , unit. mode , bcx. extra_args_for ( unit) ) ) ;
695
+ // Include metadata since it is exposed as environment variables.
696
+ let m = unit. pkg . manifest ( ) . metadata ( ) ;
697
+ let metadata = util:: hash_u64 ( & ( & m. authors , & m. description , & m. homepage , & m. repository ) ) ;
681
698
let fingerprint = Arc :: new ( Fingerprint {
682
699
rustc : util:: hash_u64 ( & bcx. rustc . verbose_version ) ,
683
700
target : util:: hash_u64 ( & unit. target ) ,
@@ -689,7 +706,7 @@ fn calculate<'a, 'cfg>(
689
706
deps,
690
707
local,
691
708
memoized_hash : Mutex :: new ( None ) ,
692
- edition : unit . target . edition ( ) ,
709
+ metadata ,
693
710
rustflags : extra_flags,
694
711
} ) ;
695
712
cx. fingerprints . insert ( * unit, Arc :: clone ( & fingerprint) ) ;
0 commit comments