buildRustCrate: pass extraRustcOpts to configure crate

Previously build flags would not be available during the configure phase
while they might be required to build the `build.rs` file.
This commit is contained in:
Andreas Rammhold 2019-02-18 00:10:36 +01:00
parent 5d42605b91
commit 044a8a24ed
No known key found for this signature in database
GPG Key ID: E432E410B5E48C86
3 changed files with 27 additions and 9 deletions

View File

@ -8,11 +8,11 @@
let
deps = makeDeps dependencies;
rustcOpts =
lib.lists.foldl' (opts: opt: opts + " " + opt)
(if release then "-C opt-level=3" else "-C debuginfo=2")
(["-C codegen-units=1"] ++ extraRustcOpts);
rustcMeta = "-C metadata=${metadata} -C extra-filename=-${metadata}";
rustcOpts =
lib.lists.foldl' (opts: opt: opts + " " + opt)
(if release then "-C opt-level=3" else "-C debuginfo=2")
(["-C codegen-units=1"] ++ extraRustcOpts);
rustcMeta = "-C metadata=${metadata} -C extra-filename=-${metadata}";
# Some platforms have different names for rustc.
rustPlatform =

View File

@ -1,9 +1,27 @@
{ lib, stdenv, echo_build_heading, noisily, makeDeps }:
{ build, buildDependencies, colors, completeBuildDeps, completeDeps, crateAuthors, crateFeatures, crateName, crateVersion, extraLinkFlags, libName, libPath, release, target_os, verbose, workspace_member }:
{ build
, buildDependencies
, colors
, completeBuildDeps
, completeDeps
, crateAuthors
, crateFeatures
, crateName
, crateVersion
, extraLinkFlags
, extraRustcOpts
, libName
, libPath
, release
, target_os
, verbose
, workspace_member }:
let version_ = lib.splitString "-" crateVersion;
versionPre = if lib.tail version_ == [] then "" else builtins.elemAt version_ 1;
version = lib.splitString "." (lib.head version_);
rustcOpts = (if release then "-C opt-level=3" else "-C debuginfo=2");
rustcOpts = lib.lists.foldl' (opts: opt: opts + " " + opt)
(if release then "-C opt-level=3" else "-C debuginfo=2")
(["-C codegen-units=1"] ++ extraRustcOpts);
buildDeps = makeDeps buildDependencies;
authors = lib.concatStringsSep ":" crateAuthors;
optLevel = if release then 3 else 0;

View File

@ -136,13 +136,13 @@ stdenv.mkDerivation (rec {
(crate.type or ["lib"]);
colors = lib.attrByPath [ "colors" ] "always" crate;
extraLinkFlags = builtins.concatStringsSep " " (crate.extraLinkFlags or []);
extraRustcOpts = (if crate ? extraRustcOpts then crate.extraRustcOpts else []) ++ extraRustcOpts_;
configurePhase = configureCrate {
inherit crateName buildDependencies completeDeps completeBuildDeps
crateFeatures libName build workspace_member release libPath crateVersion
extraLinkFlags
extraLinkFlags extraRustcOpts
crateAuthors verbose colors target_os;
};
extraRustcOpts = (if crate ? extraRustcOpts then crate.extraRustcOpts else []) ++ extraRustcOpts_;
buildPhase = buildCrate {
inherit crateName dependencies
crateFeatures libName release libPath crateType