Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ 2 lib, 3 stdenv, 4 llvm_meta, 5 monorepoSrc, 6 release_version, 7 runCommand, 8 cmake, 9 libxml2, 10 libllvm, 11 ninja, 12 libclang, 13 version, 14 python3, 15 buildLlvmTools, 16 patches ? [ ], 17 devExtraCmakeFlags ? [ ], 18 fetchpatch, 19}: 20 21stdenv.mkDerivation (finalAttrs: { 22 pname = "bolt"; 23 inherit version; 24 25 # Blank llvm dir just so relative path works 26 src = runCommand "bolt-src-${finalAttrs.version}" { inherit (monorepoSrc) passthru; } ( 27 '' 28 mkdir $out 29 '' 30 + lib.optionalString (lib.versionAtLeast release_version "14") '' 31 cp -r ${monorepoSrc}/cmake "$out" 32 '' 33 + '' 34 cp -r ${monorepoSrc}/${finalAttrs.pname} "$out" 35 cp -r ${monorepoSrc}/third-party "$out" 36 37 # BOLT re-runs tablegen against LLVM sources, so needs them available. 38 cp -r ${monorepoSrc}/llvm/ "$out" 39 chmod -R +w $out/llvm 40 '' 41 ); 42 43 sourceRoot = "${finalAttrs.src.name}/bolt"; 44 45 patches = lib.optionals (lib.versions.major release_version == "19") [ 46 (fetchpatch { 47 url = "https://github.com/llvm/llvm-project/commit/abc2eae68290c453e1899a94eccc4ed5ea3b69c1.patch"; 48 hash = "sha256-oxCxOjhi5BhNBEraWalEwa1rS3Mx9CuQgRVZ2hrbd7M="; 49 }) 50 (fetchpatch { 51 url = "https://github.com/llvm/llvm-project/commit/5909979869edca359bcbca74042c2939d900680e.patch"; 52 hash = "sha256-l4rQHYbblEADBXaZIdqTG0sZzH4fEQvYiqhLYNZDMa8="; 53 }) 54 ]; 55 56 nativeBuildInputs = [ 57 cmake 58 ninja 59 python3 60 ]; 61 62 buildInputs = [ 63 libllvm 64 libxml2 65 ]; 66 67 cmakeFlags = [ 68 (lib.cmakeFeature "LLVM_TABLEGEN_EXE" "${buildLlvmTools.tblgen}/bin/llvm-tblgen") 69 ] 70 ++ devExtraCmakeFlags; 71 72 postUnpack = '' 73 chmod -R u+w -- $sourceRoot/.. 74 ''; 75 76 prePatch = '' 77 cd .. 78 ''; 79 80 postPatch = '' 81 cd bolt 82 ''; 83 84 postInstall = '' 85 mkdir -p $dev/lib 86 mv $out/lib/libLLVMBOLT*.a $dev/lib 87 ''; 88 89 outputs = [ 90 "out" 91 "dev" 92 ]; 93 94 meta = llvm_meta // { 95 homepage = "https://github.com/llvm/llvm-project/tree/main/bolt"; 96 description = "LLVM post-link optimizer"; 97 }; 98})