mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 15:03:28 +00:00
buildRustCrate: builtins -> lib where possible
We can just use `lib` instead of `builtins` in all cases but the `hashString` case. Also changed a few lines to make use of some optional helpers from lib.
This commit is contained in:
parent
1eda713fa4
commit
0aac0e8d2c
@ -9,7 +9,7 @@
|
||||
|
||||
deps = makeDeps dependencies crateRenames;
|
||||
rustcOpts =
|
||||
lib.lists.foldl' (opts: opt: opts + " " + opt)
|
||||
lib.foldl' (opts: opt: opts + " " + opt)
|
||||
(if release then "-C opt-level=3" else "-C debuginfo=2")
|
||||
(["-C codegen-units=$NIX_BUILD_CORES"] ++ extraRustcOpts);
|
||||
rustcMeta = "-C metadata=${metadata} -C extra-filename=-${metadata}";
|
||||
|
@ -20,9 +20,9 @@
|
||||
, verbose
|
||||
, workspace_member }:
|
||||
let version_ = lib.splitString "-" crateVersion;
|
||||
versionPre = if lib.tail version_ == [] then "" else builtins.elemAt version_ 1;
|
||||
versionPre = if lib.tail version_ == [] then "" else lib.elemAt version_ 1;
|
||||
version = lib.splitVersion (lib.head version_);
|
||||
rustcOpts = lib.lists.foldl' (opts: opt: opts + " " + opt)
|
||||
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);
|
||||
buildDeps = makeDeps buildDependencies crateRenames;
|
||||
@ -90,9 +90,9 @@ in ''
|
||||
export HOST="${stdenv.hostPlatform.config}"
|
||||
export PROFILE=${if release then "release" else "debug"}
|
||||
export OUT_DIR=$(pwd)/target/build/${crateName}.out
|
||||
export CARGO_PKG_VERSION_MAJOR=${builtins.elemAt version 0}
|
||||
export CARGO_PKG_VERSION_MINOR=${builtins.elemAt version 1}
|
||||
export CARGO_PKG_VERSION_PATCH=${builtins.elemAt version 2}
|
||||
export CARGO_PKG_VERSION_MAJOR=${lib.elemAt version 0}
|
||||
export CARGO_PKG_VERSION_MINOR=${lib.elemAt version 1}
|
||||
export CARGO_PKG_VERSION_PATCH=${lib.elemAt version 2}
|
||||
export CARGO_PKG_VERSION_PRE="${versionPre}"
|
||||
export CARGO_PKG_HOMEPAGE="${crateHomepage}"
|
||||
export NUM_JOBS=1
|
||||
|
@ -16,12 +16,12 @@ let
|
||||
makeDeps = dependencies: crateRenames:
|
||||
(lib.concatMapStringsSep " " (dep:
|
||||
let
|
||||
extern = lib.strings.replaceStrings ["-"] ["_"] dep.libName;
|
||||
name = if builtins.hasAttr dep.crateName crateRenames then
|
||||
extern = lib.replaceStrings ["-"] ["_"] dep.libName;
|
||||
name = if lib.hasAttr dep.crateName crateRenames then
|
||||
lib.strings.replaceStrings ["-"] ["_"] crateRenames.${dep.crateName}
|
||||
else
|
||||
extern;
|
||||
in (if lib.lists.any (x: x == "lib") dep.crateType then
|
||||
in (if lib.any (x: x == "lib") 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}")
|
||||
@ -61,8 +61,7 @@ let
|
||||
configureCrate = import ./configure-crate.nix { inherit lib stdenv echo_build_heading noisily makeDeps; };
|
||||
buildCrate = import ./build-crate.nix { inherit lib stdenv echo_build_heading noisily makeDeps rust; };
|
||||
installCrate = import ./install-crate.nix;
|
||||
|
||||
in
|
||||
in
|
||||
|
||||
crate_: lib.makeOverridable ({ rust, release, verbose, features, buildInputs, crateOverrides,
|
||||
dependencies, buildDependencies, crateRenames,
|
||||
@ -95,34 +94,33 @@ stdenv.mkDerivation (rec {
|
||||
depsBuildBuild = [ rust stdenv.cc ];
|
||||
buildInputs = (crate.buildInputs or []) ++ buildInputs_;
|
||||
dependencies =
|
||||
builtins.map
|
||||
map
|
||||
(dep: lib.getLib (dep.override { rust = rust; release = release; verbose = verbose; crateOverrides = crateOverrides; }))
|
||||
dependencies_;
|
||||
|
||||
buildDependencies =
|
||||
builtins.map
|
||||
map
|
||||
(dep: lib.getLib (dep.override { rust = rust; release = release; verbose = verbose; crateOverrides = crateOverrides; }))
|
||||
buildDependencies_;
|
||||
|
||||
completeDeps = lib.lists.unique (dependencies ++ lib.lists.concatMap (dep: dep.completeDeps) dependencies);
|
||||
completeBuildDeps = lib.lists.unique (
|
||||
completeDeps = lib.unique (dependencies ++ lib.concatMap (dep: dep.completeDeps) dependencies);
|
||||
completeBuildDeps = lib.unique (
|
||||
buildDependencies
|
||||
++ lib.lists.concatMap (dep: dep.completeBuildDeps ++ dep.completeDeps) buildDependencies
|
||||
++ lib.concatMap (dep: dep.completeBuildDeps ++ dep.completeDeps) buildDependencies
|
||||
);
|
||||
|
||||
crateFeatures = if crate ? features then
|
||||
lib.concatMapStringsSep " " (f: "--cfg feature=\\\"${f}\\\"") (crate.features ++ features) #"
|
||||
else "";
|
||||
crateFeatures = lib.optionalString (crate ? features)
|
||||
(lib.concatMapStringsSep " " (f: "--cfg feature=\\\"${f}\\\"") (crate.features ++ features));
|
||||
|
||||
libName = if crate ? libName then crate.libName else crate.crateName;
|
||||
libPath = if crate ? libPath then crate.libPath else "";
|
||||
|
||||
depsMetadata = builtins.foldl' (str: dep: str + dep.metadata) "" (dependencies ++ buildDependencies);
|
||||
metadata = builtins.substring 0 10 (builtins.hashString "sha256" (crateName + "-" + crateVersion + "___" + toString crateFeatures + "___" + depsMetadata ));
|
||||
depsMetadata = lib.foldl' (str: dep: str + dep.metadata) "" (dependencies ++ buildDependencies);
|
||||
metadata = lib.substring 0 10 (builtins.hashString "sha256" (crateName + "-" + crateVersion + "___" + toString crateFeatures + "___" + depsMetadata ));
|
||||
|
||||
crateBin = if crate ? crateBin then
|
||||
builtins.foldl' (bins: bin: let
|
||||
name = (if bin ? name then bin.name else crateName);
|
||||
lib.foldl' (bins: bin: let
|
||||
name = if bin ? name then bin.name else crateName;
|
||||
path = if bin ? path then bin.path else "";
|
||||
in
|
||||
bins + (if bin == "" then "" else ",") + "${name} ${path}"
|
||||
@ -142,9 +140,9 @@ stdenv.mkDerivation (rec {
|
||||
if lib.attrByPath ["plugin"] false crate then ["dylib"] else
|
||||
(crate.type or ["lib"]);
|
||||
colors = lib.attrByPath [ "colors" ] "always" crate;
|
||||
extraLinkFlags = builtins.concatStringsSep " " (crate.extraLinkFlags or []);
|
||||
extraLinkFlags = lib.concatStringsSep " " (crate.extraLinkFlags or []);
|
||||
edition = crate.edition or null;
|
||||
extraRustcOpts = (if crate ? extraRustcOpts then crate.extraRustcOpts else []) ++ extraRustcOpts_ ++ (lib.optional (edition != null) "--edition ${edition}");
|
||||
extraRustcOpts = lib.optionals (crate ? extraRustcOpts) crate.extraRustcOpts ++ extraRustcOpts_ ++ (lib.optional (edition != null) "--edition ${edition}");
|
||||
|
||||
configurePhase = configureCrate {
|
||||
inherit crateName buildDependencies completeDeps completeBuildDeps crateDescription
|
||||
|
@ -3,23 +3,23 @@
|
||||
kernel = stdenv.hostPlatform.parsed.kernel.name;
|
||||
abi = stdenv.hostPlatform.parsed.abi.name;
|
||||
cpu = stdenv.hostPlatform.parsed.cpu.name;
|
||||
updateFeatures = f: up: functions: builtins.deepSeq f (lib.lists.foldl' (features: fun: fun features) (lib.attrsets.recursiveUpdate f up) functions);
|
||||
updateFeatures = f: up: functions: lib.deepSeq f (lib.foldl' (features: fun: fun features) (lib.attrsets.recursiveUpdate f up) functions);
|
||||
mapFeatures = features: map (fun: fun { features = features; });
|
||||
mkFeatures = feat: lib.lists.foldl (features: featureName:
|
||||
mkFeatures = feat: lib.foldl (features: featureName:
|
||||
if feat.${featureName} or false then
|
||||
[ featureName ] ++ features
|
||||
else
|
||||
features
|
||||
) [] (builtins.attrNames feat);
|
||||
include = includedFiles: src: builtins.filterSource (path: type:
|
||||
lib.lists.any (f:
|
||||
) [] (lib.attrNames feat);
|
||||
include = includedFiles: src: lib.filterSource (path: type:
|
||||
lib.any (f:
|
||||
let p = toString (src + ("/" + f));
|
||||
in
|
||||
p == path || (lib.strings.hasPrefix (p + "/") path)
|
||||
) includedFiles
|
||||
) src;
|
||||
exclude = excludedFiles: src: builtins.filterSource (path: type:
|
||||
lib.lists.all (f:
|
||||
exclude = excludedFiles: src: lib.filterSource (path: type:
|
||||
lib.all (f:
|
||||
!lib.strings.hasPrefix (toString (src + ("/" + f))) path
|
||||
) excludedFiles
|
||||
) src;
|
||||
|
Loading…
Reference in New Issue
Block a user