Skip to content

Commit 457c4bc

Browse files
committed
Work-around macOS 10.15 Gatekeeper issue.
1 parent 0a2f691 commit 457c4bc

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

crates/cargo-test-support/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,10 @@ fn _process(t: &OsStr) -> cargo::util::ProcessBuilder {
17411741
.env_remove("GIT_COMMITTER_NAME")
17421742
.env_remove("GIT_COMMITTER_EMAIL")
17431743
.env_remove("MSYSTEM"); // assume cmd.exe everywhere on windows
1744+
if cfg!(target_os = "macos") {
1745+
// Work-around a bug in macOS 10.15, see `link_or_copy` for details.
1746+
p.env("__CARGO_COPY_DONT_LINK_DO_NOT_USE_THIS", "1");
1747+
}
17441748
p
17451749
}
17461750

src/cargo/util/paths.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,20 @@ fn _link_or_copy(src: &Path, dst: &Path) -> CargoResult<()> {
379379
};
380380
symlink(src, dst)
381381
} else {
382-
fs::hard_link(src, dst)
382+
if env::var_os("__CARGO_COPY_DONT_LINK_DO_NOT_USE_THIS").is_some() {
383+
// This is a work-around for a bug in macOS 10.15. When running on
384+
// APFS, there seems to be a strange race condition with
385+
// Gatekeeper where it will forcefully kill a process launched via
386+
// `cargo run` with SIGKILL. Copying seems to avoid the problem.
387+
// This shouldn't affect anyone except Cargo's test suite because
388+
// it is very rare, and only seems to happen under heavy load and
389+
// rapidly creating lots of executables and running them.
390+
// See https://github.com/rust-lang/cargo/issues/7821 for the
391+
// gory details.
392+
fs::copy(src, dst).map(|_| ())
393+
} else {
394+
fs::hard_link(src, dst)
395+
}
383396
};
384397
link_result
385398
.or_else(|err| {

0 commit comments

Comments
 (0)