mirror of
https://github.com/NixOS/nix.git
synced 2025-11-13 05:56:03 +01:00
Merge pull request #13402 from DavHau/build-cores
build-cores: detect cores automatically if set to 0
This commit is contained in:
commit
b19e9acc03
8 changed files with 58 additions and 10 deletions
|
|
@ -140,7 +140,7 @@ std::vector<Path> getUserConfigFiles()
|
|||
return files;
|
||||
}
|
||||
|
||||
unsigned int Settings::getDefaultCores()
|
||||
unsigned int Settings::getDefaultCores() const
|
||||
{
|
||||
const unsigned int concurrency = std::max(1U, std::thread::hardware_concurrency());
|
||||
const unsigned int maxCPU = getMaxCPU();
|
||||
|
|
|
|||
|
|
@ -43,8 +43,6 @@ const uint32_t maxIdsPerBuild =
|
|||
|
||||
class Settings : public Config {
|
||||
|
||||
unsigned int getDefaultCores();
|
||||
|
||||
StringSet getDefaultSystemFeatures();
|
||||
|
||||
StringSet getDefaultExtraPlatforms();
|
||||
|
|
@ -57,6 +55,8 @@ public:
|
|||
|
||||
Settings();
|
||||
|
||||
unsigned int getDefaultCores() const;
|
||||
|
||||
Path nixPrefix;
|
||||
|
||||
/**
|
||||
|
|
@ -153,7 +153,7 @@ public:
|
|||
|
||||
Setting<unsigned int> buildCores{
|
||||
this,
|
||||
getDefaultCores(),
|
||||
0,
|
||||
"cores",
|
||||
R"(
|
||||
Sets the value of the `NIX_BUILD_CORES` environment variable in the [invocation of the `builder` executable](@docroot@/language/derivations.md#builder-execution) of a derivation.
|
||||
|
|
@ -166,15 +166,13 @@ public:
|
|||
-->
|
||||
For instance, in Nixpkgs, if the attribute `enableParallelBuilding` for the `mkDerivation` build helper is set to `true`, it passes the `-j${NIX_BUILD_CORES}` flag to GNU Make.
|
||||
|
||||
The value `0` means that the `builder` should use all available CPU cores in the system.
|
||||
If set to `0`, nix will detect the number of CPU cores and pass this number via NIX_BUILD_CORES.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> The number of parallel local Nix build jobs is independently controlled with the [`max-jobs`](#conf-max-jobs) setting.
|
||||
)",
|
||||
{"build-cores"},
|
||||
// Don't document the machine-specific default value
|
||||
false};
|
||||
{"build-cores"}};
|
||||
|
||||
/**
|
||||
* Read-only mode. Don't copy stuff to the store, don't change
|
||||
|
|
|
|||
|
|
@ -1083,7 +1083,7 @@ void DerivationBuilderImpl::initEnv()
|
|||
env["NIX_STORE"] = store.storeDir;
|
||||
|
||||
/* The maximum number of cores to utilize for parallel building. */
|
||||
env["NIX_BUILD_CORES"] = fmt("%d", settings.buildCores);
|
||||
env["NIX_BUILD_CORES"] = fmt("%d", settings.buildCores ? settings.buildCores : settings.getDefaultCores());
|
||||
|
||||
/* In non-structured mode, set all bindings either directory in the
|
||||
environment or via a file, as specified by
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue