Merge pull request #184620 from obsidiansystems/buildRustCrate-stdlib-deps
buildRustCrate: Add support for standard library deps
This commit is contained in:
commit
e3e24fbb8a
@ -1,4 +1,8 @@
|
||||
{ lib, stdenv, mkRustcDepArgs, mkRustcFeatureArgs, rust }:
|
||||
{ lib, stdenv
|
||||
, mkRustcDepArgs, mkRustcFeatureArgs, needUnstableCLI
|
||||
, rust
|
||||
}:
|
||||
|
||||
{ crateName,
|
||||
dependencies,
|
||||
crateFeatures, crateRenames, libName, release, libPath,
|
||||
@ -18,6 +22,8 @@
|
||||
(mkRustcFeatureArgs crateFeatures)
|
||||
] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
|
||||
"--target" (rust.toRustTargetSpec stdenv.hostPlatform)
|
||||
] ++ lib.optionals (needUnstableCLI dependencies) [
|
||||
"-Z" "unstable-options"
|
||||
] ++ extraRustcOpts
|
||||
# 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
|
||||
|
@ -46,17 +46,28 @@ let
|
||||
)
|
||||
else
|
||||
extern;
|
||||
opts = lib.optionalString (dep.stdlib or false) "noprelude:";
|
||||
filename =
|
||||
if lib.any (x: x == "lib" || x == "rlib") dep.crateType
|
||||
then "${dep.metadata}.rlib"
|
||||
else "${dep.metadata}${stdenv.hostPlatform.extensions.sharedLibrary}";
|
||||
in
|
||||
(if lib.any (x: x == "lib" || x == "rlib") dep.crateType then
|
||||
" --extern ${name}=${dep.lib}/lib/lib${extern}-${dep.metadata}.rlib"
|
||||
else
|
||||
" --extern ${name}=${dep.lib}/lib/lib${extern}-${dep.metadata}${stdenv.hostPlatform.extensions.sharedLibrary}")
|
||||
" --extern ${opts}${name}=${dep.lib}/lib/lib${extern}-${filename}"
|
||||
)
|
||||
dependencies;
|
||||
|
||||
# Create feature arguments for rustc.
|
||||
mkRustcFeatureArgs = lib.concatMapStringsSep " " (f: ''--cfg feature=\"${f}\"'');
|
||||
|
||||
# Whether we need to use unstable command line flags
|
||||
#
|
||||
# Currently just needed for standard library dependencies, which have a
|
||||
# special "noprelude:" modifier. If in later versions of Rust this is
|
||||
# stabilized we can account for that here, too, so we don't opt into
|
||||
# instability unnecessarily.
|
||||
needUnstableCLI = dependencies:
|
||||
lib.any (dep: dep.stdlib or false) dependencies;
|
||||
|
||||
inherit (import ./log.nix { inherit lib; }) noisily echo_colored;
|
||||
|
||||
configureCrate = import ./configure-crate.nix {
|
||||
@ -64,7 +75,7 @@ let
|
||||
};
|
||||
|
||||
buildCrate = import ./build-crate.nix {
|
||||
inherit lib stdenv mkRustcDepArgs mkRustcFeatureArgs rust;
|
||||
inherit lib stdenv mkRustcDepArgs mkRustcFeatureArgs needUnstableCLI rust;
|
||||
};
|
||||
|
||||
installCrate = import ./install-crate.nix { inherit stdenv; };
|
||||
|
Loading…
Reference in New Issue
Block a user