Skip to content

Commit 3faec42

Browse files
authored
Unrolled build for #142232
Rollup merge of #142232 - onur-ozkan:141986, r=Kobzol add `Cargo.lock` to CI-rustc allowed list for non-CI env Changes to dependencies usually require modifying `Cargo.toml`, which would already invalidate the CI-rustc cache if done in non-allowed paths. On non-CI environment, it should be safe to add `Cargo.lock` to the list of allowed paths as there is no real risk aside from a very rare false positive in cases like minor bumps to non-allowed path dependencies without modifying the `Cargo.toml` files. Fixes #141986
2 parents 7c10378 + c3de813 commit 3faec42

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

src/bootstrap/src/core/config/config.rs

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,39 @@ use crate::utils::channel;
5050
use crate::utils::helpers::exe;
5151
use crate::{Command, GitInfo, OnceLock, TargetSelection, check_ci_llvm, helpers, output, t};
5252

53-
/// Each path in this list is considered "allowed" in the `download-rustc="if-unchanged"` logic.
53+
/// Each path from this function is considered "allowed" in the `download-rustc="if-unchanged"` logic.
5454
/// This means they can be modified and changes to these paths should never trigger a compiler build
5555
/// when "if-unchanged" is set.
56-
///
57-
/// NOTE: Paths must have the ":!" prefix to tell git to ignore changes in those paths during
58-
/// the diff check.
59-
///
60-
/// WARNING: Be cautious when adding paths to this list. If a path that influences the compiler build
61-
/// is added here, it will cause bootstrap to skip necessary rebuilds, which may lead to risky results.
62-
/// For example, "src/bootstrap" should never be included in this list as it plays a crucial role in the
63-
/// final output/compiler, which can be significantly affected by changes made to the bootstrap sources.
64-
#[rustfmt::skip] // We don't want rustfmt to oneline this list
65-
pub const RUSTC_IF_UNCHANGED_ALLOWED_PATHS: &[&str] = &[
66-
":!library",
67-
":!src/tools",
68-
":!src/librustdoc",
69-
":!src/rustdoc-json-types",
70-
":!tests",
71-
":!triagebot.toml",
72-
];
56+
pub fn rustc_if_unchanged_allowed_paths() -> Vec<&'static str> {
57+
// NOTE: Paths must have the ":!" prefix to tell git to ignore changes in those paths during
58+
// the diff check.
59+
//
60+
// WARNING: Be cautious when adding paths to this list. If a path that influences the compiler build
61+
// is added here, it will cause bootstrap to skip necessary rebuilds, which may lead to risky results.
62+
// For example, "src/bootstrap" should never be included in this list as it plays a crucial role in the
63+
// final output/compiler, which can be significantly affected by changes made to the bootstrap sources.
64+
let mut paths = vec![
65+
":!library",
66+
":!src/tools",
67+
":!src/librustdoc",
68+
":!src/rustdoc-json-types",
69+
":!tests",
70+
":!triagebot.toml",
71+
];
72+
73+
if !CiEnv::is_ci() {
74+
// When a dependency is added/updated/removed in the library tree (or in some tools),
75+
// `Cargo.lock` will be updated by `cargo`. This update will incorrectly invalidate the
76+
// `download-rustc=if-unchanged` cache.
77+
//
78+
// To prevent this, add `Cargo.lock` to the list of allowed paths when not running on CI.
79+
// This is generally safe because changes to dependencies typically involve modifying
80+
// `Cargo.toml`, which would already invalidate the CI-rustc cache on non-allowed paths.
81+
paths.push(":!Cargo.lock");
82+
}
83+
84+
paths
85+
}
7386

7487
/// Global configuration for the entire build and/or bootstrap.
7588
///
@@ -1503,7 +1516,7 @@ impl Config {
15031516
let commit = if self.rust_info.is_managed_git_subrepository() {
15041517
// Look for a version to compare to based on the current commit.
15051518
// Only commits merged by bors will have CI artifacts.
1506-
let freshness = self.check_path_modifications(RUSTC_IF_UNCHANGED_ALLOWED_PATHS);
1519+
let freshness = self.check_path_modifications(&rustc_if_unchanged_allowed_paths());
15071520
self.verbose(|| {
15081521
eprintln!("rustc freshness: {freshness:?}");
15091522
});

src/bootstrap/src/core/config/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use serde::Deserialize;
1111

1212
use super::flags::Flags;
1313
use super::toml::change_id::ChangeIdWrapper;
14-
use super::{Config, RUSTC_IF_UNCHANGED_ALLOWED_PATHS};
14+
use super::{Config, rustc_if_unchanged_allowed_paths};
1515
use crate::ChangeId;
1616
use crate::core::build_steps::clippy::{LintConfig, get_clippy_rules_in_order};
1717
use crate::core::build_steps::llvm;
@@ -459,7 +459,7 @@ fn jobs_precedence() {
459459
#[test]
460460
fn check_rustc_if_unchanged_paths() {
461461
let config = parse("");
462-
let normalised_allowed_paths: Vec<_> = RUSTC_IF_UNCHANGED_ALLOWED_PATHS
462+
let normalised_allowed_paths: Vec<_> = rustc_if_unchanged_allowed_paths()
463463
.iter()
464464
.map(|t| {
465465
t.strip_prefix(":!").expect(&format!("{t} doesn't have ':!' prefix, but it should."))

0 commit comments

Comments
 (0)