3
0
Fork 0
forked from mirrors/nixpkgs

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 18:21:11 +02:00
parent de322b48b7
commit 9b752fd0e1
4 changed files with 24 additions and 19 deletions

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/
(

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'

View file

@ -15,7 +15,7 @@ buildRustPackage rec {
leaveDotGit = true;
};
depsSha256 = "0s9f00kg7q9dxd8g98k3z4qv404p9ra73l1bzxs6qzk54qhg44dp";
depsSha256 = "1b0mpdxmp7inkg59n2phjwzpz5gx22wqg9rfd1s01a5ylara37jw";
buildInputs = [ file curl pkgconfig python openssl cmake zlib ];

View file

@ -11,7 +11,7 @@ buildRustPackage rec {
sha256 = "0g420cbqpknhl61a4mpk3bbia8agf657d9vzzcqr338lmni80qz7";
};
depsSha256 = "1wmpd2cjmk59382dq59hmb0xa6fxbnmmaz4nfs96qf613r5ylvra";
depsSha256 = "0s951apqcr96lvc1jamk6qw3631gwnlnfgcx55vlznfm7shnmywn";
buildInputs = [ makeWrapper ];