From 443076118675ef83ef0db0938fb249273170fc56 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 30 Jun 2021 15:50:45 +0000 Subject: [PATCH] buildRustCrate: Add `extraRustcOptsForBuild` `extraRustcOpts` should not be used for build.rs, lest it contain host-platform-specific options during cross builds. --- .../rust/build-rust-crate/configure-crate.nix | 4 ++-- .../build-support/rust/build-rust-crate/default.nix | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pkgs/build-support/rust/build-rust-crate/configure-crate.nix b/pkgs/build-support/rust/build-rust-crate/configure-crate.nix index d1010ac1adb3..1a9705591d6d 100644 --- a/pkgs/build-support/rust/build-rust-crate/configure-crate.nix +++ b/pkgs/build-support/rust/build-rust-crate/configure-crate.nix @@ -13,7 +13,7 @@ , crateRenames , crateVersion , extraLinkFlags -, extraRustcOpts +, extraRustcOptsForBuildRs , libName , libPath , release @@ -24,7 +24,7 @@ let version_ = lib.splitString "-" crateVersion; version = lib.splitVersion (lib.head version_); rustcOpts = lib.foldl' (opts: opt: opts + " " + opt) (if release then "-C opt-level=3" else "-C debuginfo=2") - (["-C codegen-units=$NIX_BUILD_CORES"] ++ extraRustcOpts); + (["-C codegen-units=$NIX_BUILD_CORES"] ++ extraRustcOptsForBuildRs); buildDeps = mkRustcDepArgs buildDependencies crateRenames; authors = lib.concatStringsSep ":" crateAuthors; optLevel = if release then 3 else 0; diff --git a/pkgs/build-support/rust/build-rust-crate/default.nix b/pkgs/build-support/rust/build-rust-crate/default.nix index 13b153315f7f..afb938e51182 100644 --- a/pkgs/build-support/rust/build-rust-crate/default.nix +++ b/pkgs/build-support/rust/build-rust-crate/default.nix @@ -172,6 +172,11 @@ crate_: lib.makeOverridable # Example: [ "-Z debuginfo=2" ] # Default: [] , extraRustcOpts + # A list of extra options to pass to rustc when building a build.rs. + # + # Example: [ "-Z debuginfo=2" ] + # Default: [] + , extraRustcOptsForBuildRs # Whether to enable building tests. # Use true to enable. # Default: false @@ -228,6 +233,7 @@ crate_: lib.makeOverridable nativeBuildInputs_ = nativeBuildInputs; buildInputs_ = buildInputs; extraRustcOpts_ = extraRustcOpts; + extraRustcOptsForBuildRs_ = extraRustcOptsForBuildRs; buildTests_ = buildTests; # crate2nix has a hack for the old bash based build script that did split @@ -308,12 +314,16 @@ crate_: lib.makeOverridable lib.optionals (crate ? extraRustcOpts) crate.extraRustcOpts ++ extraRustcOpts_ ++ (lib.optional (edition != null) "--edition ${edition}"); + extraRustcOptsForBuildRs = + lib.optionals (crate ? extraRustcOptsForBuildRs) crate.extraRustcOptsForBuildRs + ++ extraRustcOptsForBuildRs_ + ++ (lib.optional (edition != null) "--edition ${edition}"); configurePhase = configureCrate { inherit crateName buildDependencies completeDeps completeBuildDeps crateDescription crateFeatures crateRenames libName build workspace_member release libPath crateVersion - extraLinkFlags extraRustcOpts + extraLinkFlags extraRustcOptsForBuildRs crateAuthors crateHomepage verbose colors; }; buildPhase = buildCrate { @@ -337,6 +347,7 @@ crate_: lib.makeOverridable release = crate_.release or true; verbose = crate_.verbose or true; extraRustcOpts = [ ]; + extraRustcOptsForBuildRs = [ ]; features = [ ]; nativeBuildInputs = [ ]; buildInputs = [ ];