diff options
author | Ricardo M. Correia <rcorreia@wizy.org> | 2015-05-19 18:21:11 +0200 |
---|---|---|
committer | Ricardo M. Correia <rcorreia@wizy.org> | 2015-05-19 19:02:38 +0200 |
commit | 9b752fd0e15df7a4f3d4f94f16883088614a70b7 (patch) | |
tree | d5d224d285f5999d88e6f9f5fc3a0e472fb862ce /pkgs/build-support/rust | |
parent | de322b48b7006cf72d6adc37a833f2e045950536 (diff) | |
download | nixlib-9b752fd0e15df7a4f3d4f94f16883088614a70b7.tar nixlib-9b752fd0e15df7a4f3d4f94f16883088614a70b7.tar.gz nixlib-9b752fd0e15df7a4f3d4f94f16883088614a70b7.tar.bz2 nixlib-9b752fd0e15df7a4f3d4f94f16883088614a70b7.tar.lz nixlib-9b752fd0e15df7a4f3d4f94f16883088614a70b7.tar.xz nixlib-9b752fd0e15df7a4f3d4f94f16883088614a70b7.tar.zst nixlib-9b752fd0e15df7a4f3d4f94f16883088614a70b7.zip |
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).
Diffstat (limited to 'pkgs/build-support/rust')
-rw-r--r-- | pkgs/build-support/rust/default.nix | 30 | ||||
-rwxr-xr-x | pkgs/build-support/rust/fetch-cargo-deps | 7 |
2 files changed, 21 insertions, 16 deletions
diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index ddf2fce3cae5..87115e392daf 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -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" + export CARGO_HOME="$(realpath deps)" - ln -s "$rustRegistry" "deps/registry/index/${registryIndexDirName}" + # 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/*))" - export CARGO_HOME="$(realpath deps)" + 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/ ( diff --git a/pkgs/build-support/rust/fetch-cargo-deps b/pkgs/build-support/rust/fetch-cargo-deps index c7799fb1b1f6..69eb404e6445 100755 --- a/pkgs/build-support/rust/fetch-cargo-deps +++ b/pkgs/build-support/rust/fetch-cargo-deps @@ -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' |