Skip to content

add Cargo.lock to CI-rustc allowed list for non-CI env #142232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
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
51 changes: 32 additions & 19 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,39 @@ use crate::utils::channel;
use crate::utils::helpers::exe;
use crate::{Command, GitInfo, OnceLock, TargetSelection, check_ci_llvm, helpers, output, t};

/// Each path in this list is considered "allowed" in the `download-rustc="if-unchanged"` logic.
/// Each path from this function is considered "allowed" in the `download-rustc="if-unchanged"` logic.
/// This means they can be modified and changes to these paths should never trigger a compiler build
/// when "if-unchanged" is set.
///
/// NOTE: Paths must have the ":!" prefix to tell git to ignore changes in those paths during
/// the diff check.
///
/// WARNING: Be cautious when adding paths to this list. If a path that influences the compiler build
/// is added here, it will cause bootstrap to skip necessary rebuilds, which may lead to risky results.
/// For example, "src/bootstrap" should never be included in this list as it plays a crucial role in the
/// final output/compiler, which can be significantly affected by changes made to the bootstrap sources.
#[rustfmt::skip] // We don't want rustfmt to oneline this list
pub const RUSTC_IF_UNCHANGED_ALLOWED_PATHS: &[&str] = &[
":!library",
":!src/tools",
":!src/librustdoc",
":!src/rustdoc-json-types",
":!tests",
":!triagebot.toml",
];
pub fn rustc_if_unchanged_allowed_paths() -> Vec<&'static str> {
// NOTE: Paths must have the ":!" prefix to tell git to ignore changes in those paths during
// the diff check.
//
// WARNING: Be cautious when adding paths to this list. If a path that influences the compiler build
// is added here, it will cause bootstrap to skip necessary rebuilds, which may lead to risky results.
// For example, "src/bootstrap" should never be included in this list as it plays a crucial role in the
// final output/compiler, which can be significantly affected by changes made to the bootstrap sources.
let mut paths = vec![
":!library",
":!src/tools",
":!src/librustdoc",
":!src/rustdoc-json-types",
":!tests",
":!triagebot.toml",
];

if !CiEnv::is_ci() {
// When a dependency is added/updated/removed in the library tree (or in some tools),
// `Cargo.lock` will be updated by `cargo`. This update will incorrectly invalidate the
// `download-rustc=if-unchanged` cache.
//
// To prevent this, add `Cargo.lock` to the list of allowed paths when not running on CI.
// This is generally safe because changes to dependencies typically involve modifying
// `Cargo.toml`, which would already invalidate the CI-rustc cache on non-allowed paths.
paths.push(":!Cargo.lock");
}

paths
}

/// Global configuration for the entire build and/or bootstrap.
///
Expand Down Expand Up @@ -1503,7 +1516,7 @@ impl Config {
let commit = if self.rust_info.is_managed_git_subrepository() {
// Look for a version to compare to based on the current commit.
// Only commits merged by bors will have CI artifacts.
let freshness = self.check_path_modifications(RUSTC_IF_UNCHANGED_ALLOWED_PATHS);
let freshness = self.check_path_modifications(&rustc_if_unchanged_allowed_paths());
self.verbose(|| {
eprintln!("rustc freshness: {freshness:?}");
});
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/config/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use serde::Deserialize;

use super::flags::Flags;
use super::toml::change_id::ChangeIdWrapper;
use super::{Config, RUSTC_IF_UNCHANGED_ALLOWED_PATHS};
use super::{Config, rustc_if_unchanged_allowed_paths};
use crate::ChangeId;
use crate::core::build_steps::clippy::{LintConfig, get_clippy_rules_in_order};
use crate::core::build_steps::llvm;
Expand Down Expand Up @@ -459,7 +459,7 @@ fn jobs_precedence() {
#[test]
fn check_rustc_if_unchanged_paths() {
let config = parse("");
let normalised_allowed_paths: Vec<_> = RUSTC_IF_UNCHANGED_ALLOWED_PATHS
let normalised_allowed_paths: Vec<_> = rustc_if_unchanged_allowed_paths()
.iter()
.map(|t| {
t.strip_prefix(":!").expect(&format!("{t} doesn't have ':!' prefix, but it should."))
Expand Down
Loading