aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/platform/darwin.cc
diff options
context:
space:
mode:
authorArtemis Tosini <lix@artem.ist>2024-05-12 21:09:26 +0000
committerjade <lix@jade.fyi>2024-06-23 03:33:07 +0000
commit12f5d27363316df8e04af1e2e376c39588e12057 (patch)
tree2605bc59d499c851f169678701e9827db180e366 /src/libstore/platform/darwin.cc
parentda4e46dd1fc04067b5ba4bc16dd68134fa7efad2 (diff)
libstore: Start creating LocalDerivationGoal subclasses
LocalDerivationGoal includes a large number of low-level sandboxing primitives for Darwin and Linux, intermingled with ifdefs. Start creating platform-specific classes to make it easier to add new platforms and review platform-specific code. This change only creates support infrastructure and moves two function, more functions will be moved in future changes. Change-Id: I9fc29fa2a7345107d4fc96c46fa90b4eabf6bb89
Diffstat (limited to 'src/libstore/platform/darwin.cc')
-rw-r--r--src/libstore/platform/darwin.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/libstore/platform/darwin.cc b/src/libstore/platform/darwin.cc
index bbb81784c..83b4b4183 100644
--- a/src/libstore/platform/darwin.cc
+++ b/src/libstore/platform/darwin.cc
@@ -6,6 +6,7 @@
#include <sys/proc_info.h>
#include <sys/sysctl.h>
#include <libproc.h>
+#include <spawn.h>
#include <regex>
@@ -220,4 +221,29 @@ void DarwinLocalStore::findPlatformRoots(UncheckedRoots & unchecked)
}
}
}
+
+void DarwinLocalDerivationGoal::execBuilder(std::string builder, Strings args, Strings envStrs)
+{
+ posix_spawnattr_t attrp;
+
+ if (posix_spawnattr_init(&attrp))
+ throw SysError("failed to initialize builder");
+
+ if (posix_spawnattr_setflags(&attrp, POSIX_SPAWN_SETEXEC))
+ 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") {
+ cpu_type_t cpu = CPU_TYPE_X86_64;
+ posix_spawnattr_setbinpref_np(&attrp, 1, &cpu, NULL);
+ }
+
+ posix_spawn(NULL, builder.c_str(), NULL, &attrp, stringsToCharPtrs(args).data(), stringsToCharPtrs(envStrs).data());
+}
}