at 16.09-beta 127 lines 4.2 kB view raw
1{ stdenv, fetchurl, fetchgit, fetchzip, file, python2, tzdata, procps 2, llvm, jemalloc, ncurses, darwin, binutils, rustPlatform, git, cmake, curl 3 4, isRelease ? false 5, shortVersion 6, forceBundledLLVM ? false 7, srcSha, srcRev 8, configureFlags ? [] 9, patches 10, targets 11, targetPatches 12, targetToolchains 13} @ args: 14 15let 16 inherit (stdenv.lib) optional optionalString; 17 18 version = if isRelease then 19 "${shortVersion}" 20 else 21 "${shortVersion}-g${builtins.substring 0 7 srcRev}"; 22 23 name = "rustc-${version}"; 24 25 procps = if stdenv.isDarwin then darwin.ps else args.procps; 26 27 llvmShared = llvm.override { enableSharedLibraries = true; }; 28 29 target = builtins.replaceStrings [" "] [","] (builtins.toString targets); 30 31 meta = with stdenv.lib; { 32 homepage = http://www.rust-lang.org/; 33 description = "A safe, concurrent, practical language"; 34 maintainers = with maintainers; [ madjar cstrahan wizeman globin havvy wkennington retrry ]; 35 license = [ licenses.mit licenses.asl20 ]; 36 platforms = platforms.linux ++ platforms.darwin; 37 }; 38in 39 40stdenv.mkDerivation { 41 inherit name; 42 inherit version; 43 inherit meta; 44 45 __impureHostDeps = [ "/usr/lib/libedit.3.dylib" ]; 46 47 NIX_LDFLAGS = optionalString stdenv.isDarwin "-rpath ${llvmShared}/lib"; 48 49 src = fetchgit { 50 url = https://github.com/rust-lang/rust; 51 rev = srcRev; 52 sha256 = srcSha; 53 }; 54 55 # We need rust to build rust. If we don't provide it, configure will try to download it. 56 configureFlags = configureFlags 57 ++ [ "--enable-local-rust" "--local-rust-root=${rustPlatform.rust.rustc}" "--enable-rpath" ] 58 # ++ [ "--jemalloc-root=${jemalloc}/lib" 59 ++ [ "--default-linker=${stdenv.cc}/bin/cc" "--default-ar=${binutils.out}/bin/ar" ] 60 ++ optional (stdenv.cc.cc ? isClang) "--enable-clang" 61 ++ optional (targets != []) "--target=${target}" 62 ++ optional (!forceBundledLLVM) "--llvm-root=${llvmShared}"; 63 64 patches = patches ++ targetPatches; 65 66 passthru.target = target; 67 68 postPatch = '' 69 substituteInPlace src/rust-installer/gen-install-script.sh \ 70 --replace /bin/echo "$(type -P echo)" 71 substituteInPlace src/rust-installer/gen-installer.sh \ 72 --replace /bin/echo "$(type -P echo)" 73 74 # Workaround for NixOS/nixpkgs#8676 75 substituteInPlace mk/rustllvm.mk \ 76 --replace "\$\$(subst /,//," "\$\$(subst /,/," 77 78 # Fix dynamic linking against llvm 79 ${optionalString (!forceBundledLLVM) ''sed -i 's/, kind = \\"static\\"//g' src/etc/mklldeps.py''} 80 81 # Fix the configure script to not require curl as we won't use it 82 sed -i configure \ 83 -e '/probe_need CFG_CURL curl/d' 84 85 # Fix the use of jemalloc prefixes which our jemalloc doesn't have 86 # TODO: reenable if we can figure out how to get our jemalloc to work 87 #[ -f src/liballoc_jemalloc/lib.rs ] && sed -i 's,je_,,g' src/liballoc_jemalloc/lib.rs 88 #[ -f src/liballoc/heap.rs ] && sed -i 's,je_,,g' src/liballoc/heap.rs # Remove for 1.4.0+ 89 90 # Disable fragile linker-output-non-utf8 test 91 rm -vr src/test/run-make/linker-output-non-utf8/ 92 93 # Useful debugging parameter 94 # export VERBOSE=1 95 ''; 96 97 preConfigure = '' 98 # Needed flags as the upstream configure script has a broken prefix substitution 99 configureFlagsArray+=("--datadir=$out/share") 100 configureFlagsArray+=("--infodir=$out/share/info") 101 ''; 102 103 # rustc unfortunately need cmake for compiling llvm-rt but doesn't 104 # use it for the normal build. This disables cmake in Nix. 105 dontUseCmakeConfigure = true; 106 107 # ps is needed for one of the test cases 108 nativeBuildInputs = [ file python2 procps rustPlatform.rust.rustc git cmake ]; 109 110 buildInputs = [ ncurses ] ++ targetToolchains 111 ++ optional (!forceBundledLLVM) llvmShared; 112 113 # https://github.com/rust-lang/rust/issues/30181 114 # enableParallelBuilding = false; # missing files during linking, occasionally 115 116 outputs = [ "out" "doc" ]; 117 setOutputFlags = false; 118 119 preCheck = '' 120 export TZDIR=${tzdata}/share/zoneinfo 121 ${optionalString stdenv.isDarwin "export TMPDIR=/tmp"} 122 ''; 123 124 # Disable doCheck on Darwin to work around upstream issue 125 doCheck = true; 126 dontSetConfigureCross = true; 127}