3
0
Fork 0
forked from mirrors/nixpkgs

cargo, cargoSnapshot: add rustc runtime dependency

It turns out that cargo implicitly depends on rustc at runtime: even
`cargo help` will fail if rustc is not in the PATH.

This means that we need to wrap the cargo binary to add rustc to PATH.
However, I have opted into doing something slightly unusual: instead of
tying down a specific cargo to use a specific rustc (i.e., wrap cargo so
that "${rustc}/bin" is prefixed into PATH), instead I'm adding the rustc
used to build cargo as a fallback rust compiler (i.e., wrap cargo so
that "${rustc}/bin" is suffixed into PATH). This means that cargo will
prefer to use a rust compiler that is in the default path, but fallback
into the one used to build cargo only if there wasn't any rust compiler
in the default path.

The reason I'm doing this is that otherwise it could cause unexpected
effects. For example, if you had a build environment with the
rustcMaster and cargo derivations, you would expect cargo to use
rustcMaster to compile your project (since rustcMaster would be the only
compiler available in $PATH), but this wouldn't happen if we tied down
cargo to use the rustc that was used to compile it (because the default
cargo derivation gets compiled with the stable rust compiler).

That said, I have slightly modified makeRustPlatform so that a rust
platform will always use the rust compiler that was used to build cargo,
because this prevents mistakenly depending on two different versions of
the rust compiler (stable and unstable) in the same rust platform,
something which is usually undesirable.

Fixes #11053
This commit is contained in:
Ricardo M. Correia 2015-11-17 19:32:03 +01:00
parent 893179e9c1
commit 2b694c237b
6 changed files with 43 additions and 28 deletions

View file

