Merge pull request #4444 from matthewbauer/unset-curproc-arch-affinity

Set kern.curproc_arch_affinity=0 to escape Rosetta
This commit is contained in:
Eelco Dolstra 2021-01-13 12:16:53 +01:00 committed by GitHub
commit 4e9cec79bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -52,6 +52,7 @@
#if __APPLE__
#include <spawn.h>
#include <sys/sysctl.h>
#endif
#include <pwd.h>
@ -2865,6 +2866,10 @@ void DerivationGoal::runChild()
throw SysError("failed to initialize builder");
if (drv->platform == "aarch64-darwin") {
// Unset kern.curproc_arch_affinity so we can escape Rosetta
int affinity = 0;
sysctlbyname("kern.curproc_arch_affinity", NULL, NULL, &affinity, sizeof(affinity));
cpu_type_t cpu = CPU_TYPE_ARM64;
posix_spawnattr_setbinpref_np(&attrp, 1, &cpu, NULL);
} else if (drv->platform == "x86_64-darwin") {