Skip to content

Commit 66530cc

Browse files
committed
feat(unstable): Added -Zfine-grain-locking unstable feature
1 parent bd97934 commit 66530cc

File tree

3 files changed

+58
-34
lines changed

3 files changed

+58
-34
lines changed

src/cargo/core/features.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ use std::str::FromStr;
127127
use anyhow::{Error, bail};
128128
use cargo_util::ProcessBuilder;
129129
use serde::{Deserialize, Serialize};
130+
use tracing::debug;
130131

131132
use crate::GlobalContext;
132133
use crate::core::resolver::ResolveBehavior;
@@ -861,6 +862,7 @@ unstable_cli_options!(
861862
dual_proc_macros: bool = ("Build proc-macros for both the host and the target"),
862863
feature_unification: bool = ("Enable new feature unification modes in workspaces"),
863864
features: Option<Vec<String>>,
865+
fine_grain_locking: bool = ("Use fine grain locking instead of locking the entire build cache"),
864866
fix_edition: Option<FixEdition> = ("Permanently unstable edition migration helper"),
865867
gc: bool = ("Track cache usage and \"garbage collect\" unused files"),
866868
#[serde(deserialize_with = "deserialize_git_features")]
@@ -1242,6 +1244,9 @@ impl CliUnstable {
12421244
if self.gitoxide.is_none() && cargo_use_gitoxide_instead_of_git2() {
12431245
self.gitoxide = GitoxideFeatures::safe().into();
12441246
}
1247+
1248+
self.implicitly_enable_features_if_needed();
1249+
12451250
Ok(warnings)
12461251
}
12471252

@@ -1380,6 +1385,7 @@ impl CliUnstable {
13801385
"direct-minimal-versions" => self.direct_minimal_versions = parse_empty(k, v)?,
13811386
"dual-proc-macros" => self.dual_proc_macros = parse_empty(k, v)?,
13821387
"feature-unification" => self.feature_unification = parse_empty(k, v)?,
1388+
"fine-grain-locking" => self.fine_grain_locking = parse_empty(k, v)?,
13831389
"fix-edition" => {
13841390
let fe = v
13851391
.ok_or_else(|| anyhow::anyhow!("-Zfix-edition expected a value"))?
@@ -1512,6 +1518,13 @@ impl CliUnstable {
15121518
);
15131519
}
15141520
}
1521+
1522+
fn implicitly_enable_features_if_needed(&mut self) {
1523+
if self.fine_grain_locking && !self.build_dir_new_layout {
1524+
debug!("-Zbuild-dir-new-layout implicitly enabled by -Zfine-grain-locking");
1525+
self.build_dir_new_layout = true;
1526+
}
1527+
}
15151528
}
15161529

15171530
/// Returns the current release channel ("stable", "beta", "nightly", "dev").

src/doc/src/reference/unstable.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Each new feature described below should explain how to use it.
9898
* [open-namespaces](#open-namespaces) --- Allow multiple packages to participate in the same API namespace
9999
* [panic-immediate-abort](#panic-immediate-abort) --- Passes `-Cpanic=immediate-abort` to the compiler.
100100
* [compile-time-deps](#compile-time-deps) --- Perma-unstable feature for rust-analyzer
101+
* [fine-grain-locking](#fine-grain-locking) --- Use fine grain locking instead of locking the entire build cache
101102
* rustdoc
102103
* [rustdoc-map](#rustdoc-map) --- Provides mappings for documentation to link to external sites like [docs.rs](https://docs.rs/).
103104
* [scrape-examples](#scrape-examples) --- Shows examples within documentation.
@@ -1743,6 +1744,14 @@ panic-immediate-abort = true
17431744
panic = "immediate-abort"
17441745
```
17451746

1747+
## fine-grain-locking
1748+
1749+
* Tracking Issue: [#4282](https://github.com/rust-lang/cargo/issues/4282)
1750+
1751+
Use fine grain locking instead of locking the entire build cache.
1752+
1753+
Note: Fine grain locking implicitly enables [build-dir-new-layout](#build-dir-new-layout) as fine grain locking builds on that directory reoganization.
1754+
17461755
## `[lints.cargo]`
17471756

17481757
* Tracking Issue: [#12235](https://github.com/rust-lang/cargo/issues/12235)

tests/testsuite/cargo/z_help/stdout.term.svg

Lines changed: 36 additions & 34 deletions
Loading

0 commit comments

Comments
 (0)