Skip to content

Commit

Permalink
Merge pull request #184820 from obsidiansystems/buildRustCrate-stdlib…
Browse files Browse the repository at this point in the history
…-deps-21.11

[backport release-21.11] buildRustCrate: Add support for standard library deps
  • Loading branch information
Ericson2314 authored Aug 2, 2022
2 parents 511f6a5 + c19d196 commit eabc382
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
8 changes: 7 additions & 1 deletion pkgs/build-support/rust/build-rust-crate/build-crate.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{ lib, stdenv, mkRustcDepArgs, mkRustcFeatureArgs, rust }:
{ lib, stdenv
, mkRustcDepArgs, mkRustcFeatureArgs, needUnstableCLI
, rust
}:

{ crateName,
dependencies,
crateFeatures, crateRenames, libName, release, libPath,
Expand All @@ -17,6 +21,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
Expand Down
21 changes: 16 additions & 5 deletions pkgs/build-support/rust/build-rust-crate/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,36 @@ 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 {
inherit lib stdenv rust echo_colored noisily mkRustcDepArgs mkRustcFeatureArgs;
};

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; };
Expand Down

0 comments on commit eabc382

Please sign in to comment.