From 8b7f8b56f11145c1be5188113cbcdbea27e99525 Mon Sep 17 00:00:00 2001 From: Peter Simons Date: Wed, 23 Jun 2010 14:34:08 +0000 Subject: Added support for passing an (impure) NIX_BUILD_CORES variable to build expressions. This patch adds the configuration file variable "build-cores" and the command line argument "--cores". These settings specify the number of CPU cores to utilize for parallel building within a job, i.e. by passing an appropriate "-j" flag to GNU Make. The default value is 1, which means that parallel building is *disabled*. If the number of build cores is specified as 0 (synonymously: "guess" or "auto"), then the actual value is supposed to be auto-detected by builders at run-time, i.e by calling the nproc(1) utility from coreutils. The environment variable $NIX_BUILD_CORES is available to builders, but the contents of that variable does *not* influence the hash that goes into the $out store path, i.e. the number of build cores to be utilized can be changed at will without requiring any re-builds. --- src/libstore/build.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/libstore/build.cc') diff --git a/src/libstore/build.cc b/src/libstore/build.cc index f901c1f7d99e..a53c23bf447d 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -1411,6 +1411,9 @@ void DerivationGoal::startBuilder() in the store or in the build directory). */ env["NIX_STORE"] = nixStore; + /* The maximum number of cores to utilize for parallel building. */ + env["NIX_BUILD_CORES"] = (format("%d") % buildCores).str(); + /* Add all bindings specified in the derivation. */ foreach (StringPairs::iterator, i, drv.env) env[i->first] = i->second; -- cgit 1.4.1 From a17071fef15115dc0e7052ebe091ffe8457f77d0 Mon Sep 17 00:00:00 2001 From: Peter Simons Date: Thu, 24 Jun 2010 17:51:04 +0000 Subject: Include to ensure that strcpy(), strlen(), and memset() are declared. An "using namespace std" was added locally in those functions that refer to names from . That is not pretty, but it's a very portable solution, because strcpy() and friends will be found in both the 'std' and in the global namespace. --- src/libstore/build.cc | 2 ++ src/libstore/remote-store.cc | 2 ++ src/nix-worker/nix-worker.cc | 2 ++ 3 files changed, 6 insertions(+) (limited to 'src/libstore/build.cc') diff --git a/src/libstore/build.cc b/src/libstore/build.cc index a53c23bf447d..ef2f7adf3194 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -2638,6 +2639,7 @@ void Worker::waitForInput() timeout.tv_sec = std::max((time_t) 0, lastWokenUp + wakeUpInterval - before); } else lastWokenUp = 0; + using namespace std; /* Use select() to wait for the input side of any logger pipe to become `available'. Note that `available' (i.e., non-blocking) includes EOF. */ diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 5143143f57c3..9db90c872a4b 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -13,6 +13,7 @@ #include #include +#include namespace nix { @@ -158,6 +159,7 @@ void RemoteStore::connectToDaemon() addr.sun_family = AF_UNIX; if (socketPathRel.size() >= sizeof(addr.sun_path)) throw Error(format("socket path `%1%' is too long") % socketPathRel); + using namespace std; strcpy(addr.sun_path, socketPathRel.c_str()); if (connect(fdSocket, (struct sockaddr *) &addr, sizeof(addr)) == -1) diff --git a/src/nix-worker/nix-worker.cc b/src/nix-worker/nix-worker.cc index bd2209c6d756..0052fbb7d5cd 100644 --- a/src/nix-worker/nix-worker.cc +++ b/src/nix-worker/nix-worker.cc @@ -7,6 +7,7 @@ #include "globals.hh" #include +#include #include #include #include @@ -111,6 +112,7 @@ static bool isFarSideClosed(int socket) time and wouldn't have to worry about races. */ static void sigPollHandler(int sigNo) { + using namespace std; try { /* Check that the far side actually closed. We're still getting spurious signals every once in a while. I.e., -- cgit 1.4.1