Skip to content

Commit

Permalink
rust: add update script
Browse files Browse the repository at this point in the history
- script to automatically checksums for stable, beta, nightly (only dependency closure needs to be updated manually)
- unify code for bootstraping + add platforms for all channels
- fix rustc sandbox builds (cargo no longer download the registry)
  • Loading branch information
Mic92 committed Jan 17, 2017
1 parent 0abf358 commit f2392b6
Show file tree
Hide file tree
Showing 18 changed files with 564 additions and 370 deletions.
58 changes: 0 additions & 58 deletions pkgs/development/compilers/rust/beta.nix

This file was deleted.

90 changes: 0 additions & 90 deletions pkgs/development/compilers/rust/bootstrap.nix

This file was deleted.

33 changes: 33 additions & 0 deletions pkgs/development/compilers/rust/cargo-bin.nix
@@ -0,0 +1,33 @@
{ stdenv, fetchurl, makeWrapper, sources, channel }:

with stdenv.lib;

let
metadata = sources.${channel}.cargo.${stdenv.system};
in stdenv.mkDerivation rec {
name = "cargo-nightly-${metadata.version}";

src = fetchurl {
inherit (metadata) url sha256;
};

buildInputs = [ makeWrapper ];
phases = ["unpackPhase" "installPhase"];

installPhase = ''
./install.sh --prefix=$out --components=cargo
${optionalString stdenv.isLinux ''
patchelf \
--set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
"$out/bin/cargo"
''}
'';

meta = {
homepage = http://www.rust-lang.org/;
description = "Downloads your Rust project's dependencies and builds your project";
license = [ licenses.mit licenses.asl20 ];
inherit rustMaintainers;
};
}
1 change: 1 addition & 0 deletions pkgs/development/compilers/rust/cargo.nix
Expand Up @@ -11,6 +11,7 @@ rustPlatform.buildRustPackage rec {
url = "https://github.com/rust-lang/cargo";
rev = srcRev;
sha256 = srcSha;
fetchSubmodules = true;
};

inherit depsSha256;
Expand Down
190 changes: 161 additions & 29 deletions pkgs/development/compilers/rust/default.nix
@@ -1,36 +1,168 @@
{ stdenv, callPackage, recurseIntoAttrs, makeRustPlatform,
targets ? [], targetToolchains ? [], targetPatches ? [] }:
{ stdenv, fetchurl, callPackage, gdb, recurseIntoAttrs, makeRustPlatform, buildEnv,
targets ? [], targetToolchains ? [], targetPatches ? [],
makeWrapper}:

