Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ 2 lib, 3 stdenv, 4 release_version, 5 src ? null, 6 llvm_meta, 7 version, 8 monorepoSrc ? null, 9 runCommand, 10 cmake, 11 ninja, 12 python3, 13 libcxx, 14 enableShared ? !stdenv.hostPlatform.isStatic, 15 doFakeLibgcc ? stdenv.hostPlatform.useLLVM, 16 devExtraCmakeFlags ? [ ], 17 getVersionFile, 18}: 19stdenv.mkDerivation ( 20 finalAttrs: 21 let 22 hasPatches = builtins.length finalAttrs.patches > 0; 23 in 24 { 25 pname = "libunwind"; 26 27 inherit version; 28 29 patches = lib.optional (lib.versionOlder release_version "17") ( 30 getVersionFile "libunwind/gnu-install-dirs.patch" 31 ); 32 33 src = 34 if monorepoSrc != null then 35 runCommand "libunwind-src-${version}" { inherit (monorepoSrc) passthru; } ( 36 '' 37 mkdir -p "$out" 38 '' 39 + lib.optionalString (lib.versionAtLeast release_version "14") '' 40 cp -r ${monorepoSrc}/cmake "$out" 41 '' 42 + '' 43 cp -r ${monorepoSrc}/libunwind "$out" 44 mkdir -p "$out/libcxx" 45 cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx" 46 cp -r ${monorepoSrc}/libcxx/utils "$out/libcxx" 47 mkdir -p "$out/llvm" 48 cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" 49 '' 50 + lib.optionalString (lib.versionAtLeast release_version "15") '' 51 cp -r ${monorepoSrc}/llvm/utils "$out/llvm" 52 cp -r ${monorepoSrc}/runtimes "$out" 53 '' 54 ) 55 else 56 src; 57 58 sourceRoot = 59 if lib.versionAtLeast release_version "15" then 60 "${finalAttrs.src.name}/runtimes" 61 else 62 "${finalAttrs.src.name}/libunwind"; 63 64 outputs = [ 65 "out" 66 "dev" 67 ]; 68 69 nativeBuildInputs = [ 70 cmake 71 ] 72 ++ lib.optionals (lib.versionAtLeast release_version "15") [ 73 ninja 74 python3 75 ]; 76 77 cmakeFlags = [ 78 (lib.cmakeBool "LIBUNWIND_ENABLE_SHARED" enableShared) 79 ] 80 ++ lib.optional (lib.versionAtLeast release_version "15") ( 81 lib.cmakeFeature "LLVM_ENABLE_RUNTIMES" "libunwind" 82 ) 83 ++ lib.optionals (lib.versions.major release_version == "12" && stdenv.hostPlatform.isDarwin) [ 84 (lib.cmakeBool "CMAKE_CXX_COMPILER_WORKS" true) 85 ] 86 ++ devExtraCmakeFlags; 87 88 prePatch = 89 lib.optionalString 90 (lib.versionAtLeast release_version "15" && (hasPatches || lib.versionOlder release_version "18")) 91 '' 92 cd ../libunwind 93 chmod -R u+w . 94 ''; 95 96 postPatch = 97 lib.optionalString 98 (lib.versionAtLeast release_version "15" && (hasPatches || lib.versionOlder release_version "18")) 99 '' 100 cd ../runtimes 101 ''; 102 103 postInstall = 104 lib.optionalString (enableShared && !stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isWindows) 105 '' 106 # libcxxabi wants to link to libunwind_shared.so (?). 107 ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so 108 '' 109 + lib.optionalString (enableShared && stdenv.hostPlatform.isWindows) '' 110 ln -s $out/lib/libunwind.dll.a $out/lib/libunwind_shared.dll.a 111 '' 112 + lib.optionalString (doFakeLibgcc && !stdenv.hostPlatform.isWindows) '' 113 ln -s $out/lib/libunwind.so $out/lib/libgcc_s.so 114 ln -s $out/lib/libunwind.so $out/lib/libgcc_s.so.1 115 '' 116 + lib.optionalString (doFakeLibgcc && stdenv.hostPlatform.isWindows) '' 117 ln -s $out/lib/libunwind.dll.a $out/lib/libgcc_s.dll.a 118 ''; 119 120 meta = llvm_meta // { 121 # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst 122 homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library"; 123 description = "LLVM's unwinder library"; 124 longDescription = '' 125 The unwind library provides a family of _Unwind_* functions implementing 126 the language-neutral stack unwinding portion of the Itanium C++ ABI (Level 127 I). It is a dependency of the C++ ABI library, and sometimes is a 128 dependency of other runtimes. 129 ''; 130 }; 131 } 132)