Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Support auto-configuration of build-max-jobs
"build-max-jobs" and the "-j" option can now be set to "auto" to use
the number of CPUs in the system. (Unlike build-cores, it doesn't use
0 to imply auto-configuration, because a) magic values are a bad idea
in general; b) 0 is a legitimate value used to disable local
building.)
Fixes #1198 .
Loading branch information
@@ -101,9 +101,9 @@ flag, e.g. <literal>--option gc-keep-outputs false</literal>.</para>
<listitem ><para >This option defines the maximum number of jobs
that Nix will try to build in parallel. The default is
<literal >1</literal >. You should generally set it to the number
of CPUs in your system (e.g., < literal >2</ literal > on an Athlon 64
X2). It can be overridden using the <option
<literal >1</literal >. The special value < literal >auto</ literal >
causes Nix to use the number of CPUs in your system. It can be
overridden using the <option
linkend =' opt-max-jobs' >--max-jobs</option > (<option >-j</option >)
command line switch.</para ></listitem >
@@ -93,8 +93,9 @@
<term ><option >-j</option ></term >
<listitem ><para >Sets the maximum number of build jobs that Nix will
perform in parallel to the specified number. The default is
specified by the <link
perform in parallel to the specified number. Specify
<literal >auto</literal > to use the number of CPUs in the system.
The default is specified by the <link
linkend =' conf-build-max-jobs' ><literal >build-max-jobs</literal ></link >
configuration setting, which itself defaults to
<literal >1</literal >. A higher value is useful on SMP systems or to
@@ -167,14 +167,17 @@ struct LegacyArgs : public MixCommonArgs
settings.set (" build-fallback" , " true" );
});
mkFlag1 (' j' , " max-jobs" , " jobs" , " maximum number of parallel builds" , [=](std::string s) {
settings.set (" build-max-jobs" , s);
});
auto intSettingAlias = [&](char shortName, const std::string & longName,
const std::string & description, const std::string & dest) {
mkFlag<unsigned int >(shortName, longName, description, [=](unsigned int n) {
settings.set (dest, std::to_string (n));
});
};
intSettingAlias (' j' , " max-jobs" , " maximum number of parallel builds" , " build-max-jobs" );
intSettingAlias (0 , " cores" , " maximum number of CPU cores to use inside a build" , " build-cores" );
intSettingAlias (0 , " max-silent-time" , " number of seconds of silence before a build is killed" , " build-max-silent-time" );
intSettingAlias (0 , " timeout" , " number of seconds before a build is killed" , " build-timeout" );
@@ -147,7 +147,14 @@ int Settings::get(const string & name, int def)
void Settings::update ()
{
_get (tryFallback, " build-fallback" );
_get (maxBuildJobs, " build-max-jobs" );
auto s = get (" build-max-jobs" , std::string (" 1" ));
if (s == " auto" )
maxBuildJobs = std::max (1U , std::thread::hardware_concurrency ());
else
if (!string2Int (s, maxBuildJobs))
throw Error (" configuration setting ‘build-max-jobs’ should be ‘auto’ or an integer" );
_get (buildCores, " build-cores" );
_get (thisSystem, " system" );
_get (maxSilentTime, " build-max-silent-time" );
Toggle all file notes
This comment has been minimized.
7251d04
Thanks!