From 2b694c237b5a19594774420a6929a9470ad81a28 Mon Sep 17 00:00:00 2001 From: "Ricardo M. Correia" Date: Tue, 17 Nov 2015 19:32:03 +0100 Subject: [PATCH] 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 --- pkgs/build-support/rust/default.nix | 6 ++--- pkgs/build-support/rust/fetchcargo.nix | 4 +-- .../tools/build-managers/cargo/common.nix | 6 ++++- .../tools/build-managers/cargo/default.nix | 13 +++++---- .../tools/build-managers/cargo/snapshot.nix | 15 ++++++----- pkgs/top-level/all-packages.nix | 27 +++++++++++-------- 6 files changed, 43 insertions(+), 28 deletions(-) diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index c23581d96019..e0d451417780 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -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"; diff --git a/pkgs/build-support/rust/fetchcargo.nix b/pkgs/build-support/rust/fetchcargo.nix index 0ce1d0a11d32..95eefbedc327 100644 --- a/pkgs/build-support/rust/fetchcargo.nix +++ b/pkgs/build-support/rust/fetchcargo.nix @@ -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"; diff --git a/pkgs/development/tools/build-managers/cargo/common.nix b/pkgs/development/tools/build-managers/cargo/common.nix index 94b9ca1f6655..941fe8073075 100644 --- a/pkgs/development/tools/build-managers/cargo/common.nix +++ b/pkgs/development/tools/build-managers/cargo/common.nix @@ -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"; diff --git a/pkgs/development/tools/build-managers/cargo/default.nix b/pkgs/development/tools/build-managers/cargo/default.nix index c614e8c23863..bdd6c18e92c7 100644 --- a/pkgs/development/tools/build-managers/cargo/default.nix +++ b/pkgs/development/tools/build-managers/cargo/default.nix @@ -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 diff --git a/pkgs/development/tools/build-managers/cargo/snapshot.nix b/pkgs/development/tools/build-managers/cargo/snapshot.nix index f24bcc2d9ab8..ad07148815bb 100644 --- a/pkgs/development/tools/build-managers/cargo/snapshot.nix +++ b/pkgs/development/tools/build-managers/cargo/snapshot.nix @@ -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; } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 744ad14e4c95..8fcc8a6b4193 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -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 { };