Skip to content

Commit 97181c6

Browse files
committed
Auto merge of #13851 - weihanglo:macos, r=epage
refactor: remove unnecessary branch for link binary on macOS
2 parents 9e57a8d + f8aead9 commit 97181c6

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

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

-4
Original file line numberDiff line numberDiff line change
@@ -1286,10 +1286,6 @@ pub trait TestEnv: Sized {
12861286
.env_remove("USER") // not set on some rust-lang docker images
12871287
.env_remove("XDG_CONFIG_HOME") // see #2345
12881288
.env_remove("OUT_DIR"); // see #13204
1289-
if cfg!(target_os = "macos") {
1290-
// Work-around a bug in macOS 10.15, see `link_or_copy` for details.
1291-
self = self.env("__CARGO_COPY_DONT_LINK_DO_NOT_USE_THIS", "1");
1292-
}
12931289
if cfg!(windows) {
12941290
self = self.env("USERPROFILE", paths::home());
12951291
}

crates/cargo-util/src/paths.rs

+10-18
Original file line numberDiff line numberDiff line change
@@ -565,26 +565,18 @@ fn _link_or_copy(src: &Path, dst: &Path) -> Result<()> {
565565
src
566566
};
567567
symlink(src, dst)
568-
} else if env::var_os("__CARGO_COPY_DONT_LINK_DO_NOT_USE_THIS").is_some() {
569-
// This is a work-around for a bug in macOS 10.15. When running on
570-
// APFS, there seems to be a strange race condition with
571-
// Gatekeeper where it will forcefully kill a process launched via
572-
// `cargo run` with SIGKILL. Copying seems to avoid the problem.
573-
// This shouldn't affect anyone except Cargo's test suite because
574-
// it is very rare, and only seems to happen under heavy load and
575-
// rapidly creating lots of executables and running them.
576-
// See https://github.com/rust-lang/cargo/issues/7821 for the
577-
// gory details.
578-
fs::copy(src, dst).map(|_| ())
579568
} else {
580569
if cfg!(target_os = "macos") {
581-
// This is a work-around for a bug on macos. There seems to be a race condition
582-
// with APFS when hard-linking binaries. Gatekeeper does not have signing or
583-
// hash information stored in kernel when running the process. Therefore killing it.
584-
// This problem does not appear when copying files as kernel has time to process it.
585-
// Note that: fs::copy on macos is using CopyOnWrite (syscall fclonefileat) which should be
586-
// as fast as hardlinking.
587-
// See https://github.com/rust-lang/cargo/issues/10060 for the details
570+
// There seems to be a race condition with APFS when hard-linking
571+
// binaries. Gatekeeper does not have signing or hash information
572+
// stored in kernel when running the process. Therefore killing it.
573+
// This problem does not appear when copying files as kernel has
574+
// time to process it. Note that: fs::copy on macos is using
575+
// CopyOnWrite (syscall fclonefileat) which should be as fast as
576+
// hardlinking. See these issues for the details:
577+
//
578+
// * https://github.com/rust-lang/cargo/issues/7821
579+
// * https://github.com/rust-lang/cargo/issues/10060
588580
fs::copy(src, dst).map_or_else(
589581
|e| {
590582
if e.raw_os_error()

0 commit comments

Comments
 (0)