Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ 2 lib, 3 stdenv, 4 fetchurl, 5 mrustc, 6 mrustc-minicargo, 7 llvm_12, 8 libffi, 9 cmake, 10 python3, 11 zlib, 12 libxml2, 13 openssl, 14 pkg-config, 15 curl, 16 which, 17 time, 18}: 19 20let 21 mrustcTargetVersion = "1.54"; 22 rustcVersion = "1.54.0"; 23 rustcSrc = fetchurl { 24 url = "https://static.rust-lang.org/dist/rustc-${rustcVersion}-src.tar.gz"; 25 sha256 = "0xk9dhfff16caambmwij67zgshd8v9djw6ha0fnnanlv7rii31dc"; 26 }; 27 rustcDir = "rustc-${rustcVersion}-src"; 28 outputDir = "output-${rustcVersion}"; 29in 30 31stdenv.mkDerivation rec { 32 pname = "mrustc-bootstrap"; 33 version = "${mrustc.version}_${rustcVersion}"; 34 35 inherit (mrustc) src; 36 postUnpack = "tar -xf ${rustcSrc} -C source/"; 37 38 # the rust build system complains that nix alters the checksums 39 dontFixLibtool = true; 40 41 patches = [ 42 ./patches/0001-dont-download-rustc.patch 43 ]; 44 45 postPatch = '' 46 echo "applying patch ./rustc-${rustcVersion}-src.patch" 47 patch -p0 -d ${rustcDir}/ < rustc-${rustcVersion}-src.patch 48 ''; 49 50 # rustc unfortunately needs cmake to compile llvm-rt but doesn't 51 # use it for the normal build. This disables cmake in Nix. 52 dontUseCmakeConfigure = true; 53 54 strictDeps = true; 55 nativeBuildInputs = [ 56 cmake 57 mrustc 58 mrustc-minicargo 59 pkg-config 60 python3 61 time 62 which 63 ]; 64 buildInputs = [ 65 # for rustc 66 llvm_12 67 libffi 68 zlib 69 libxml2 70 # for cargo 71 openssl 72 (curl.override { inherit openssl; }) 73 ]; 74 75 makeFlags = [ 76 # Use shared mrustc/minicargo/llvm instead of rebuilding them 77 "MRUSTC=${mrustc}/bin/mrustc" 78 #"MINICARGO=${mrustc-minicargo}/bin/minicargo" # FIXME: we need to rebuild minicargo locally so --manifest-overrides is applied 79 "LLVM_CONFIG=${llvm_12.dev}/bin/llvm-config" 80 "RUSTC_TARGET=${stdenv.targetPlatform.rust.rustcTarget}" 81 ]; 82 83 buildPhase = '' 84 runHook preBuild 85 86 local flagsArray=( 87 PARLEVEL=$NIX_BUILD_CORES 88 ${toString makeFlags} 89 ) 90 91 touch ${rustcDir}/dl-version 92 export OUTDIR_SUF=-${rustcVersion} 93 export RUSTC_VERSION=${rustcVersion} 94 export MRUSTC_TARGET_VER=${mrustcTargetVersion} 95 export MRUSTC_PATH=${mrustc}/bin/mrustc 96 97 echo minicargo.mk: libs 98 make -f minicargo.mk "''${flagsArray[@]}" LIBS 99 100 echo test 101 make "''${flagsArray[@]}" test 102 103 # disabled because it expects ./bin/mrustc 104 #echo local_tests 105 #make "''${flagsArray[@]}" local_tests 106 107 echo minicargo.mk: rustc 108 make -f minicargo.mk "''${flagsArray[@]}" ${outputDir}/rustc 109 110 echo minicargo.mk: cargo 111 make -f minicargo.mk "''${flagsArray[@]}" ${outputDir}/cargo 112 113 echo run_rustc 114 make -C run_rustc "''${flagsArray[@]}" 115 116 unset flagsArray 117 118 runHook postBuild 119 ''; 120 121 doCheck = true; 122 checkPhase = '' 123 runHook preCheck 124 run_rustc/${outputDir}/prefix/bin/hello_world | grep "hello, world" 125 runHook postCheck 126 ''; 127 128 installPhase = '' 129 runHook preInstall 130 mkdir -p $out/bin/ $out/lib/ 131 cp run_rustc/${outputDir}/prefix/bin/cargo $out/bin/cargo 132 cp run_rustc/${outputDir}/prefix/bin/rustc_binary $out/bin/rustc 133 134 cp -r run_rustc/${outputDir}/prefix/lib/* $out/lib/ 135 cp $out/lib/rustlib/${stdenv.targetPlatform.rust.rustcTarget}/lib/*.so $out/lib/ 136 runHook postInstall 137 ''; 138 139 meta = with lib; { 140 inherit (src.meta) homepage; 141 description = "Minimal build of Rust"; 142 longDescription = '' 143 A minimal build of Rust, built from source using mrustc. 144 This is useful for bootstrapping the main Rust compiler without 145 an initial binary toolchain download. 146 ''; 147 maintainers = with maintainers; [ 148 progval 149 r-burns 150 ]; 151 license = with licenses; [ 152 mit 153 asl20 154 ]; 155 platforms = [ "x86_64-linux" ]; 156 }; 157}