diff --git a/src/cargo/core/compiler/layout.rs b/src/cargo/core/compiler/layout.rs index d0207db8aea..e754949d7c5 100644 --- a/src/cargo/core/compiler/layout.rs +++ b/src/cargo/core/compiler/layout.rs @@ -103,6 +103,7 @@ use crate::core::Workspace; use crate::core::compiler::CompileTarget; +use crate::util::flock::is_on_nfs_mount; use crate::util::{CargoResult, FileLock}; use cargo_util::paths; use std::path::{Path, PathBuf}; @@ -152,17 +153,21 @@ impl Layout { // For now we don't do any more finer-grained locking on the artifact // directory, so just lock the entire thing for the duration of this // compile. - let artifact_dir_lock = - dest.open_rw_exclusive_create(".cargo-lock", ws.gctx(), "build directory")?; + let artifact_dir_lock = if is_on_nfs_mount(root.as_path_unlocked()) { + None + } else { + Some(dest.open_rw_exclusive_create(".cargo-lock", ws.gctx(), "artifact directory")?) + }; - let build_dir_lock = if root != build_root { + let build_dir_lock = if root == build_root || is_on_nfs_mount(build_root.as_path_unlocked()) + { + None + } else { Some(build_dest.open_rw_exclusive_create( ".cargo-lock", ws.gctx(), "build directory", )?) - } else { - None }; let root = root.into_path_unlocked(); let build_root = build_root.into_path_unlocked(); @@ -222,7 +227,7 @@ pub struct ArtifactDirLayout { timings: PathBuf, /// The lockfile for a build (`.cargo-lock`). Will be unlocked when this /// struct is `drop`ped. - _lock: FileLock, + _lock: Option, } impl ArtifactDirLayout { diff --git a/src/cargo/util/flock.rs b/src/cargo/util/flock.rs index 89613f04a97..5e9d3549040 100644 --- a/src/cargo/util/flock.rs +++ b/src/cargo/util/flock.rs @@ -427,7 +427,7 @@ fn acquire( } #[cfg(all(target_os = "linux", not(target_env = "musl")))] -fn is_on_nfs_mount(path: &Path) -> bool { +pub fn is_on_nfs_mount(path: &Path) -> bool { use std::ffi::CString; use std::mem; use std::os::unix::prelude::*; @@ -445,7 +445,7 @@ fn is_on_nfs_mount(path: &Path) -> bool { } #[cfg(any(not(target_os = "linux"), target_env = "musl"))] -fn is_on_nfs_mount(_path: &Path) -> bool { +pub fn is_on_nfs_mount(_path: &Path) -> bool { false } diff --git a/src/cargo/util/mod.rs b/src/cargo/util/mod.rs index d8416d3e3db..ad2c5b5bc2e 100644 --- a/src/cargo/util/mod.rs +++ b/src/cargo/util/mod.rs @@ -42,7 +42,7 @@ mod dependency_queue; pub mod diagnostic_server; pub mod edit_distance; pub mod errors; -mod flock; +pub mod flock; pub mod frontmatter; pub mod graph; mod hasher;