Last active
September 8, 2019 05:55
-
-
Save danieldk/9d78945828dc5d0bcebc0e0b913d5211 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/pkgs/build-support/rust/build-rust-crate/build-crate.nix b/pkgs/build-support/rust/build-rust-crate/build-crate.nix | |
index 2999c3d4c1d..d3f9ded4a04 100644 | |
--- a/pkgs/build-support/rust/build-rust-crate/build-crate.nix | |
+++ b/pkgs/build-support/rust/build-rust-crate/build-crate.nix | |
@@ -3,11 +3,11 @@ | |
dependencies, | |
crateFeatures, libName, release, libPath, | |
crateType, metadata, crateBin, hasCrateBin, | |
- extraRustcOpts, verbose, colors }: | |
+ extraRustcOpts, verbose, colors, renames }: | |
let | |
- deps = makeDeps dependencies; | |
+ deps = makeDeps dependencies renames; | |
rustcOpts = | |
lib.lists.foldl' (opts: opt: opts + " " + opt) | |
(if release then "-C opt-level=3" else "-C debuginfo=2") | |
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 169adcf2d43..7993f789d43 100644 | |
--- a/pkgs/build-support/rust/build-rust-crate/configure-crate.nix | |
+++ b/pkgs/build-support/rust/build-rust-crate/configure-crate.nix | |
@@ -15,6 +15,7 @@ | |
, libName | |
, libPath | |
, release | |
+, renames | |
, target_os | |
, verbose | |
, workspace_member }: | |
@@ -24,7 +25,7 @@ let version_ = lib.splitString "-" crateVersion; | |
rustcOpts = lib.lists.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; | |
+ buildDeps = makeDeps buildDependencies renames; | |
authors = lib.concatStringsSep ":" crateAuthors; | |
optLevel = if release then 3 else 0; | |
completeDepsDir = lib.concatStringsSep " " completeDeps; | |
diff --git a/pkgs/build-support/rust/build-rust-crate/default.nix b/pkgs/build-support/rust/build-rust-crate/default.nix | |
index acb2ee63cce..d50f6c7668e 100644 | |
--- a/pkgs/build-support/rust/build-rust-crate/default.nix | |
+++ b/pkgs/build-support/rust/build-rust-crate/default.nix | |
@@ -13,13 +13,15 @@ let | |
then "macos" | |
else stdenv.hostPlatform.parsed.kernel.name; | |
- makeDeps = dependencies: | |
+ makeDeps = dependencies: renames: | |
(lib.concatMapStringsSep " " (dep: | |
- let extern = lib.strings.replaceStrings ["-"] ["_"] dep.libName; in | |
+ let | |
+ extern = lib.strings.replaceStrings ["-"] ["_"] dep.libName; | |
+ name = lib.strings.replaceStrings ["-"] ["_"] (builtins.getAttr dep.libName renames); in | |
(if lib.lists.any (x: x == "lib") dep.crateType then | |
- " --extern ${extern}=${dep.out}/lib/lib${extern}-${dep.metadata}.rlib" | |
+ " --extern ${name}=${dep.out}/lib/lib${extern}-${dep.metadata}.rlib" | |
else | |
- " --extern ${extern}=${dep.out}/lib/lib${extern}-${dep.metadata}${stdenv.hostPlatform.extensions.sharedLibrary}") | |
+ " --extern ${name}=${dep.out}/lib/lib${extern}-${dep.metadata}${stdenv.hostPlatform.extensions.sharedLibrary}") | |
) dependencies); | |
echo_build_heading = colors: '' | |
@@ -60,7 +62,7 @@ let | |
in | |
crate_: lib.makeOverridable ({ rust, release, verbose, features, buildInputs, crateOverrides, | |
- dependencies, buildDependencies, | |
+ dependencies, buildDependencies, renames, | |
extraRustcOpts, | |
preUnpack, postUnpack, prePatch, patches, postPatch, | |
preConfigure, postConfigure, preBuild, postBuild, preInstall, postInstall }: | |
@@ -71,7 +73,7 @@ let crate = crate_ // (lib.attrByPath [ crate_.crateName ] (attr: {}) crateOverr | |
processedAttrs = [ | |
"src" "buildInputs" "crateBin" "crateLib" "libName" "libPath" | |
"buildDependencies" "dependencies" "features" | |
- "crateName" "version" "build" "authors" "colors" "edition" | |
+ "crateName" "renames" "version" "build" "authors" "colors" "edition" | |
]; | |
extraDerivationAttrs = lib.filterAttrs (n: v: ! lib.elem n processedAttrs) crate; | |
buildInputs_ = buildInputs; | |
@@ -145,13 +147,13 @@ stdenv.mkDerivation (rec { | |
inherit crateName buildDependencies completeDeps completeBuildDeps crateDescription | |
crateFeatures libName build workspace_member release libPath crateVersion | |
extraLinkFlags extraRustcOpts | |
- crateAuthors crateHomepage verbose colors target_os; | |
+ crateAuthors crateHomepage verbose colors target_os renames; | |
}; | |
buildPhase = buildCrate { | |
inherit crateName dependencies | |
crateFeatures libName release libPath crateType | |
metadata crateBin hasCrateBin verbose colors | |
- extraRustcOpts; | |
+ extraRustcOpts renames; | |
}; | |
installPhase = installCrate crateName metadata; | |
@@ -177,4 +179,5 @@ stdenv.mkDerivation (rec { | |
postInstall = crate_.postInstall or ""; | |
dependencies = crate_.dependencies or []; | |
buildDependencies = crate_.buildDependencies or []; | |
+ renames = crate_.renames or {}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/crate2nix.nix b/crate2nix.nix | |
index bca75df..bc03133 100644 | |
--- a/crate2nix.nix | |
+++ b/crate2nix.nix | |
@@ -178,6 +178,7 @@ rec { | |
dependencies = { | |
"getrandom" = { | |
packageId = "getrandom 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)"; | |
+ rename = "getrandom_package"; | |
optional = true; | |
}; | |
"libc" = { | |
@@ -382,7 +383,9 @@ rec { | |
dependencyDerivations buildByPackageId features (crateConfig.dependencies or {}); | |
buildDependencies = | |
dependencyDerivations buildByPackageId features (crateConfig.buildDependencies or {}); | |
- in buildRustCrate (crateConfig // { inherit features dependencies buildDependencies; }); | |
+ renames = | |
+ lib.mapAttrs (name: value: value.rename or name) (crateConfig.dependencies or {}); | |
+ in buildRustCrate (crateConfig // { inherit features dependencies buildDependencies renames; }); | |
in buildByPackageId packageId; | |
/* Returns the actual derivations for the given dependencies. */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment