Skip to content

Commit 180f599

Browse files
committed
Auto merge of #10196 - charlesroussel:master, r=alexcrichton
Add workaround for sporadic kills when building on Macos This is the workaround for the issue #10060
2 parents b05697d + c9c67c0 commit 180f599

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

crates/cargo-util/src/paths.rs

Lines changed: 12 additions & 1 deletion
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)