Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at netboot-syslinux-multiplatform 149 lines 3.7 kB view raw
1{ lib, stdenv 2, fetchurl 3, mrustc 4, mrustc-minicargo 5, rust 6, llvm_12 7, llvmPackages_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 libffi zlib libxml2 67 # for cargo 68 openssl 69 (curl.override { inherit openssl; }) 70 ]; 71 72 makeFlags = [ 73 # Use shared mrustc/minicargo/llvm instead of rebuilding them 74 "MRUSTC=${mrustc}/bin/mrustc" 75 #"MINICARGO=${mrustc-minicargo}/bin/minicargo" # FIXME: we need to rebuild minicargo locally so --manifest-overrides is applied 76 "LLVM_CONFIG=${llvm_12.dev}/bin/llvm-config" 77 "RUSTC_TARGET=${rust.toRustTarget stdenv.targetPlatform}" 78 ]; 79 80 buildPhase = '' 81 runHook preBuild 82 83 local flagsArray=( 84 PARLEVEL=$NIX_BUILD_CORES 85 ${toString makeFlags} 86 ) 87 88 touch ${rustcDir}/dl-version 89 export OUTDIR_SUF=-${rustcVersion} 90 export RUSTC_VERSION=${rustcVersion} 91 export MRUSTC_TARGET_VER=${mrustcTargetVersion} 92 export MRUSTC_PATH=${mrustc}/bin/mrustc 93 94 echo minicargo.mk: libs 95 make -f minicargo.mk "''${flagsArray[@]}" LIBS 96 97 echo test 98 make "''${flagsArray[@]}" test 99 100 # disabled because it expects ./bin/mrustc 101 #echo local_tests 102 #make "''${flagsArray[@]}" local_tests 103 104 echo minicargo.mk: rustc 105 make -f minicargo.mk "''${flagsArray[@]}" ${outputDir}/rustc 106 107 echo minicargo.mk: cargo 108 make -f minicargo.mk "''${flagsArray[@]}" ${outputDir}/cargo 109 110 echo run_rustc 111 make -C run_rustc "''${flagsArray[@]}" 112 113 unset flagsArray 114 115 runHook postBuild 116 ''; 117 118 doCheck = true; 119 checkPhase = '' 120 runHook preCheck 121 run_rustc/${outputDir}/prefix/bin/hello_world | grep "hello, world" 122 runHook postCheck 123 ''; 124 125 installPhase = '' 126 runHook preInstall 127 mkdir -p $out/bin/ $out/lib/ 128 cp run_rustc/${outputDir}/prefix/bin/cargo $out/bin/cargo 129 cp run_rustc/${outputDir}/prefix/bin/rustc_binary $out/bin/rustc 130 131 cp -r run_rustc/${outputDir}/prefix/lib/* $out/lib/ 132 cp $out/lib/rustlib/${rust.toRustTarget stdenv.targetPlatform}/lib/*.so $out/lib/ 133 runHook postInstall 134 ''; 135 136 meta = with lib; { 137 inherit (src.meta) homepage; 138 description = "A minimal build of Rust"; 139 longDescription = '' 140 A minimal build of Rust, built from source using mrustc. 141 This is useful for bootstrapping the main Rust compiler without 142 an initial binary toolchain download. 143 ''; 144 maintainers = with maintainers; [ progval r-burns ]; 145 license = with licenses; [ mit asl20 ]; 146 platforms = [ "x86_64-linux" ]; 147 }; 148} 149