From 26bb89013e67bcc817d9f3f71178e6e32fa4ce5e Mon Sep 17 00:00:00 2001 From: Kornel Date: Wed, 12 Nov 2025 21:03:23 +0000 Subject: [PATCH] Avoid hashing CARGO_ variables that are redundant or don't affect results --- src/compiler/rust.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/compiler/rust.rs b/src/compiler/rust.rs index c34b110fa..a10f0751d 100644 --- a/src/compiler/rust.rs +++ b/src/compiler/rust.rs @@ -1517,15 +1517,19 @@ where continue; } - // CARGO_MAKEFLAGS will have jobserver info which is extremely non-cacheable. - // CARGO_REGISTRIES_*_TOKEN contains non-cacheable secrets. - // Registry override config doesn't need to be hashed, because deps' package IDs - // already uniquely identify the relevant registries. - // CARGO_BUILD_JOBS only affects Cargo's parallelism, not rustc output. - if var == "CARGO_MAKEFLAGS" - || var.starts_with("CARGO_REGISTRIES_") - || var == "CARGO_BUILD_JOBS" - { + let may_skip = var == "CARGO_MAKEFLAGS" // will have jobserver info which is extremely non-cacheable. + || var == "CARGO_BUILD_JOBS" // does not affect results + || var.starts_with("CARGO_REGISTRIES_") // CARGO_REGISTRIES_*_TOKEN contains non-cacheable secrets, and package IDs already uniquely identify the relevant registries. + || var.starts_with("CARGO_REGISTRY_") // same as CARGO_REGISTRIES_* + || var == "CARGO_TARGET_DIR" // already included in the file paths + || var == "CARGO_BUILD_BUILD_DIR" + || var == "CARGO_BUILD_TARGET_DIR" + || var.starts_with("CARGO_HTTP_") // not relevant + || var.starts_with("CARGO_NET_") + || var.starts_with("CARGO_TERM_") + || var.starts_with("CARGO_ALIAS_") + || var == "CARGO_CACHE_AUTO_CLEAN_FREQUENCY"; + if may_skip { continue; } @@ -3501,6 +3505,7 @@ proc_macro false OsString::from("CARGO_BUILD_JOBS"), OsString::from("ignored"), ), + (OsString::from("CARGO_TERM_COLOR"), OsString::from("never")), ] .to_vec(), false,