Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at flake-libs 108 lines 3.3 kB view raw
1{ 2 lib, 3 stdenv, 4 llvm_meta, 5 release_version, 6 buildLlvmTools, 7 monorepoSrc ? null, 8 src ? null, 9 runCommand, 10 cmake, 11 ninja, 12 libxml2, 13 libllvm, 14 version, 15 devExtraCmakeFlags ? [ ], 16 getVersionFile, 17 fetchpatch, 18}: 19stdenv.mkDerivation (finalAttrs: { 20 pname = "lld"; 21 inherit version; 22 23 src = 24 if monorepoSrc != null then 25 runCommand "lld-src-${version}" { inherit (monorepoSrc) passthru; } ( 26 '' 27 mkdir -p "$out" 28 '' 29 + lib.optionalString (lib.versionAtLeast release_version "14") '' 30 cp -r ${monorepoSrc}/cmake "$out" 31 '' 32 + '' 33 cp -r ${monorepoSrc}/lld "$out" 34 mkdir -p "$out/libunwind" 35 cp -r ${monorepoSrc}/libunwind/include "$out/libunwind" 36 mkdir -p "$out/llvm" 37 '' 38 ) 39 else 40 src; 41 42 sourceRoot = "${finalAttrs.src.name}/lld"; 43 44 patches = 45 [ (getVersionFile "lld/gnu-install-dirs.patch") ] 46 ++ lib.optional (lib.versions.major release_version == "14") ( 47 getVersionFile "lld/fix-root-src-dir.patch" 48 ) 49 ++ lib.optional (lib.versionAtLeast release_version "16" && lib.versionOlder release_version "18") ( 50 getVersionFile "lld/add-table-base.patch" 51 ) 52 ++ lib.optional (lib.versions.major release_version == "18") ( 53 # https://github.com/llvm/llvm-project/pull/97122 54 fetchpatch { 55 name = "more-openbsd-program-headers.patch"; 56 url = "https://github.com/llvm/llvm-project/commit/d7fd8b19e560fbb613159625acd8046d0df75115.patch"; 57 stripLen = 1; 58 hash = "sha256-7wTy7XDTx0+fhWQpW1KEuz7xJvpl42qMTUfd20KGOfA="; 59 } 60 ); 61 62 nativeBuildInputs = [ cmake ] ++ lib.optional (lib.versionAtLeast release_version "15") ninja; 63 buildInputs = [ 64 libllvm 65 libxml2 66 ]; 67 68 cmakeFlags = 69 lib.optionals (lib.versionOlder release_version "14") [ 70 (lib.cmakeFeature "LLVM_CONFIG_PATH" "${libllvm.dev}/bin/llvm-config${ 71 lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-native" 72 }") 73 ] 74 ++ lib.optionals (lib.versionAtLeast release_version "15") [ 75 (lib.cmakeFeature "LLD_INSTALL_PACKAGE_DIR" "${placeholder "dev"}/lib/cmake/lld") 76 ] 77 ++ [ 78 (lib.cmakeFeature "LLVM_TABLEGEN_EXE" "${buildLlvmTools.tblgen}/bin/llvm-tblgen") 79 ] 80 ++ devExtraCmakeFlags; 81 82 postPatch = lib.optionalString (lib.versionOlder release_version "14") '' 83 substituteInPlace MachO/CMakeLists.txt --replace-fail \ 84 '(''${LLVM_MAIN_SRC_DIR}/' '(../' 85 ''; 86 87 # Musl's default stack size is too small for lld to be able to link Firefox. 88 LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152"; 89 90 outputs = [ 91 "out" 92 "lib" 93 "dev" 94 ]; 95 96 meta = llvm_meta // { 97 homepage = "https://lld.llvm.org/"; 98 description = "LLVM linker (unwrapped)"; 99 longDescription = '' 100 LLD is a linker from the LLVM project that is a drop-in replacement for 101 system linkers and runs much faster than them. It also provides features 102 that are useful for toolchain developers. 103 The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and 104 WebAssembly in descending order of completeness. Internally, LLD consists 105 of several different linkers. 106 ''; 107 }; 108})