Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/compiler/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1518,15 +1518,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 {
Comment on lines +1521 to +1533
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe something like:

Suggested change
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 {
// Skip environment variables that shouldn't affect caching
const CARGO_SKIP_VARS: &[&str] = &[
"CARGO_MAKEFLAGS", // jobserver info which is extremely non-cacheable
"CARGO_BUILD_JOBS", // does not affect results
"CARGO_TARGET_DIR", // already included in the file paths
"CARGO_BUILD_BUILD_DIR",
"CARGO_BUILD_TARGET_DIR",
"CARGO_CACHE_AUTO_CLEAN_FREQUENCY",
];
const CARGO_SKIP_PREFIXES: &[&str] = &[
"CARGO_REGISTRIES_", // contains non-cacheable secrets, package IDs already identify registries
"CARGO_REGISTRY_", // same as CARGO_REGISTRIES_*
"CARGO_HTTP_", // not relevant
"CARGO_NET_",
"CARGO_TERM_",
"CARGO_ALIAS_",
];
let may_skip = CARGO_SKIP_VARS.contains(&var.as_str())
|| CARGO_SKIP_PREFIXES
.iter()
.any(|prefix| var.starts_with(prefix));
if may_skip {

continue;
}

Expand Down Expand Up @@ -3502,6 +3506,7 @@ proc_macro false
OsString::from("CARGO_BUILD_JOBS"),
OsString::from("ignored"),
),
(OsString::from("CARGO_TERM_COLOR"), OsString::from("never")),
]
.to_vec(),
false,
Expand Down