diff options
author | Ricardo M. Correia <rcorreia@wizy.org> | 2015-04-23 02:43:11 +0200 |
---|---|---|
committer | Ricardo M. Correia <rcorreia@wizy.org> | 2015-04-23 02:58:07 +0200 |
commit | e42c17ee9709c8fddbaee7d79c0d13f330443582 (patch) | |
tree | acfc4cbf89124ca51c005715431576e62c6cd191 /pkgs/build-support/rust | |
parent | d648be67246e771126defb34989ecb9f88292c64 (diff) | |
download | nixlib-e42c17ee9709c8fddbaee7d79c0d13f330443582.tar nixlib-e42c17ee9709c8fddbaee7d79c0d13f330443582.tar.gz nixlib-e42c17ee9709c8fddbaee7d79c0d13f330443582.tar.bz2 nixlib-e42c17ee9709c8fddbaee7d79c0d13f330443582.tar.lz nixlib-e42c17ee9709c8fddbaee7d79c0d13f330443582.tar.xz nixlib-e42c17ee9709c8fddbaee7d79c0d13f330443582.tar.zst nixlib-e42c17ee9709c8fddbaee7d79c0d13f330443582.zip |
buildRustPackage: Fix Cargo.lock being ignored
It turns out that `cargo`, with respect to registry dependencies, was ignoring the package versions locked in `Cargo.lock` because we changed the registry index URL. Therefore, every time `rustRegistry` would be updated, we'd always try to use the latest version available for every dependency and as a result the deps' SHA256 hashes would almost always have to be changed. To fix this, now we do a string substitution in `Cargo.lock` of the `crates.io` registry URL with our URL. This should be safe because our registry is just a copy of the `crates.io` registry at a certain point in time. Since now we don't always use the latest version of every dependency, the build of `cargo` actually started to fail because two of the dependencies specified in its `Cargo.lock` file have build failures. To fix the latter problem, I've added a `cargoUpdateHook` variable that gets ran both when fetching dependencies and just before building the program. The purpose of `cargoUpdateHook` is to do any ad-hoc updating of dependencies necessary to get the package to build. The use of the '--precise' flag is needed so that cargo doesn't try to fetch an even newer version whenever `rustRegistry` is updated (and therefore have to change depsSha256 as a consequence).
Diffstat (limited to 'pkgs/build-support/rust')
-rw-r--r-- | pkgs/build-support/rust/default.nix | 15 | ||||
-rwxr-xr-x | pkgs/build-support/rust/fetch-cargo-deps | 15 | ||||
-rw-r--r-- | pkgs/build-support/rust/fetchcargo.nix | 4 |
3 files changed, 26 insertions, 8 deletions
diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index 45d706b8c562..6a5e4b86194f 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -1,5 +1,5 @@ { stdenv, cacert, git, rustc, cargo, rustRegistry }: -{ name, src, depsSha256, buildInputs ? [], ... } @ args: +{ name, src, depsSha256, buildInputs ? [], cargoUpdateHook ? "", ... } @ args: let fetchDeps = import ./fetchcargo.nix { @@ -7,12 +7,12 @@ let }; cargoDeps = fetchDeps { - inherit name src; + inherit name src cargoUpdateHook; sha256 = depsSha256; }; in stdenv.mkDerivation (args // { - inherit cargoDeps rustRegistry; + inherit cargoDeps rustRegistry cargoUpdateHook; buildInputs = [ git cargo rustc ] ++ buildInputs; @@ -23,8 +23,15 @@ in stdenv.mkDerivation (args // { ( cd $sourceRoot ln -s $rustRegistry ./cargo-rust-registry - cargo clean + + substituteInPlace Cargo.lock \ + --replace "registry+https://github.com/rust-lang/crates.io-index" \ + "registry+file:///proc/self/cwd/cargo-rust-registry" + + eval "$cargoUpdateHook" + cargo fetch + cargo clean ) '' + (args.postUnpack or ""); diff --git a/pkgs/build-support/rust/fetch-cargo-deps b/pkgs/build-support/rust/fetch-cargo-deps index d6579fe94bda..f0a21e673cd9 100755 --- a/pkgs/build-support/rust/fetch-cargo-deps +++ b/pkgs/build-support/rust/fetch-cargo-deps @@ -1,6 +1,8 @@ -#! /bin/sh -eu +#! /bin/sh -set -o pipefail +source $stdenv/setup + +set -euo pipefail src=$(realpath $1) out=$(realpath $2) @@ -38,6 +40,15 @@ EOF export CARGO_HOME=$out cd $src + +set +u +substituteInPlace Cargo.lock \ + --replace "registry+https://github.com/rust-lang/crates.io-index" \ + "registry+file:///proc/self/cwd/cargo-rust-registry" +set -u + +eval "$cargoUpdateHook" + cargo fetch --verbose # TODO: check that Cargo.lock exists, and hasn't changed diff --git a/pkgs/build-support/rust/fetchcargo.nix b/pkgs/build-support/rust/fetchcargo.nix index cd5d69e06d0d..7ebd02a485d7 100644 --- a/pkgs/build-support/rust/fetchcargo.nix +++ b/pkgs/build-support/rust/fetchcargo.nix @@ -1,12 +1,12 @@ { stdenv, cacert, git, rustc, cargo, rustRegistry }: -{ name ? "cargo-deps", src, sha256 }: +{ name ? "cargo-deps", src, sha256, cargoUpdateHook ? "" }: stdenv.mkDerivation { name = "${name}-fetch"; buildInputs = [ rustc cargo git ]; builder = ./fetch-builder.sh; fetcher = ./fetch-cargo-deps; - inherit src rustRegistry; + inherit src rustRegistry cargoUpdateHook; outputHashAlgo = "sha256"; outputHashMode = "recursive"; |