Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at flake-libs 127 lines 3.8 kB view raw
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 ++ lib.optionals (lib.versionAtLeast release_version "15") [ 72 ninja 73 python3 74 ]; 75 76 cmakeFlags = 77 [ (lib.cmakeBool "LIBUNWIND_ENABLE_SHARED" enableShared) ] 78 ++ lib.optional (lib.versionAtLeast release_version "15") ( 79 lib.cmakeFeature "LLVM_ENABLE_RUNTIMES" "libunwind" 80 ) 81 ++ lib.optionals (lib.versions.major release_version == "12" && stdenv.hostPlatform.isDarwin) [ 82 (lib.cmakeBool "CMAKE_CXX_COMPILER_WORKS" true) 83 ] 84 ++ devExtraCmakeFlags; 85 86 prePatch = 87 lib.optionalString 88 (lib.versionAtLeast release_version "15" && (hasPatches || lib.versionOlder release_version "18")) 89 '' 90 cd ../libunwind 91 chmod -R u+w . 92 ''; 93 94 postPatch = 95 lib.optionalString 96 (lib.versionAtLeast release_version "15" && (hasPatches || lib.versionOlder release_version "18")) 97 '' 98 cd ../runtimes 99 ''; 100 101 postInstall = 102 lib.optionalString (enableShared && !stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isWindows) 103 '' 104 # libcxxabi wants to link to libunwind_shared.so (?). 105 ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so 106 '' 107 + lib.optionalString (enableShared && stdenv.hostPlatform.isWindows) '' 108 ln -s $out/lib/libunwind.dll.a $out/lib/libunwind_shared.dll.a 109 '' 110 + lib.optionalString (doFakeLibgcc) '' 111 ln -s $out/lib/libunwind.so $out/lib/libgcc_s.so 112 ln -s $out/lib/libunwind.so $out/lib/libgcc_s.so.1 113 ''; 114 115 meta = llvm_meta // { 116 # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst 117 homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library"; 118 description = "LLVM's unwinder library"; 119 longDescription = '' 120 The unwind library provides a family of _Unwind_* functions implementing 121 the language-neutral stack unwinding portion of the Itanium C++ ABI (Level 122 I). It is a dependency of the C++ ABI library, and sometimes is a 123 dependency of other runtimes. 124 ''; 125 }; 126 } 127)