Skip to content

Commit 475d030

Browse files
committed
feat(unstable): Added -Zfine-grain-locking unstable feature
1 parent 4f15cc8 commit 475d030

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")]
@@ -1241,6 +1243,9 @@ impl CliUnstable {
12411243
if self.gitoxide.is_none() && cargo_use_gitoxide_instead_of_git2() {
12421244
self.gitoxide = GitoxideFeatures::safe().into();
12431245
}
1246+
1247+
self.implicitly_enable_features_if_needed();
1248+
12441249
Ok(warnings)
12451250
}
12461251

@@ -1379,6 +1384,7 @@ impl CliUnstable {
13791384
"direct-minimal-versions" => self.direct_minimal_versions = parse_empty(k, v)?,
13801385
"dual-proc-macros" => self.dual_proc_macros = parse_empty(k, v)?,
13811386
"feature-unification" => self.feature_unification = parse_empty(k, v)?,
1387+
"fine-grain-locking" => self.fine_grain_locking = parse_empty(k, v)?,
13821388
"fix-edition" => {
13831389
let fe = v
13841390
.ok_or_else(|| anyhow::anyhow!("-Zfix-edition expected a value"))?
@@ -1510,6 +1516,13 @@ impl CliUnstable {
15101516
);
15111517
}
15121518
}
1519+
1520+
fn implicitly_enable_features_if_needed(&mut self) {
1521+
if self.fine_grain_locking && !self.build_dir_new_layout {
1522+
debug!("-Zbuild-dir-new-layout implicitly enabled by -Zfine-grain-locking");
1523+
self.build_dir_new_layout = true;
1524+
}
1525+
}
15131526
}
15141527

15151528
/// 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
@@ -96,6 +96,7 @@ Each new feature described below should explain how to use it.
9696
* [gc](#gc) --- Global cache garbage collection.
9797
* [open-namespaces](#open-namespaces) --- Allow multiple packages to participate in the same API namespace
9898
* [panic-immediate-abort](#panic-immediate-abort) --- Passes `-Cpanic=immediate-abort` to the compiler.
99+
* [fine-grain-locking](#fine-grain-locking) --- Use fine grain locking instead of locking the entire build cache
99100
* rustdoc
100101
* [rustdoc-map](#rustdoc-map) --- Provides mappings for documentation to link to external sites like [docs.rs](https://docs.rs/).
101102
* [scrape-examples](#scrape-examples) --- Shows examples within documentation.
@@ -1709,6 +1710,14 @@ panic-immediate-abort = true
17091710
panic = "immediate-abort"
17101711
```
17111712

1713+
## fine-grain-locking
1714+
1715+
* Tracking Issue: [#4282](https://github.com/rust-lang/cargo/issues/4282)
1716+
1717+
Use fine grain locking instead of locking the entire build cache.
1718+
1719+
Note: Fine grain locking implicitly enables [build-dir-new-layout](#build-dir-new-layout) as fine grain locking builds on that directory reoganization.
1720+
17121721
## `[lints.cargo]`
17131722

17141723
* 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)