at 18.03-beta 172 lines 5.9 kB view raw
1{ stdenv, targetPackages 2, fetchurl, fetchgit, fetchzip, file, python2, tzdata, procps 3, llvm, jemalloc, ncurses, darwin, rustPlatform, git, cmake, curl 4, which, libffi, gdb 5, version 6, forceBundledLLVM ? false 7, src 8, configureFlags ? [] 9, patches 10, targets 11, targetPatches 12, targetToolchains 13, doCheck ? true 14, broken ? false 15, buildPlatform, hostPlatform 16} @ args: 17 18let 19 inherit (stdenv.lib) optional optionalString; 20 inherit (darwin.apple_sdk.frameworks) Security; 21 22 procps = if stdenv.isDarwin then darwin.ps else args.procps; 23 24 llvmShared = llvm.override { enableSharedLibraries = true; }; 25 26 target = builtins.replaceStrings [" "] [","] (builtins.toString targets); 27in 28 29stdenv.mkDerivation { 30 name = "rustc-${version}"; 31 inherit version; 32 33 inherit src; 34 35 __darwinAllowLocalNetworking = true; 36 37 # The build will fail at the very end on AArch64 without this. 38 dontUpdateAutotoolsGnuConfigScripts = if stdenv.isAarch64 then true else null; 39 40 # Running the default `strip -S` command on Darwin corrupts the 41 # .rlib files in "lib/". 42 # 43 # See https://github.com/NixOS/nixpkgs/pull/34227 44 stripDebugList = if stdenv.isDarwin then [ "bin" ] else null; 45 46 NIX_LDFLAGS = optionalString stdenv.isDarwin "-rpath ${llvmShared}/lib"; 47 48 # Enable nightly features in stable compiles (used for 49 # bootstrapping, see https://github.com/rust-lang/rust/pull/37265). 50 # This loosens the hard restrictions on bootstrapping-compiler 51 # versions. 52 RUSTC_BOOTSTRAP = "1"; 53 54 # Increase codegen units to introduce parallelism within the compiler. 55 RUSTFLAGS = "-Ccodegen-units=10"; 56 57 # We need rust to build rust. If we don't provide it, configure will try to download it. 58 configureFlags = configureFlags 59 ++ [ "--enable-local-rust" "--local-rust-root=${rustPlatform.rust.rustc}" "--enable-rpath" ] 60 ++ [ "--enable-vendor" ] 61 # ++ [ "--jemalloc-root=${jemalloc}/lib" 62 ++ [ "--default-linker=${targetPackages.stdenv.cc}/bin/cc" ] 63 ++ optional (!forceBundledLLVM) [ "--enable-llvm-link-shared" ] 64 ++ optional (targets != []) "--target=${target}" 65 ++ optional (!forceBundledLLVM) "--llvm-root=${llvmShared}"; 66 67 patches = patches ++ targetPatches; 68 69 # the rust build system complains that nix alters the checksums 70 dontFixLibtool = true; 71 72 passthru.target = target; 73 74 postPatch = '' 75 patchShebangs src/etc 76 77 # Fix dynamic linking against llvm 78 #${optionalString (!forceBundledLLVM) ''sed -i 's/, kind = \\"static\\"//g' src/etc/mklldeps.py''} 79 80 # Fix the configure script to not require curl as we won't use it 81 sed -i configure \ 82 -e '/probe_need CFG_CURL curl/d' 83 84 # Fix the use of jemalloc prefixes which our jemalloc doesn't have 85 # TODO: reenable if we can figure out how to get our jemalloc to work 86 #[ -f src/liballoc_jemalloc/lib.rs ] && sed -i 's,je_,,g' src/liballoc_jemalloc/lib.rs 87 #[ -f src/liballoc/heap.rs ] && sed -i 's,je_,,g' src/liballoc/heap.rs # Remove for 1.4.0+ 88 89 # Disable fragile tests. 90 rm -vr src/test/run-make/linker-output-non-utf8 || true 91 rm -vr src/test/run-make/issue-26092 || true 92 93 # Remove test targeted at LLVM 3.9 - https://github.com/rust-lang/rust/issues/36835 94 rm -vr src/test/run-pass/issue-36023.rs || true 95 96 # Disable test getting stuck on hydra - possible fix: 97 # https://reviews.llvm.org/rL281650 98 rm -vr src/test/run-pass/issue-36474.rs || true 99 100 # On Hydra: `TcpListener::bind(&addr)`: Address already in use (os error 98)' 101 sed '/^ *fn fast_rebind()/i#[ignore]' -i src/libstd/net/tcp.rs 102 103 # Useful debugging parameter 104 # export VERBOSE=1 105 '' 106 + optionalString stdenv.isDarwin '' 107 # Disable all lldb tests. 108 # error: Can't run LLDB test because LLDB's python path is not set 109 rm -vr src/test/debuginfo/* 110 rm -v src/test/run-pass/backtrace-debuginfo.rs 111 112 # error: No such file or directory 113 rm -v src/test/run-pass/issue-45731.rs 114 115 # Disable tests that fail when sandboxing is enabled. 116 substituteInPlace src/libstd/sys/unix/ext/net.rs \ 117 --replace '#[test]' '#[test] #[ignore]' 118 substituteInPlace src/test/run-pass/env-home-dir.rs \ 119 --replace 'home_dir().is_some()' true 120 rm -v src/test/run-pass/fds-are-cloexec.rs # FIXME: pipes? 121 rm -v src/test/run-pass/sync-send-in-std.rs # FIXME: ??? 122 ''; 123 124 # rustc unfortunately need cmake for compiling llvm-rt but doesn't 125 # use it for the normal build. This disables cmake in Nix. 126 dontUseCmakeConfigure = true; 127 128 # ps is needed for one of the test cases 129 nativeBuildInputs = 130 [ file python2 procps rustPlatform.rust.rustc git cmake 131 which libffi 132 ] 133 # Only needed for the debuginfo tests 134 ++ optional (!stdenv.isDarwin) gdb; 135 136 buildInputs = [ ncurses ] ++ targetToolchains 137 ++ optional stdenv.isDarwin Security 138 ++ optional (!forceBundledLLVM) llvmShared; 139 140 outputs = [ "out" "man" "doc" ]; 141 setOutputFlags = false; 142 143 # Disable codegen units for the tests. 144 preCheck = '' 145 export RUSTFLAGS= 146 export TZDIR=${tzdata}/share/zoneinfo 147 '' + 148 # Ensure TMPDIR is set, and disable a test that removing the HOME 149 # variable from the environment falls back to another home 150 # directory. 151 optionalString stdenv.isDarwin '' 152 export TMPDIR=/tmp 153 sed -i '28s/home_dir().is_some()/true/' ./src/test/run-pass/env-home-dir.rs 154 ''; 155 156 inherit doCheck; 157 158 configurePlatforms = []; 159 160 # https://github.com/NixOS/nixpkgs/pull/21742#issuecomment-272305764 161 # https://github.com/rust-lang/rust/issues/30181 162 # enableParallelBuilding = false; 163 164 meta = with stdenv.lib; { 165 homepage = https://www.rust-lang.org/; 166 description = "A safe, concurrent, practical language"; 167 maintainers = with maintainers; [ madjar cstrahan wizeman globin havvy wkennington ]; 168 license = [ licenses.mit licenses.asl20 ]; 169 platforms = platforms.linux ++ platforms.darwin; 170 broken = broken; 171 }; 172}