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/libmain/shared.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/libmain') diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index 3fbec4b5245d..19aa1e71cca9 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -135,6 +135,12 @@ static void initAndRun(int argc, char * * argv) /* Get some settings from the configuration file. */ thisSystem = querySetting("system", SYSTEM); maxBuildJobs = queryIntSetting("build-max-jobs", 1); + string tmp = querySetting("build-cores", "/UNDEFINED"); + std::transform(tmp.begin(), tmp.end(), tmp.begin(), tolower); + if (tmp == "auto" || tmp == "guess") + buildCores = 0; + else + buildCores = queryIntSetting("build-cores", 1); maxSilentTime = queryIntSetting("build-max-silent-time", 0); /* Catch SIGINT. */ @@ -226,6 +232,14 @@ static void initAndRun(int argc, char * * argv) tryFallback = true; else if (arg == "--max-jobs" || arg == "-j") maxBuildJobs = getIntArg(arg, i, args.end()); + else if (arg == "--cores") { + string tmp = *(++i); + std::transform(tmp.begin(), tmp.end(), tmp.begin(), tolower); + if (tmp == "auto" || tmp == "guess") + buildCores = 0u; + else + buildCores = getIntArg(arg, --i, args.end()); + } else if (arg == "--readonly-mode") readOnlyMode = true; else if (arg == "--max-silent-time") -- cgit 1.4.1