buildRustCrate: document and cleanup the symbol seeding

That code had been in the derivation for a while but no explanation was
given why that is needed. It might be helpful to our future selfs to
document why things are done the way they are.
This commit is contained in:
Andreas Rammhold
2019-12-11 23:23:55 +01:00
parent db55d1f89d
commit f4aeabd04a
@@ -93,8 +93,13 @@ stdenv.mkDerivation (rec {
libName = if crate ? libName then crate.libName else crate.crateName; libName = if crate ? libName then crate.libName else crate.crateName;
libPath = if crate ? libPath then crate.libPath else ""; libPath = if crate ? libPath then crate.libPath else "";
depsMetadata = lib.foldl' (str: dep: str + dep.metadata) "" (dependencies ++ buildDependencies); # Seed the symbol hashes with something unique every time.
metadata = lib.substring 0 10 (builtins.hashString "sha256" (crateName + "-" + crateVersion + "___" + toString crateFeatures + "___" + depsMetadata )); # https://doc.rust-lang.org/1.0.0/rustc/metadata/loader/index.html#frobbing-symbols
metadata = let
depsMetadata = lib.foldl' (str: dep: str + dep.metadata) "" (dependencies ++ buildDependencies);
hashedMetadata = builtins.hashString "sha256"
(crateName + "-" + crateVersion + "___" + toString crateFeatures + "___" + depsMetadata);
in lib.substring 0 10 hashedMetadata;
crateBin = if crate ? crateBin then crateBin = if crate ? crateBin then
lib.foldl' (bins: bin: let lib.foldl' (bins: bin: let