diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2021-01-15 02:01:24 +0000 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2021-01-15 02:01:24 +0000 |
commit | 0027b05a15e5845c5ce70c86b5b1a34e7caff039 (patch) | |
tree | 9264ad326d070ec2dcf5d19a373721672eb1df2e /src/libstore/build | |
parent | fed123724679de89d3f56a4c01b5c4c96f93e584 (diff) | |
parent | 7a472a76d4dcbbd0eb7832c0bdcb120d32881e8b (diff) |
Merge remote-tracking branch 'upstream/master' into non-local-store-build
Diffstat (limited to 'src/libstore/build')
-rw-r--r-- | src/libstore/build/derivation-goal.cc | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/src/libstore/build/derivation-goal.cc b/src/libstore/build/derivation-goal.cc index 17f39a86e..953e241d8 100644 --- a/src/libstore/build/derivation-goal.cc +++ b/src/libstore/build/derivation-goal.cc @@ -50,6 +50,11 @@ #define pivot_root(new_root, put_old) (syscall(SYS_pivot_root, new_root, put_old)) #endif +#if __APPLE__ +#include <spawn.h> +#include <sys/sysctl.h> +#endif + #include <pwd.h> #include <grp.h> @@ -683,11 +688,7 @@ void DerivationGoal::tryToBuild() } void DerivationGoal::tryLocalBuild() { - bool buildLocally = buildMode != bmNormal || parsedDrv->willBuildLocally(worker.store); - - /* Make sure that we are allowed to start a build. If this - derivation prefers to be done locally, do it even if - maxBuildJobs is 0. */ + /* Make sure that we are allowed to start a build. */ if (!dynamic_cast<LocalStore *>(&worker.store)) { throw Error( "unable to build with a primary store that isn't a local store; " @@ -695,7 +696,7 @@ void DerivationGoal::tryLocalBuild() { "\nhttps://nixos.org/nix/manual/#chap-distributed-builds"); } unsigned int curBuilds = worker.getNrLocalBuilds(); - if (curBuilds >= settings.maxBuildJobs && !(buildLocally && curBuilds == 0)) { + if (curBuilds >= settings.maxBuildJobs) { worker.waitForBuildSlot(shared_from_this()); outputLocks.unlock(); return; @@ -1714,12 +1715,10 @@ void DerivationGoal::startBuilder() userNamespaceSync.writeSide = -1; }); - pid_t tmp; auto ss = tokenizeString<std::vector<std::string>>(readLine(builderOut.readSide.get())); assert(ss.size() == 2); usingUserNamespace = ss[0] == "1"; - if (!string2Int<pid_t>(ss[1], tmp)) abort(); - pid = tmp; + pid = string2Int<pid_t>(ss[1]).value(); if (usingUserNamespace) { /* Set the UID/GID mapping of the builder's user namespace @@ -2877,7 +2876,31 @@ void DerivationGoal::runChild() } } +#if __APPLE__ + 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, NULL, &attrp, stringsToCharPtrs(args).data(), stringsToCharPtrs(envStrs).data()); +#else execve(builder, stringsToCharPtrs(args).data(), stringsToCharPtrs(envStrs).data()); +#endif throw SysError("executing '%1%'", drv->builder); |