2015-01-19 18:41:28 +01:00
|
|
|
{stdenv, fetchurl, which, file, perl, curl, python27, makeWrapper
|
|
|
|
, tzdata, git, valgrind, procps, coreutils
|
|
|
|
}:
|
2014-07-30 06:04:38 +02:00
|
|
|
|
2015-01-04 13:58:46 +01:00
|
|
|
assert !stdenv.isFreeBSD;
|
|
|
|
|
2014-07-30 06:04:38 +02:00
|
|
|
/* Rust's build process has a few quirks :
|
|
|
|
|
|
|
|
- It requires some patched in llvm that haven't landed upstream, so it
|
|
|
|
compiles its own llvm. This might change in the future, so at some
|
|
|
|
point we may be able to switch to nix's llvm.
|
|
|
|
|
|
|
|
- The Rust compiler is written is Rust, so it requires a bootstrap
|
|
|
|
compiler, which is downloaded during the build. To make the build
|
|
|
|
pure, we download it ourself before and put it where it is
|
|
|
|
expected. Once the language is stable (1.0) , we might want to
|
|
|
|
switch it to use nix's packaged rust compiler.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2015-01-19 18:41:28 +01:00
|
|
|
with ((import ./common.nix) {inherit stdenv; version = "1.0.0-alpha"; });
|
2014-07-30 06:04:38 +02:00
|
|
|
|
2015-01-08 09:37:43 +01:00
|
|
|
let snapshotHash = if stdenv.system == "i686-linux"
|
2015-01-19 18:41:28 +01:00
|
|
|
then "d8b73fc9aa3ad72ce1408a41e35d78dba10eb4d4"
|
2014-07-30 06:04:38 +02:00
|
|
|
else if stdenv.system == "x86_64-linux"
|
2015-01-19 18:41:28 +01:00
|
|
|
then "697880d3640e981bbbf23284363e8e9a158b588d"
|
2014-07-31 00:12:16 +02:00
|
|
|
else if stdenv.system == "i686-darwin"
|
2015-01-19 18:41:28 +01:00
|
|
|
then "a73b1fc03e8cac747aab0aa186292bb4332a7a98"
|
2014-07-30 06:04:38 +02:00
|
|
|
else if stdenv.system == "x86_64-darwin"
|
2015-01-19 18:41:28 +01:00
|
|
|
then "e4ae2670ea4ba5c2e5b4245409c9cab45c9eeb5b"
|
2014-07-30 06:04:38 +02:00
|
|
|
else abort "no-snapshot for platform ${stdenv.system}";
|
2015-01-19 18:41:28 +01:00
|
|
|
snapshotDate = "2015-01-07";
|
|
|
|
snapshotRev = "9e4e524";
|
2015-01-08 09:37:43 +01:00
|
|
|
snapshotName = "rust-stage0-${snapshotDate}-${snapshotRev}-${platform}-${snapshotHash}.tar.bz2";
|
2014-07-30 06:04:38 +02:00
|
|
|
|
|
|
|
in stdenv.mkDerivation {
|
|
|
|
inherit name;
|
|
|
|
inherit version;
|
|
|
|
inherit meta;
|
|
|
|
|
|
|
|
src = fetchurl {
|
2015-01-19 18:41:28 +01:00
|
|
|
url = "http://static.rust-lang.org/dist/rustc-${version}-src.tar.gz";
|
|
|
|
sha256 = "0p62gx3s087n09d2v3l9iyfx5cmsa1x91n4ysixcb7w3drr8a8is";
|
2014-07-30 06:04:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
# We need rust to build rust. If we don't provide it, configure will try to download it.
|
|
|
|
snapshot = stdenv.mkDerivation {
|
|
|
|
name = "rust-stage0";
|
|
|
|
src = fetchurl {
|
|
|
|
url = "http://static.rust-lang.org/stage0-snapshots/${snapshotName}";
|
2015-01-08 09:37:43 +01:00
|
|
|
sha1 = snapshotHash;
|
2014-07-30 06:04:38 +02:00
|
|
|
};
|
|
|
|
dontStrip = true;
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p "$out"
|
|
|
|
cp -r bin "$out/bin"
|
|
|
|
'' + (if stdenv.isLinux then ''
|
2014-12-17 19:11:30 +01:00
|
|
|
patchelf --interpreter "${stdenv.glibc}/lib/${stdenv.cc.dynamicLinker}" \
|
|
|
|
--set-rpath "${stdenv.cc.gcc}/lib/:${stdenv.cc.gcc}/lib64/" \
|
2014-07-30 06:04:38 +02:00
|
|
|
"$out/bin/rustc"
|
|
|
|
'' else "");
|
|
|
|
};
|
|
|
|
|
2014-12-17 19:11:30 +01:00
|
|
|
configureFlags = [ "--enable-local-rust" "--local-rust-root=$snapshot" ]
|
|
|
|
++ stdenv.lib.optional (stdenv.cc ? clang) "--enable-clang";
|
2014-07-30 06:04:38 +02:00
|
|
|
|
|
|
|
# The compiler requires cc, so we patch the source to tell it where to find it
|
2015-01-19 18:41:28 +01:00
|
|
|
patches = [ ./hardcode_paths.patch ./local_stage0.patch ]
|
|
|
|
++ stdenv.lib.optional stdenv.needsPax ./grsec.patch;
|
|
|
|
|
2014-07-30 06:04:38 +02:00
|
|
|
postPatch = ''
|
2015-01-19 18:41:28 +01:00
|
|
|
substituteInPlace src/librustc_trans/back/link.rs \
|
2014-12-17 19:11:30 +01:00
|
|
|
--subst-var-by "ccPath" "${stdenv.cc}/bin/cc"
|
2014-10-16 22:24:33 +02:00
|
|
|
substituteInPlace src/librustc_back/archive.rs \
|
2014-12-17 19:11:30 +01:00
|
|
|
--subst-var-by "arPath" "${stdenv.cc.binutils}/bin/ar"
|
2015-01-19 18:41:28 +01:00
|
|
|
|
|
|
|
substituteInPlace src/rust-installer/gen-install-script.sh \
|
|
|
|
--replace /bin/echo "${coreutils}/bin/echo"
|
|
|
|
substituteInPlace src/rust-installer/gen-installer.sh \
|
|
|
|
--replace /bin/echo "${coreutils}/bin/echo"
|
2014-07-30 06:04:38 +02:00
|
|
|
'';
|
|
|
|
|
2015-01-19 18:41:28 +01:00
|
|
|
buildInputs = [ which file perl curl python27 makeWrapper git valgrind procps ];
|
|
|
|
|
|
|
|
enableParallelBuilding = false; # disabled due to rust-lang/rust#16305
|
|
|
|
|
|
|
|
preCheck = "export TZDIR=${tzdata}/share/zoneinfo";
|
|
|
|
|
|
|
|
doCheck = true;
|
2014-07-30 06:04:38 +02:00
|
|
|
}
|