@ -1,4 +1,4 @@
{ stdenv, cacert, git, rustc, cargo, rustRegistry }:
{ stdenv, cacert, git, cargo, rustRegistry }:
{ name, depsSha256
, src ? null
, srcs ? null
@ -9,7 +9,7 @@
let
fetchDeps = import ./fetchcargo.nix {
inherit stdenv cacert git rustc cargo rustRegistry;
inherit stdenv cacert git cargo rustRegistry;
};
cargoDeps = fetchDeps {
@ -22,7 +22,7 @@ in stdenv.mkDerivation (args // {
patchRegistryDeps = ./patch-registry-deps;
buildInputs = [ git cargo rustc ] ++ buildInputs;
buildInputs = [ git cargo cargo.rustc ] ++ buildInputs;
configurePhase = args.configurePhase or "true";

View file

@ -1,9 +1,9 @@
{ stdenv, cacert, git, rustc, cargo, rustRegistry }:
{ stdenv, cacert, git, cargo, rustRegistry }:
{ name ? "cargo-deps", src, srcs, sourceRoot, sha256, cargoUpdateHook ? "" }:
stdenv.mkDerivation {
name = "${name}-fetch";
buildInputs = [ rustc cargo git ];
buildInputs = [ cargo git ];
inherit src srcs sourceRoot rustRegistry cargoUpdateHook;
phases = "unpackPhase installPhase";

View file

@ -1,4 +1,4 @@
{stdenv, version}:
{stdenv, version, rustc}:
{
inherit version;
@ -11,6 +11,8 @@
"$out/lib/rustlib/rust-installer-version" \
"$out/lib/rustlib/uninstall.sh" \
"$out/lib/rustlib/manifest-cargo"
wrapProgram "$out/bin/cargo" --suffix PATH : "${rustc}/bin"
'';
platform = if stdenv.system == "i686-linux"
@ -23,6 +25,8 @@
then "x86_64-apple-darwin"
else throw "no snapshot to bootstrap for this platform (missing platform url suffix)";
passthru.rustc = rustc;
meta = with stdenv.lib; {
homepage = http://crates.io;
description = "Downloads your Rust project's dependencies and builds your project";

View file

@ -1,12 +1,15 @@
{ stdenv, fetchgit, rustPlatform, file, curl, python, pkgconfig, openssl
, cmake, zlib }:
with ((import ./common.nix) { inherit stdenv; version = "0.6.0"; });
, cmake, zlib, makeWrapper }:
with rustPlatform;
with ((import ./common.nix) {
inherit stdenv rustc;
version = "0.6.0";
});
buildRustPackage rec {
inherit name version meta;
inherit name version meta passthru;
# Needs to use fetchgit instead of fetchFromGitHub to fetch submodules
src = fetchgit {
@ -17,7 +20,7 @@ buildRustPackage rec {
depsSha256 = "1m045yywv67sx75idbsny59d3dzbqnhr07k41jial5n5zwp87mb9";
buildInputs = [ file curl pkgconfig python openssl cmake zlib ];
buildInputs = [ file curl pkgconfig python openssl cmake zlib makeWrapper ];
configurePhase = ''
./configure --enable-optimize --prefix=$out --local-cargo=${cargo}/bin/cargo

View file

@ -1,11 +1,14 @@
{ stdenv, fetchurl, zlib }:
{ stdenv, fetchurl, zlib, makeWrapper, rustc }:
/* Cargo binary snapshot */
let snapshotDate = "2015-06-17";
in
with ((import ./common.nix) { inherit stdenv; version = "snapshot-${snapshotDate}"; });
with ((import ./common.nix) {
inherit stdenv rustc;
version = "snapshot-${snapshotDate}";
});
let snapshotHash = if stdenv.system == "i686-linux"
then "g2h9l35123r72hqdwayd9h79kspfb4y9"
@ -20,23 +23,23 @@ let snapshotHash = if stdenv.system == "i686-linux"
in
stdenv.mkDerivation {
inherit name version meta;
inherit name version meta passthru;
src = fetchurl {
url = "https://static-rust-lang-org.s3.amazonaws.com/cargo-dist/${snapshotDate}/${snapshotName}";
sha1 = snapshotHash;
};
buildInputs = [ makeWrapper ];
dontStrip = true;
installPhase = ''
mkdir -p "$out"
./install.sh "--prefix=$out"
${postInstall}
'' + (if stdenv.isLinux then ''
patchelf --interpreter "${stdenv.glibc}/lib/${stdenv.cc.dynamicLinker}" \
--set-rpath "${stdenv.cc.cc}/lib/:${stdenv.cc.cc}/lib64/:${zlib}/lib" \
"$out/bin/cargo"
'' else "");
'' else "") + postInstall;
}

View file

@ -4773,23 +4773,27 @@ let
rustPlatform = rustStable;
rustStable = recurseIntoAttrs (makeRustPlatform rustc cargo rustStable);
rustUnstable = recurseIntoAttrs (makeRustPlatform rustcMaster
(cargo.override { rustPlatform = rustUnstableCargoPlatform; }) rustUnstable);
rustStable = recurseIntoAttrs (makeRustPlatform cargo rustStable);
rustUnstable = recurseIntoAttrs (makeRustPlatform
(cargo.override { rustPlatform = rustUnstableCargoPlatform; }) rustUnstable);
# rust platform to build cargo itself (with cargoSnapshot)
rustCargoPlatform = makeRustPlatform rustc cargoSnapshot.cargo rustCargoPlatform;
rustUnstableCargoPlatform = makeRustPlatform rustcMaster cargoSnapshot.cargo rustUnstableCargoPlatform;
rustCargoPlatform = makeRustPlatform (cargoSnapshot rustc) rustCargoPlatform;
rustUnstableCargoPlatform = makeRustPlatform (cargoSnapshot rustcMaster) rustUnstableCargoPlatform;
makeRustPlatform = rustc: cargo: self:
makeRustPlatform = cargo: self:
let
callPackage = newScope self;
in {
inherit rustc cargo;
inherit cargo;
rustc = cargo.rustc;
rustRegistry = callPackage ./rust-packages.nix { };
buildRustPackage = callPackage ../build-support/rust { };
buildRustPackage = callPackage ../build-support/rust {
inherit cargo;
};
};
rustfmt = callPackage ../development/tools/rust/rustfmt { };
@ -5422,9 +5426,10 @@ let
rustPlatform = rustCargoPlatform;
};
cargoSnapshot = {
cargo = callPackage ../development/tools/build-managers/cargo/snapshot.nix { };
};
cargoSnapshot = rustc:
callPackage ../development/tools/build-managers/cargo/snapshot.nix {
inherit rustc;
};
casperjs = callPackage ../development/tools/casperjs { };