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.
This commit is contained in:
		
							parent
							
								
									819548d92f
								
							
						
					
					
						commit
						8b7f8b56f1
					
				
					 5 changed files with 35 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,6 +22,7 @@ bool keepGoing = false;
 | 
			
		|||
bool tryFallback = false;
 | 
			
		||||
Verbosity buildVerbosity = lvlInfo;
 | 
			
		||||
unsigned int maxBuildJobs = 1;
 | 
			
		||||
unsigned int buildCores = 1;
 | 
			
		||||
bool readOnlyMode = false;
 | 
			
		||||
string thisSystem = "unset";
 | 
			
		||||
time_t maxSilentTime = 0;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -55,6 +55,11 @@ extern Verbosity buildVerbosity;
 | 
			
		|||
/* Maximum number of parallel build jobs.  0 means unlimited. */
 | 
			
		||||
extern unsigned int maxBuildJobs;
 | 
			
		||||
 | 
			
		||||
/* Number of CPU cores to utilize in parallel within a build, i.e. by passing
 | 
			
		||||
   this number to Make via '-j'. 0 means that the number of actual CPU cores on
 | 
			
		||||
   the local host ought to be auto-detected. */
 | 
			
		||||
extern unsigned int buildCores;
 | 
			
		||||
 | 
			
		||||
/* Read-only mode.  Don't copy stuff to the store, don't change the
 | 
			
		||||
   database. */
 | 
			
		||||
extern bool readOnlyMode;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue