at 17.09-beta 5.5 kB view raw
1{ stdenv, fetchurl, fetchgit, fetchzip, file, python2, tzdata, procps 2, llvm, jemalloc, ncurses, darwin, binutils, rustPlatform, git, cmake, curl 3, which, libffi, gdb 4, version 5, forceBundledLLVM ? false 6, src 7, configureFlags ? [] 8, patches 9, targets 10, targetPatches 11, targetToolchains 12, doCheck ? true 13, buildPlatform, hostPlatform 14} @ args: 15 16let 17 inherit (stdenv.lib) optional optionalString; 18 19 procps = if stdenv.isDarwin then darwin.ps else args.procps; 20 21 llvmShared = llvm.override { enableSharedLibraries = true; }; 22 23 target = builtins.replaceStrings [" "] [","] (builtins.toString targets); 24 25in 26 27stdenv.mkDerivation { 28 name = "rustc-${version}"; 29 inherit version; 30 31 inherit src; 32 33 __impureHostDeps = [ "/usr/lib/libedit.3.dylib" ]; 34 35 NIX_LDFLAGS = optionalString stdenv.isDarwin "-rpath ${llvmShared}/lib"; 36 37 # Enable nightly features in stable compiles (used for 38 # bootstrapping, see https://github.com/rust-lang/rust/pull/37265). 39 # This loosens the hard restrictions on bootstrapping-compiler 40 # versions. 41 RUSTC_BOOTSTRAP = "1"; 42 43 # Increase codegen units to introduce parallelism within the compiler. 44 RUSTFLAGS = "-Ccodegen-units=10"; 45 46 # We need rust to build rust. If we don't provide it, configure will try to download it. 47 configureFlags = configureFlags 48 ++ [ "--enable-local-rust" "--local-rust-root=${rustPlatform.rust.rustc}" "--enable-rpath" ] 49 ++ [ "--enable-vendor" "--disable-locked-deps" ] 50 ++ [ "--enable-llvm-link-shared" ] 51 # ++ [ "--jemalloc-root=${jemalloc}/lib" 52 ++ [ "--default-linker=${stdenv.cc}/bin/cc" "--default-ar=${binutils.out}/bin/ar" ] 53 ++ optional (stdenv.cc.cc ? isClang) "--enable-clang" 54 ++ optional (targets != []) "--target=${target}" 55 ++ optional (!forceBundledLLVM) "--llvm-root=${llvmShared}"; 56 57 patches = patches ++ targetPatches; 58 59 passthru.target = target; 60 61 postPatch = '' 62 # Fix dynamic linking against llvm 63 #${optionalString (!forceBundledLLVM) ''sed -i 's/, kind = \\"static\\"//g' src/etc/mklldeps.py''} 64 65 # Fix the configure script to not require curl as we won't use it 66 sed -i configure \ 67 -e '/probe_need CFG_CURL curl/d' 68 69 # Fix the use of jemalloc prefixes which our jemalloc doesn't have 70 # TODO: reenable if we can figure out how to get our jemalloc to work 71 #[ -f src/liballoc_jemalloc/lib.rs ] && sed -i 's,je_,,g' src/liballoc_jemalloc/lib.rs 72 #[ -f src/liballoc/heap.rs ] && sed -i 's,je_,,g' src/liballoc/heap.rs # Remove for 1.4.0+ 73 74 # Disable fragile linker-output-non-utf8 test 75 rm -vr src/test/run-make/linker-output-non-utf8 || true 76 77 # Remove test targeted at LLVM 3.9 - https://github.com/rust-lang/rust/issues/36835 78 rm -vr src/test/run-pass/issue-36023.rs || true 79 80 # Disable test getting stuck on hydra - possible fix: 81 # https://reviews.llvm.org/rL281650 82 rm -vr src/test/run-pass/issue-36474.rs || true 83 84 # Disable some failing gdb tests. Try re-enabling these when gdb 85 # is updated past version 7.12. 86 rm src/test/debuginfo/basic-types-globals.rs 87 rm src/test/debuginfo/basic-types-mut-globals.rs 88 rm src/test/debuginfo/c-style-enum.rs 89 rm src/test/debuginfo/lexical-scopes-in-block-expression.rs 90 rm src/test/debuginfo/limited-debuginfo.rs 91 rm src/test/debuginfo/simple-struct.rs 92 rm src/test/debuginfo/simple-tuple.rs 93 rm src/test/debuginfo/union-smoke.rs 94 rm src/test/debuginfo/vec-slices.rs 95 rm src/test/debuginfo/vec.rs 96 97 # Useful debugging parameter 98 # export VERBOSE=1 99 '' 100 + optionalString stdenv.isDarwin '' 101 # Disable all lldb tests. 102 # error: Can't run LLDB test because LLDB's python path is not set 103 rm -vr src/test/debuginfo/* 104 ''; 105 106 preConfigure = '' 107 # Needed flags as the upstream configure script has a broken prefix substitution 108 configureFlagsArray+=("--datadir=$out/share") 109 configureFlagsArray+=("--infodir=$out/share/info") 110 ''; 111 112 # rustc unfortunately need cmake for compiling llvm-rt but doesn't 113 # use it for the normal build. This disables cmake in Nix. 114 dontUseCmakeConfigure = true; 115 116 # ps is needed for one of the test cases 117 nativeBuildInputs = 118 [ file python2 procps rustPlatform.rust.rustc git cmake 119 which libffi 120 ] 121 # Only needed for the debuginfo tests 122 ++ optional (!stdenv.isDarwin) gdb; 123 124 buildInputs = [ ncurses ] ++ targetToolchains 125 ++ optional (!forceBundledLLVM) llvmShared; 126 127 outputs = [ "out" "man" "doc" ]; 128 setOutputFlags = false; 129 130 # Disable codegen units for the tests. 131 preCheck = '' 132 export RUSTFLAGS= 133 export TZDIR=${tzdata}/share/zoneinfo 134 '' + 135 # Ensure TMPDIR is set, and disable a test that removing the HOME 136 # variable from the environment falls back to another home 137 # directory. 138 optionalString stdenv.isDarwin '' 139 export TMPDIR=/tmp 140 sed -i '28s/home_dir().is_some()/true/' ./src/test/run-pass/env-home-dir.rs 141 ''; 142 143 inherit doCheck; 144 145 configurePlatforms = []; 146 147 # https://github.com/NixOS/nixpkgs/pull/21742#issuecomment-272305764 148 # https://github.com/rust-lang/rust/issues/30181 149 # enableParallelBuilding = false; 150 151 meta = with stdenv.lib; { 152 homepage = http://www.rust-lang.org/; 153 description = "A safe, concurrent, practical language"; 154 maintainers = with maintainers; [ madjar cstrahan wizeman globin havvy wkennington ]; 155 license = [ licenses.mit licenses.asl20 ]; 156 platforms = platforms.linux ++ platforms.darwin; 157 }; 158}