nixpkgs-suyu/pkgs/development/compilers/rust/bootstrap.nix
2016-11-16 13:25:19 +02:00

90 lines
2.6 KiB
Nix

{ stdenv, fetchurl, makeWrapper, cacert, zlib }:
let
inherit (stdenv.lib) optionalString;
platform =
if stdenv.system == "i686-linux"
then "i686-unknown-linux-gnu"
else if stdenv.system == "x86_64-linux"
then "x86_64-unknown-linux-gnu"
else if stdenv.system == "i686-darwin"
then "i686-apple-darwin"
else if stdenv.system == "x86_64-darwin"
then "x86_64-apple-darwin"
else abort "missing boostrap url for platform ${stdenv.system}";
# fetch hashes by running `print-hashes.sh 1.12.1`
bootstrapHash =
if stdenv.system == "i686-linux"
then "ede9b9d14d1ddbc29975d1ead73fcf2758719b4b371363afe1c32eb8d6e96bb3"
else if stdenv.system == "x86_64-linux"
then "9e546aec13e389429ba2d86c8f4e67eba5af146c979e4faa16ffb40ddaf9984c"
else if stdenv.system == "i686-darwin"
then "2648645c4fe1ecf36beb7de63501dd99e9547a7a6d5683acf2693b919a550b69"
else if stdenv.system == "x86_64-darwin"
then "0ac5e58dba3d24bf09dcc90eaac02d2df053122b0def945ec4cfe36ac6d4d011"
else throw "missing boostrap hash for platform ${stdenv.system}";
needsPatchelf = stdenv.isLinux;
src = fetchurl {
url = "https://static.rust-lang.org/dist/rust-${version}-${platform}.tar.gz";
sha256 = bootstrapHash;
};
version = "1.12.1";
in
rec {
rustc = stdenv.mkDerivation rec {
name = "rustc-bootstrap-${version}";
inherit version;
inherit src;
buildInputs = [ makeWrapper ];
phases = ["unpackPhase" "installPhase"];
installPhase = ''
./install.sh --prefix=$out \
--components=rustc,rust-std-${platform},rust-docs
${optionalString needsPatchelf ''
patchelf \
--set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
"$out/bin/rustc"
''}
# Do NOT, I repeat, DO NOT use `wrapProgram` on $out/bin/rustc
# (or similar) here. It causes strange effects where rustc loads
# the wrong libraries in a bootstrap-build causing failures that
# are very hard to track dow. For details, see
# https://github.com/rust-lang/rust/issues/34722#issuecomment-232164943
'';
};
cargo = stdenv.mkDerivation rec {
name = "cargo-bootstrap-${version}";
inherit version;
inherit src;
buildInputs = [ makeWrapper zlib rustc ];
phases = ["unpackPhase" "installPhase"];
installPhase = ''
./install.sh --prefix=$out \
--components=cargo
${optionalString needsPatchelf ''
patchelf \
--set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
"$out/bin/cargo"
''}
wrapProgram "$out/bin/cargo" \
--suffix PATH : "${rustc}/bin"
'';
};
}