with stdenv.lib;
let
rustPlatform = recurseIntoAttrs (makeRustPlatform (callPackage ./bootstrap.nix {}));
in
rec {
rustc = callPackage ./rustc.nix {
shortVersion = "1.14";
isRelease = true;
forceBundledLLVM = false;
configureFlags = [ "--release-channel=stable" ];
srcRev = "e8a0123241f0d397d39cd18fcc4e5e7edde22730";
srcSha = "1sla3gnx9dqvivnyhvwz299mc3jmdy805q2y5xpmpi1vhfk0bafx";

patches = [
./patches/disable-lockfile-check-stable.patch
./patches/darwin-disable-fragile-tcp-tests.patch
] ++ stdenv.lib.optional stdenv.needsPax ./patches/grsec.patch;

inherit targets;
inherit targetPatches;
inherit targetToolchains;
inherit rustPlatform;
};

cargo = callPackage ./cargo.nix rec {
version = "0.15.0";
srcRev = "298a0127f703d4c2500bb06d309488b92ef84ae1";
srcSha = "0v74r18vszapw2rfk7w72czkp9gbq4s1sggphm5vx0kyh058dxc5";
depsSha256 = "0ksiywli8r4lkprfknm0yz1w27060psi3db6wblqmi8sckzdm44h";
sources = builtins.fromJSON (builtins.readFile ./sources.json);

rustMaintainers = with maintainers;
[ qknight madjar cstrahan wizeman globin havvy wkennington retrry ];

rustcSrc = {
channel,
rustPlatform,
forceBundledLLVM ? false,
supportsVendoring ? true,
targets ? [],
targetPatches ? [],
targetToolchains ? []
} @ args:
let
metadata = sources.${channel}.rust-src.all;
in callPackage ./rustc.nix {
inherit (metadata) version;
configureFlags = [ "--release-channel=${channel}" ];
srcUrl = metadata.url;
srcSha = metadata.sha256;

patches = ["${./patches}${channel}/*.patch"]
++ (stdenv.lib.optional stdenv.needsPax ./patches/grsec.patch);

inherit rustPlatform targets targetPatches targetToolchains forceBundledLLVM supportsVendoring;
};

cargoSrc = { channel, rustc, rustPlatform, depsSha256 } @ args:
let
metadata = sources.${channel}.cargo-src.all;
in callPackage ./cargo.nix rec {
inherit (metadata) version;
srcSha = metadata.sha256;
srcRev = metadata.revision;

inherit depsSha256;
inherit rustc; # the rustc that will be wrapped by cargo
inherit rustPlatform; # used to build cargo
};

rustcBin = channel: callPackage ./rustc-bin.nix {
inherit sources channel;
};

cargoBin = channel: callPackage ./cargo-bin.nix {
inherit sources channel;
};

# Rust wants cargo next to rustc.
# Could be simplified when https://github.com/rust-lang/rust/issues/38950 is fixed
bootstrapPlatform = rust: makeRustPlatform {
rustc = stdenv.mkDerivation {
name = "rust-cargo-bundle";
src = null;
phases = "installPhase";
installPhase = ''
mkdir -p $out/{bin,lib}
cp -sR ${rust.rustc}/* $out/
ln -s ${rust.cargo}/bin/cargo $out/bin/cargo
'';
};
inherit (rust) cargo;
};

removeFailingDebugInfoTests = ''
# Remove failing debuginfo tests because of old gdb version (<v8):
# https://github.com/rust-lang/rust/issues/38948#issuecomment-271443596
remove=(borrowed-enum.rs \
generic-struct-style-enum.rs \
generic-tuple-style-enum.rs \
packed-struct.rs \
recursive-struct.rs \
struct-in-enum.rs \
struct-style-enum.rs \
tuple-style-enum.rs \
union-smoke.rs \
unique-enum.rs)
for f in ''${remove[@]}; do
rm -vr src/test/debuginfo/$f || true
done
'';
in rec {
rustStableBin = {
rustc = rustcBin "stable";
cargo = cargoBin "stable";
};

rustStable = let
platform = bootstrapPlatform rustStableBin;
in {
rustc = rustcSrc {
channel = "stable";
rustPlatform = platform;
supportsVendoring = false;
};

cargo = cargoSrc {
channel = "stable";
rustPlatform = platform;
rustc = rustStable.rustc;
depsSha256 = "0ksiywli8r4lkprfknm0yz1w27060psi3db6wblqmi8sckzdm44h";
};
};

rustBetaBin = {
rustc = rustcBin "beta";
cargo = cargoBin "beta";
};

rustBeta = let
platform = bootstrapPlatform rustBetaBin;
in {
rustc = overrideDerivation (rustcSrc {
channel = "beta";
rustPlatform = platform;
# TODO: figure out why linking fails without this
forceBundledLLVM = true;
}) (oldAttrs: {
nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ gdb rustBetaBin.cargo ];
postPatch = ''
${oldAttrs.postPatch}
${removeFailingDebugInfoTests}
'';
});

cargo = cargoSrc {
channel = "beta";
rustPlatform = platform;
rustc = rustBetaBin.rustc;
depsSha256 = "11s2xpgfhl4mb4wa2nk4mzsypr7m9daxxc7l0vraiz5cr77gk7qq";
};
};

rustNightlyBin = {
rustc = rustcBin "nightly";
cargo = cargoBin "nightly";
};

rustNightly = let
platform = bootstrapPlatform rustNightlyBin;
in {
rustc = overrideDerivation (rustcSrc {
channel = "nightly";
rustPlatform = platform;
forceBundledLLVM = true;
}) (oldAttrs: {
nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ gdb rustNightlyBin.cargo ];
postPatch = ''
${oldAttrs.postPatch}
${removeFailingDebugInfoTests}
'';
});

cargo = cargoSrc {
channel = "nightly";
rustPlatform = platform;
rustc = rustNightlyBin.rustc;
depsSha256 = "1sywnhzgambmqsjs2xlnzracfv7vjljha55hgf8wca2marafr5dp";
};
};
}

0 comments on commit f2392b6

Please sign in to comment.