Skip to content

Commit f93929d

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

File tree

4 files changed

+72
-34
lines changed

4 files changed

+72
-34
lines changed

src/cargo/core/features.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,7 @@ unstable_cli_options!(
861861
dual_proc_macros: bool = ("Build proc-macros for both the host and the target"),
862862
feature_unification: bool = ("Enable new feature unification modes in workspaces"),
863863
features: Option<Vec<String>>,
864+
fine_grain_locking: bool = ("Use fine grain locking instead of locking the entire build cache"),
864865
fix_edition: Option<FixEdition> = ("Permanently unstable edition migration helper"),
865866
gc: bool = ("Track cache usage and \"garbage collect\" unused files"),
866867
#[serde(deserialize_with = "deserialize_git_features")]
@@ -1241,6 +1242,9 @@ impl CliUnstable {
12411242
if self.gitoxide.is_none() && cargo_use_gitoxide_instead_of_git2() {
12421243
self.gitoxide = GitoxideFeatures::safe().into();
12431244
}
1245+
1246+
self.fail_if_incompatible_opts()?;
1247+
12441248
Ok(warnings)
12451249
}
12461250

@@ -1379,6 +1383,7 @@ impl CliUnstable {
13791383
"direct-minimal-versions" => self.direct_minimal_versions = parse_empty(k, v)?,
13801384
"dual-proc-macros" => self.dual_proc_macros = parse_empty(k, v)?,
13811385
"feature-unification" => self.feature_unification = parse_empty(k, v)?,
1386+
"fine-grain-locking" => self.fine_grain_locking = parse_empty(k, v)?,
13821387
"fix-edition" => {
13831388
let fe = v
13841389
.ok_or_else(|| anyhow::anyhow!("-Zfix-edition expected a value"))?
@@ -1510,6 +1515,14 @@ impl CliUnstable {
15101515
);
15111516
}
15121517
}
1518+
1519+
fn fail_if_incompatible_opts(&self) -> CargoResult<()> {
1520+
if self.fine_grain_locking && !self.build_dir_new_layout {
1521+
bail!("-Z fine-grain-locking requires -Z build-dir-new-layout");
1522+
}
1523+
1524+
Ok(())
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 also requires enabling the [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

tests/testsuite/features.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,3 +2368,17 @@ fn invalid_feature_name_slash_error() {
23682368
"#]])
23692369
.run();
23702370
}
2371+
2372+
#[cargo_test]
2373+
fn fine_grain_locking_should_require_new_build_dir_layout() {
2374+
let p = project().file("src/main.rs", "").build();
2375+
2376+
p.cargo("-Zfine-grain-locking check")
2377+
.masquerade_as_nightly_cargo(&["fine grain locking flag"])
2378+
.with_status(101)
2379+
.with_stderr_data(str![[r#"
2380+
[ERROR] -Z fine-grain-locking requires -Z build-dir-new-layout
2381+
2382+
"#]])
2383+
.run();
2384+
}

0 commit comments

Comments
 (0)