78
78
//! [`CompileKind`] (host/target) | ✓ | ✓ | ✓ | ✓
79
79
//! `__CARGO_DEFAULT_LIB_METADATA`[^4] | | ✓ | ✓ | ✓
80
80
//! `package_id` | | ✓ | ✓ | ✓
81
- //! authors, description, homepage, repo | ✓ | | |
82
81
//! Target src path relative to ws | ✓ | | |
83
82
//! Target flags (test/bench/for_host/edition) | ✓ | | |
84
83
//! -C incremental=… flag | ✓ | | |
189
188
//! files to learn about environment variables that the rustc compile depends on.
190
189
//! Cargo then later uses this to trigger a recompile if a referenced env var
191
190
//! changes (even if the source didn't change).
191
+ //! This also includes env vars generated from Cargo metadata like `CARGO_PKG_DESCRIPTION`.
192
+ //! (See [`EmittablePackageMetadata`])
192
193
//!
193
194
//! #### dep-info files for build system integration.
194
195
//!
371
372
mod dep_info;
372
373
mod dirty_reason;
373
374
375
+ use std:: borrow:: Cow ;
374
376
use std:: collections:: hash_map:: { Entry , HashMap } ;
375
377
use std:: env;
376
378
use std:: fs;
377
379
use std:: fs:: File ;
378
380
use std:: hash:: { self , Hash , Hasher } ;
379
381
use std:: io:: { self } ;
380
382
use std:: path:: { Path , PathBuf } ;
383
+ use std:: str:: FromStr ;
381
384
use std:: sync:: { Arc , Mutex } ;
382
385
use std:: time:: SystemTime ;
383
386
@@ -391,6 +394,7 @@ use serde::{Deserialize, Serialize};
391
394
use tracing:: { debug, info} ;
392
395
393
396
use crate :: core:: compiler:: unit_graph:: UnitDep ;
397
+ use crate :: core:: package:: EmittablePackageMetadata ;
394
398
use crate :: core:: Package ;
395
399
use crate :: util;
396
400
use crate :: util:: errors:: CargoResult ;
@@ -612,10 +616,6 @@ pub struct Fingerprint {
612
616
memoized_hash : Mutex < Option < u64 > > ,
613
617
/// RUSTFLAGS/RUSTDOCFLAGS environment variable value (or config value).
614
618
rustflags : Vec < String > ,
615
- /// Hash of some metadata from the manifest, such as "authors", or
616
- /// "description", which are exposed as environment variables during
617
- /// compilation.
618
- metadata : u64 ,
619
619
/// Hash of various config settings that change how things are compiled.
620
620
config : u64 ,
621
621
/// The rustc target. This is only relevant for `.json` files, otherwise
@@ -831,11 +831,12 @@ impl LocalFingerprint {
831
831
& self ,
832
832
mtime_cache : & mut HashMap < PathBuf , FileTime > ,
833
833
checksum_cache : & mut HashMap < PathBuf , Checksum > ,
834
- pkg_root : & Path ,
834
+ pkg : & Package ,
835
835
target_root : & Path ,
836
836
cargo_exe : & Path ,
837
837
gctx : & GlobalContext ,
838
838
) -> CargoResult < Option < StaleItem > > {
839
+ let pkg_root = pkg. root ( ) ;
839
840
match self {
840
841
// We need to parse `dep_info`, learn about the crate's dependencies.
841
842
//
@@ -849,6 +850,18 @@ impl LocalFingerprint {
849
850
return Ok ( Some ( StaleItem :: MissingFile ( dep_info) ) ) ;
850
851
} ;
851
852
for ( key, previous) in info. env . iter ( ) {
853
+ if let Ok ( t) = EmittablePackageMetadata :: from_str ( key. as_str ( ) ) {
854
+ let value = pkg. emitted_env_var ( & t) ;
855
+ let value = match value {
856
+ Cow :: Borrowed ( v) => v,
857
+ Cow :: Owned ( ref v) => v. as_str ( ) ,
858
+ } ;
859
+
860
+ if Some ( value) == previous. as_deref ( ) {
861
+ continue ;
862
+ }
863
+ }
864
+
852
865
let current = if key == CARGO_ENV {
853
866
Some ( cargo_exe. to_str ( ) . ok_or_else ( || {
854
867
format_err ! (
@@ -932,7 +945,6 @@ impl Fingerprint {
932
945
local : Mutex :: new ( Vec :: new ( ) ) ,
933
946
memoized_hash : Mutex :: new ( None ) ,
934
947
rustflags : Vec :: new ( ) ,
935
- metadata : 0 ,
936
948
config : 0 ,
937
949
compile_kind : 0 ,
938
950
fs_status : FsStatus :: Stale ,
@@ -995,9 +1007,6 @@ impl Fingerprint {
995
1007
new : self . rustflags . clone ( ) ,
996
1008
} ;
997
1009
}
998
- if self . metadata != old. metadata {
999
- return DirtyReason :: MetadataChanged ;
1000
- }
1001
1010
if self . config != old. config {
1002
1011
return DirtyReason :: ConfigSettingsChanged ;
1003
1012
}
@@ -1142,13 +1151,14 @@ impl Fingerprint {
1142
1151
& mut self ,
1143
1152
mtime_cache : & mut HashMap < PathBuf , FileTime > ,
1144
1153
checksum_cache : & mut HashMap < PathBuf , Checksum > ,
1145
- pkg_root : & Path ,
1154
+ pkg : & Package ,
1146
1155
target_root : & Path ,
1147
1156
cargo_exe : & Path ,
1148
1157
gctx : & GlobalContext ,
1149
1158
) -> CargoResult < ( ) > {
1150
1159
assert ! ( !self . fs_status. up_to_date( ) ) ;
1151
1160
1161
+ let pkg_root = pkg. root ( ) ;
1152
1162
let mut mtimes = HashMap :: new ( ) ;
1153
1163
1154
1164
// Get the `mtime` of all outputs. Optionally update their mtime
@@ -1249,7 +1259,7 @@ impl Fingerprint {
1249
1259
if let Some ( item) = local. find_stale_item (
1250
1260
mtime_cache,
1251
1261
checksum_cache,
1252
- pkg_root ,
1262
+ pkg ,
1253
1263
target_root,
1254
1264
cargo_exe,
1255
1265
gctx,
@@ -1279,7 +1289,6 @@ impl hash::Hash for Fingerprint {
1279
1289
profile,
1280
1290
ref deps,
1281
1291
ref local,
1282
- metadata,
1283
1292
config,
1284
1293
compile_kind,
1285
1294
ref rustflags,
@@ -1294,7 +1303,6 @@ impl hash::Hash for Fingerprint {
1294
1303
path,
1295
1304
profile,
1296
1305
& * local,
1297
- metadata,
1298
1306
config,
1299
1307
compile_kind,
1300
1308
rustflags,
@@ -1445,7 +1453,7 @@ fn calculate(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResult
1445
1453
fingerprint. check_filesystem (
1446
1454
& mut build_runner. mtime_cache ,
1447
1455
& mut build_runner. checksum_cache ,
1448
- unit. pkg . root ( ) ,
1456
+ & unit. pkg ,
1449
1457
& target_root,
1450
1458
cargo_exe,
1451
1459
build_runner. bcx . gctx ,
@@ -1529,9 +1537,6 @@ fn calculate_normal(
1529
1537
build_runner. lto [ unit] ,
1530
1538
unit. pkg . manifest ( ) . lint_rustflags ( ) ,
1531
1539
) ) ;
1532
- // Include metadata since it is exposed as environment variables.
1533
- let m = unit. pkg . manifest ( ) . metadata ( ) ;
1534
- let metadata = util:: hash_u64 ( ( & m. authors , & m. description , & m. homepage , & m. repository ) ) ;
1535
1540
let mut config = StableHasher :: new ( ) ;
1536
1541
if let Some ( linker) = build_runner. compilation . target_linker ( unit. kind ) {
1537
1542
linker. hash ( & mut config) ;
@@ -1560,7 +1565,6 @@ fn calculate_normal(
1560
1565
deps,
1561
1566
local : Mutex :: new ( local) ,
1562
1567
memoized_hash : Mutex :: new ( None ) ,
1563
- metadata,
1564
1568
config : Hasher :: finish ( & config) ,
1565
1569
compile_kind,
1566
1570
rustflags : extra_flags,
0 commit comments