Merge pull request #138321 from obsidiansystems/fix-build-rust-crate-cross
buildRustCrate: Fix some things for cross builds
This commit is contained in:
commit
f1f320d4ac
|
@ -15,8 +15,9 @@
|
|||
"--remap-path-prefix=$NIX_BUILD_TOP=/"
|
||||
(mkRustcDepArgs dependencies crateRenames)
|
||||
(mkRustcFeatureArgs crateFeatures)
|
||||
] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
|
||||
"--target" (rust.toRustTargetSpec stdenv.hostPlatform)
|
||||
] ++ extraRustcOpts
|
||||
++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) "--target ${rust.toRustTargetSpec stdenv.hostPlatform} -C linker=${stdenv.hostPlatform.config}-gcc"
|
||||
# since rustc 1.42 the "proc_macro" crate is part of the default crate prelude
|
||||
# https://github.com/rust-lang/cargo/commit/4d64eb99a4#diff-7f98585dbf9d30aa100c8318e2c77e79R1021-R1022
|
||||
++ lib.optional (lib.elem "proc-macro" crateType) "--extern proc_macro"
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 = [ ];
|
||||
|
|
Loading…
Reference in a new issue