mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-14 05:29:20 +03:00
buildRustCrate: make codegen-units configurable
This parameter is being set to `$NIX_BUILD_CORES` by default. This is a standard practice but there's a suspicion that this can produce broken builds. For some details see https://github.com/cargo2nix/cargo2nix/issues/184 . As a work-around/test, it'd be good if codegen-units can be set to something constant, such as `1`. This PR allows it. Note that the default of `$NIX_BUILD_CORES` is preserved so this MR causes no change in default behaviour and no rebuilds.
This commit is contained in:
parent
b455605c2d
commit
f6897d23f4
3 changed files with 9 additions and 5 deletions
|
@ -4,14 +4,15 @@
|
||||||
crateFeatures, crateRenames, libName, release, libPath,
|
crateFeatures, crateRenames, libName, release, libPath,
|
||||||
crateType, metadata, crateBin, hasCrateBin,
|
crateType, metadata, crateBin, hasCrateBin,
|
||||||
extraRustcOpts, verbose, colors,
|
extraRustcOpts, verbose, colors,
|
||||||
buildTests
|
buildTests,
|
||||||
|
codegenUnits
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
baseRustcOpts =
|
baseRustcOpts =
|
||||||
[
|
[
|
||||||
(if release then "-C opt-level=3" else "-C debuginfo=2")
|
(if release then "-C opt-level=3" else "-C debuginfo=2")
|
||||||
"-C codegen-units=$NIX_BUILD_CORES"
|
"-C codegen-units=${codegenUnits}"
|
||||||
"--remap-path-prefix=$NIX_BUILD_TOP=/"
|
"--remap-path-prefix=$NIX_BUILD_TOP=/"
|
||||||
(mkRustcDepArgs dependencies crateRenames)
|
(mkRustcDepArgs dependencies crateRenames)
|
||||||
(mkRustcFeatureArgs crateFeatures)
|
(mkRustcFeatureArgs crateFeatures)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
{
|
{
|
||||||
build
|
build
|
||||||
, buildDependencies
|
, buildDependencies
|
||||||
|
, codegenUnits
|
||||||
, colors
|
, colors
|
||||||
, completeBuildDeps
|
, completeBuildDeps
|
||||||
, completeDeps
|
, completeDeps
|
||||||
|
@ -24,7 +25,7 @@ let version_ = lib.splitString "-" crateVersion;
|
||||||
version = lib.splitVersion (lib.head version_);
|
version = lib.splitVersion (lib.head version_);
|
||||||
rustcOpts = lib.foldl' (opts: opt: opts + " " + opt)
|
rustcOpts = lib.foldl' (opts: opt: opts + " " + opt)
|
||||||
(if release then "-C opt-level=3" else "-C debuginfo=2")
|
(if release then "-C opt-level=3" else "-C debuginfo=2")
|
||||||
(["-C codegen-units=$NIX_BUILD_CORES"] ++ extraRustcOptsForBuildRs);
|
(["-C codegen-units=${codegenUnits}"] ++ extraRustcOptsForBuildRs);
|
||||||
buildDeps = mkRustcDepArgs buildDependencies crateRenames;
|
buildDeps = mkRustcDepArgs buildDependencies crateRenames;
|
||||||
authors = lib.concatStringsSep ":" crateAuthors;
|
authors = lib.concatStringsSep ":" crateAuthors;
|
||||||
optLevel = if release then 3 else 0;
|
optLevel = if release then 3 else 0;
|
||||||
|
|
|
@ -228,6 +228,7 @@ crate_: lib.makeOverridable
|
||||||
"colors"
|
"colors"
|
||||||
"edition"
|
"edition"
|
||||||
"buildTests"
|
"buildTests"
|
||||||
|
"codegenUnits"
|
||||||
];
|
];
|
||||||
extraDerivationAttrs = builtins.removeAttrs crate processedAttrs;
|
extraDerivationAttrs = builtins.removeAttrs crate processedAttrs;
|
||||||
nativeBuildInputs_ = nativeBuildInputs;
|
nativeBuildInputs_ = nativeBuildInputs;
|
||||||
|
@ -315,6 +316,7 @@ crate_: lib.makeOverridable
|
||||||
colors = lib.attrByPath [ "colors" ] "always" crate;
|
colors = lib.attrByPath [ "colors" ] "always" crate;
|
||||||
extraLinkFlags = lib.concatStringsSep " " (crate.extraLinkFlags or [ ]);
|
extraLinkFlags = lib.concatStringsSep " " (crate.extraLinkFlags or [ ]);
|
||||||
edition = crate.edition or null;
|
edition = crate.edition or null;
|
||||||
|
codegenUnits = if crate ? codegenUnits then crate.codegenUnits else "$NIX_BUILD_CORES";
|
||||||
extraRustcOpts =
|
extraRustcOpts =
|
||||||
lib.optionals (crate ? extraRustcOpts) crate.extraRustcOpts
|
lib.optionals (crate ? extraRustcOpts) crate.extraRustcOpts
|
||||||
++ extraRustcOpts_
|
++ extraRustcOpts_
|
||||||
|
@ -329,13 +331,13 @@ crate_: lib.makeOverridable
|
||||||
inherit crateName buildDependencies completeDeps completeBuildDeps crateDescription
|
inherit crateName buildDependencies completeDeps completeBuildDeps crateDescription
|
||||||
crateFeatures crateRenames libName build workspace_member release libPath crateVersion
|
crateFeatures crateRenames libName build workspace_member release libPath crateVersion
|
||||||
extraLinkFlags extraRustcOptsForBuildRs
|
extraLinkFlags extraRustcOptsForBuildRs
|
||||||
crateAuthors crateHomepage verbose colors;
|
crateAuthors crateHomepage verbose colors codegenUnits;
|
||||||
};
|
};
|
||||||
buildPhase = buildCrate {
|
buildPhase = buildCrate {
|
||||||
inherit crateName dependencies
|
inherit crateName dependencies
|
||||||
crateFeatures crateRenames libName release libPath crateType
|
crateFeatures crateRenames libName release libPath crateType
|
||||||
metadata hasCrateBin crateBin verbose colors
|
metadata hasCrateBin crateBin verbose colors
|
||||||
extraRustcOpts buildTests;
|
extraRustcOpts buildTests codegenUnits;
|
||||||
};
|
};
|
||||||
installPhase = installCrate crateName metadata buildTests;
|
installPhase = installCrate crateName metadata buildTests;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue