at 25.11-pre 4.7 kB view raw
1{ 2 lib, 3 stdenv, 4 makeWrapper, 5 wrapRustc, 6 bash, 7 curl, 8 zlib, 9 autoPatchelfHook, 10 gcc, 11 version, 12 src, 13 platform, 14 versionType, 15}: 16 17let 18 inherit (lib) optionalString; 19 20 bootstrapping = versionType == "bootstrap"; 21 22 installComponents = "rustc,rust-std-${platform}" + (optionalString bootstrapping ",cargo"); 23in 24 25rec { 26 rustc-unwrapped = stdenv.mkDerivation { 27 pname = "rustc-${versionType}"; 28 29 inherit version; 30 inherit src; 31 32 meta = with lib; { 33 homepage = "https://www.rust-lang.org/"; 34 sourceProvenance = with sourceTypes; [ binaryNativeCode ]; 35 description = "Safe, concurrent, practical language"; 36 maintainers = with maintainers; [ qknight ]; 37 license = [ 38 licenses.mit 39 licenses.asl20 40 ]; 41 }; 42 43 nativeBuildInputs = lib.optional (!stdenv.hostPlatform.isDarwin) autoPatchelfHook; 44 buildInputs = 45 [ bash ] 46 ++ lib.optional (!stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isFreeBSD) gcc.cc.lib 47 ++ lib.optional (!stdenv.hostPlatform.isDarwin) zlib; 48 49 postPatch = '' 50 patchShebangs . 51 ''; 52 53 installPhase = 54 '' 55 ./install.sh --prefix=$out \ 56 --components=${installComponents} 57 58 # Do NOT, I repeat, DO NOT use `wrapProgram` on $out/bin/rustc 59 # (or similar) here. It causes strange effects where rustc loads 60 # the wrong libraries in a bootstrap-build causing failures that 61 # are very hard to track down. For details, see 62 # https://github.com/rust-lang/rust/issues/34722#issuecomment-232164943 63 '' 64 + lib.optionalString stdenv.hostPlatform.isDarwin '' 65 install_name_tool -change "/usr/lib/libcurl.4.dylib" \ 66 "${lib.getLib curl}/lib/libcurl.4.dylib" "$out/bin/cargo" 67 ''; 68 69 # The strip tool in cctools 973.0.1 and up appears to break rlibs in the 70 # binaries. The lib.rmeta object inside the ar archive should contain an 71 # .rmeta section, but it is removed. Luckily, this doesn't appear to be an 72 # issue for Rust builds produced by Nix. 73 dontStrip = true; 74 75 setupHooks = ./setup-hook.sh; 76 77 passthru = rec { 78 tier1TargetPlatforms = [ 79 # Platforms with host tools from 80 # https://doc.rust-lang.org/nightly/rustc/platform-support.html 81 "x86_64-darwin" 82 "aarch64-darwin" 83 "i686-freebsd" 84 "x86_64-freebsd" 85 "x86_64-solaris" 86 "aarch64-linux" 87 "armv6l-linux" 88 "armv7l-linux" 89 "i686-linux" 90 "loongarch64-linux" 91 "powerpc64-linux" 92 "powerpc64le-linux" 93 "riscv64-linux" 94 "s390x-linux" 95 "x86_64-linux" 96 "aarch64-netbsd" 97 "armv7l-netbsd" 98 "i686-netbsd" 99 "powerpc-netbsd" 100 "x86_64-netbsd" 101 "i686-openbsd" 102 "x86_64-openbsd" 103 "i686-windows" 104 "x86_64-windows" 105 ]; 106 targetPlatforms = tier1TargetPlatforms ++ [ 107 # Platforms without host tools from 108 # https://doc.rust-lang.org/nightly/rustc/platform-support.html 109 "armv5tel-linux" 110 "armv7a-linux" 111 "m68k-linux" 112 "mips-linux" 113 "mips64-linux" 114 "mipsel-linux" 115 "mips64el-linux" 116 "riscv32-linux" 117 "armv6l-netbsd" 118 "mipsel-netbsd" 119 "riscv64-netbsd" 120 "x86_64-redox" 121 "wasm32-wasi" 122 ]; 123 badTargetPlatforms = [ 124 # Rust is currently unable to target the n32 ABI 125 lib.systems.inspect.patterns.isMips64n32 126 ]; 127 }; 128 }; 129 130 rustc = wrapRustc rustc-unwrapped; 131 132 cargo = stdenv.mkDerivation { 133 pname = "cargo-${versionType}"; 134 135 inherit version; 136 inherit src; 137 138 meta = with lib; { 139 homepage = "https://doc.rust-lang.org/cargo/"; 140 sourceProvenance = with sourceTypes; [ binaryNativeCode ]; 141 description = "Rust package manager"; 142 maintainers = with maintainers; [ qknight ]; 143 license = [ 144 licenses.mit 145 licenses.asl20 146 ]; 147 }; 148 149 nativeBuildInputs = [ 150 makeWrapper 151 ] ++ lib.optional (!stdenv.hostPlatform.isDarwin) autoPatchelfHook; 152 buildInputs = [ 153 bash 154 ] ++ lib.optional (!stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isFreeBSD) gcc.cc.lib; 155 156 postPatch = '' 157 patchShebangs . 158 ''; 159 160 installPhase = 161 '' 162 patchShebangs ./install.sh 163 ./install.sh --prefix=$out \ 164 --components=cargo 165 '' 166 + lib.optionalString stdenv.hostPlatform.isDarwin '' 167 install_name_tool -change "/usr/lib/libcurl.4.dylib" \ 168 "${lib.getLib curl}/lib/libcurl.4.dylib" "$out/bin/cargo" 169 '' 170 + '' 171 wrapProgram "$out/bin/cargo" \ 172 --suffix PATH : "${rustc}/bin" 173 ''; 174 }; 175}