From 65a152a5721c923ee8bfd7c5842ee98e7c0311ac Mon Sep 17 00:00:00 2001 From: Ross Sullivan Date: Sat, 22 Nov 2025 21:40:36 +0900 Subject: [PATCH 1/4] feat(unstable): Added -Zfine-grain-locking unstable feature --- src/cargo/core/features.rs | 13 ++++ src/doc/src/reference/unstable.md | 9 +++ tests/testsuite/cargo/z_help/stdout.term.svg | 70 ++++++++++---------- 3 files changed, 58 insertions(+), 34 deletions(-) diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index f9f13dc2951..8acb40a8b1c 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -127,6 +127,7 @@ use std::str::FromStr; use anyhow::{Error, bail}; use cargo_util::ProcessBuilder; use serde::{Deserialize, Serialize}; +use tracing::debug; use crate::GlobalContext; use crate::core::resolver::ResolveBehavior; @@ -861,6 +862,7 @@ unstable_cli_options!( dual_proc_macros: bool = ("Build proc-macros for both the host and the target"), feature_unification: bool = ("Enable new feature unification modes in workspaces"), features: Option>, + fine_grain_locking: bool = ("Use fine grain locking instead of locking the entire build cache"), fix_edition: Option = ("Permanently unstable edition migration helper"), gc: bool = ("Track cache usage and \"garbage collect\" unused files"), #[serde(deserialize_with = "deserialize_git_features")] @@ -1242,6 +1244,9 @@ impl CliUnstable { if self.gitoxide.is_none() && cargo_use_gitoxide_instead_of_git2() { self.gitoxide = GitoxideFeatures::safe().into(); } + + self.implicitly_enable_features_if_needed(); + Ok(warnings) } @@ -1380,6 +1385,7 @@ impl CliUnstable { "direct-minimal-versions" => self.direct_minimal_versions = parse_empty(k, v)?, "dual-proc-macros" => self.dual_proc_macros = parse_empty(k, v)?, "feature-unification" => self.feature_unification = parse_empty(k, v)?, + "fine-grain-locking" => self.fine_grain_locking = parse_empty(k, v)?, "fix-edition" => { let fe = v .ok_or_else(|| anyhow::anyhow!("-Zfix-edition expected a value"))? @@ -1512,6 +1518,13 @@ impl CliUnstable { ); } } + + fn implicitly_enable_features_if_needed(&mut self) { + if self.fine_grain_locking && !self.build_dir_new_layout { + debug!("-Zbuild-dir-new-layout implicitly enabled by -Zfine-grain-locking"); + self.build_dir_new_layout = true; + } + } } /// Returns the current release channel ("stable", "beta", "nightly", "dev"). diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md index 9872e709d04..99d92d1812e 100644 --- a/src/doc/src/reference/unstable.md +++ b/src/doc/src/reference/unstable.md @@ -98,6 +98,7 @@ Each new feature described below should explain how to use it. * [open-namespaces](#open-namespaces) --- Allow multiple packages to participate in the same API namespace * [panic-immediate-abort](#panic-immediate-abort) --- Passes `-Cpanic=immediate-abort` to the compiler. * [compile-time-deps](#compile-time-deps) --- Perma-unstable feature for rust-analyzer + * [fine-grain-locking](#fine-grain-locking) --- Use fine grain locking instead of locking the entire build cache * rustdoc * [rustdoc-map](#rustdoc-map) --- Provides mappings for documentation to link to external sites like [docs.rs](https://docs.rs/). * [scrape-examples](#scrape-examples) --- Shows examples within documentation. @@ -1735,6 +1736,14 @@ panic-immediate-abort = true panic = "immediate-abort" ``` +## fine-grain-locking + +* Tracking Issue: [#4282](https://github.com/rust-lang/cargo/issues/4282) + +Use fine grain locking instead of locking the entire build cache. + +Note: Fine grain locking implicitly enables [build-dir-new-layout](#build-dir-new-layout) as fine grain locking builds on that directory reoganization. + ## `[lints.cargo]` * Tracking Issue: [#12235](https://github.com/rust-lang/cargo/issues/12235) diff --git a/tests/testsuite/cargo/z_help/stdout.term.svg b/tests/testsuite/cargo/z_help/stdout.term.svg index f3354ac179b..ee4a90279a2 100644 --- a/tests/testsuite/cargo/z_help/stdout.term.svg +++ b/tests/testsuite/cargo/z_help/stdout.term.svg @@ -1,4 +1,4 @@ - +