Skip to content

Commit c9c67c0

Browse files
Add workaround for sporadic kills when building on Macos
1 parent 6d75259 commit c9c67c0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

crates/cargo-util/src/paths.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,18 @@ fn _link_or_copy(src: &Path, dst: &Path) -> Result<()> {
539539
// gory details.
540540
fs::copy(src, dst).map(|_| ())
541541
} else {
542-
fs::hard_link(src, dst)
542+
if cfg!(target_os = "macos") {
543+
// This is a work-around for a bug on macos. There seems to be a race condition
544+
// with APFS when hard-linking binaries. Gatekeeper does not have signing or
545+
// hash informations stored in kernel when running the process. Therefore killing it.
546+
// This problem does not appear when copying files as kernel has time to process it.
547+
// Note that: fs::copy on macos is using CopyOnWrite (syscall fclonefileat) which should be
548+
// as fast as hardlinking.
549+
// See https://github.com/rust-lang/cargo/issues/10060 for the details
550+
fs::copy(src, dst).map(|_| ())
551+
} else {
552+
fs::hard_link(src, dst)
553+
}
543554
};
544555
link_result
545556
.or_else(|err| {

0 commit comments

Comments
 (0)