buildRustPackage: Don't hardcode registry index hash

Instead, discover it automatically when building the package.

This makes `buildRustPackage` more future-proof with respect to changes
in how `cargo` generates the hash.

Also, it fixes broken builds in i686 because apparently, cargo generates
a different registry index hash in this architecture (compared to
x86-64).
This commit is contained in:
Ricardo M. Correia
2015-05-19 19:02:38 +02:00
parent de322b48b7
commit 9b752fd0e1
4 changed files with 24 additions and 19 deletions
+20 -12
View File
@@ -11,14 +11,6 @@ let
sha256 = depsSha256;
};
# The following is the directory name cargo creates when the registry index
# URL is file:///dev/null
#
# It's OK to use /dev/null as the URL because by the time we do this, cargo
# won't attempt to update the registry anymore, so the URL is more or less
# irrelevant
registryIndexDirName = "-ba82b75dd6681d6f";
in stdenv.mkDerivation (args // {
inherit cargoDeps rustRegistry;
@@ -34,18 +26,34 @@ in stdenv.mkDerivation (args // {
cp -r "$cargoDeps" deps
chmod +w deps -R
# It's OK to use /dev/null as the URL because by the time we do this, cargo
# won't attempt to update the registry anymore, so the URL is more or less
# irrelevant
cat <<EOF > deps/config
[registry]
index = "file:///dev/null"
EOF
echo "Using rust registry from $rustRegistry"
ln -s "$rustRegistry" "deps/registry/index/${registryIndexDirName}"
export CARGO_HOME="$(realpath deps)"
# Let's find out which $indexHash cargo uses for file:///dev/null
(cd $sourceRoot && cargo fetch &>/dev/null)
cd deps
indexHash="$(basename $(echo registry/index/*))"
echo "Using indexHash '$indexHash'"
rm -rf -- "registry/cache/$indexHash" \
"registry/index/$indexHash"
mv registry/cache/HASH "registry/cache/$indexHash"
echo "Using rust registry from $rustRegistry"
ln -s "$rustRegistry" "registry/index/$indexHash"
# Retrieved the Cargo.lock file which we saved during the fetch
cd ..
mv deps/Cargo.lock $sourceRoot/
(
+2 -5
View File
@@ -104,12 +104,9 @@ substituteInPlace Cargo.lock \
set -u
mv Cargo.lock $out/
# The following is the $indexHash cargo uses for the registry index when
# its URL is file:///dev/null, which is the registry index URL we use to make
# sure our output is deterministic.
registryIndexDirName="-ba82b75dd6681d6f"
mv $out/registry/cache/* $out/registry/cache/$registryIndexDirName
# Let's replace $indexHash with something more deterministic
mv $out/registry/cache/* $out/registry/cache/HASH
# The registry index changes all the time, so it's not deterministic
# We'll symlink it before running 'cargo build'