Skip to content

Commit 79ee504

Browse files
refactor(hydro_lang): use fs2 file locking to fix stable build testing #1780 (#1816)
rust-lang/rust#130994 Also configures betterToml formatting --------- Co-authored-by: Copilot <[email protected]> This PR refactors file locking in the hydro_lang deployment code to use fs2 for non-nightly builds, addressing stability issues in build testing. - Always create the project lock file regardless of the Rust channel - Use fs2 file locking for non-nightly builds while retaining the original nightly locking - Add a non-nightly fs2 dependency configuration in Cargo.toml
1 parent fbb5fab commit 79ee504

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

.vscode/settings.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,16 @@
2323
"files.watcherExclude": {
2424
"**/target": true
2525
},
26-
}
26+
"evenBetterToml.formatter.columnWidth": 80,
27+
"evenBetterToml.formatter.compactArrays": true,
28+
"evenBetterToml.formatter.allowedBlankLines": 2,
29+
"evenBetterToml.formatter.trailingNewline": true,
30+
"evenBetterToml.formatter.arrayAutoCollapse": true,
31+
"evenBetterToml.formatter.arrayAutoExpand": true,
32+
"evenBetterToml.formatter.arrayTrailingComma": true,
33+
"evenBetterToml.formatter.compactEntries": false,
34+
"evenBetterToml.formatter.compactInlineTables": false,
35+
"evenBetterToml.formatter.crlf": false,
36+
"evenBetterToml.formatter.indentEntries": false,
37+
"evenBetterToml.formatter.indentTables": false,
38+
}

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hydro_lang/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ tokio-stream = { version = "0.1.3", default-features = false, features = [
6565
toml = { version = "0.8.0", optional = true }
6666
trybuild-internals-api = { version = "1.0.99", optional = true }
6767

68+
# TODO(mingwei): remove once file locking is stable: https://github.com/rust-lang/rust/issues/130994
69+
# build.rs `println!("cargo:rustc-cfg=nightly")` doesn't gate this (happens
70+
# after dependency resolution), but this doesn't hurt to have.
71+
[target.'cfg(not(nightly))'.dependencies]
72+
fs2 = "0.4.0"
73+
6874
[target.'cfg(target_os = "linux")'.dependencies]
6975
chrono = { version = "0.4.39", optional = true }
7076
procfs = { version = "0.17.0", optional = true }

hydro_lang/src/deploy/trybuild.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,12 @@ pub fn create_trybuild()
265265
{
266266
let _concurrent_test_lock = CONCURRENT_TEST_LOCK.lock().unwrap();
267267

268-
#[cfg(nightly)]
269268
let project_lock = File::create(path!(project.dir / ".hydro-trybuild-lock"))?;
269+
// TODO(mingwei): remove cfg once file locking is stable: https://github.com/rust-lang/rust/issues/130994
270270
#[cfg(nightly)]
271271
project_lock.lock()?;
272+
#[cfg(not(nightly))]
273+
fs2::FileExt::lock_exclusive(&project_lock)?;
272274

273275
let manifest_toml = toml::to_string(&project.manifest)?;
274276
write_atomic(manifest_toml.as_ref(), &path!(project.dir / "Cargo.toml"))?;
@@ -309,8 +311,12 @@ fn write_atomic(contents: &[u8], path: &Path) -> Result<(), std::io::Error> {
309311
.create(true)
310312
.truncate(false)
311313
.open(path)?;
314+
315+
// TODO(mingwei): remove cfg once file locking is stable: https://github.com/rust-lang/rust/issues/130994
312316
#[cfg(nightly)]
313317
file.lock()?;
318+
#[cfg(not(nightly))]
319+
fs2::FileExt::lock_exclusive(&file)?;
314320

315321
let mut existing_contents = Vec::new();
316322
file.read_to_end(&mut existing_contents)?;

0 commit comments

Comments
 (0)