lol
1{ lib
2, stdenv
3, release_version
4, patches ? []
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}:
16let
17 pname = "libunwind";
18 src' = if monorepoSrc != null then
19 runCommand "${pname}-src-${version}" {} (''
20 mkdir -p "$out"
21 cp -r ${monorepoSrc}/cmake "$out"
22 cp -r ${monorepoSrc}/${pname} "$out"
23 mkdir -p "$out/libcxx"
24 cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx"
25 cp -r ${monorepoSrc}/libcxx/utils "$out/libcxx"
26 mkdir -p "$out/llvm"
27 cp -r ${monorepoSrc}/llvm/cmake "$out/llvm"
28 '' + lib.optionalString (lib.versionAtLeast release_version "15") ''
29 cp -r ${monorepoSrc}/llvm/utils "$out/llvm"
30 cp -r ${monorepoSrc}/runtimes "$out"
31 '') else src;
32
33 hasPatches = builtins.length patches > 0;
34
35 postUnpack = lib.optionalString (lib.versions.major release_version == "12") ''
36 ln -s ${libcxx.src}/libcxx .
37 ln -s ${libcxx.src}/llvm .
38 '';
39
40 prePatch = lib.optionalString (lib.versionAtLeast release_version "15" && (hasPatches || lib.versionOlder release_version "18")) ''
41 cd ../${pname}
42 chmod -R u+w .
43 '';
44
45 postPatch = lib.optionalString (lib.versionAtLeast release_version "15" && (hasPatches || lib.versionOlder release_version "18")) ''
46 cd ../runtimes
47 '';
48
49 postInstall = lib.optionalString (enableShared && !stdenv.hostPlatform.isDarwin) ''
50 # libcxxabi wants to link to libunwind_shared.so (?).
51 ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so
52 '';
53in
54stdenv.mkDerivation (rec {
55 inherit pname version patches;
56
57 src = src';
58
59 sourceRoot =
60 if lib.versionOlder release_version "13" then null
61 else if lib.versionAtLeast release_version "15" then "${src.name}/runtimes"
62 else "${src.name}/${pname}";
63
64 outputs = [ "out" "dev" ];
65
66 nativeBuildInputs = [ cmake ] ++ lib.optionals (lib.versionAtLeast release_version "15") [
67 ninja python3
68 ];
69
70 cmakeFlags = lib.optional (lib.versionAtLeast release_version "15") "-DLLVM_ENABLE_RUNTIMES=libunwind"
71 ++ lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF";
72
73 meta = llvm_meta // {
74 # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst
75 homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library";
76 description = "LLVM's unwinder library";
77 longDescription = ''
78 The unwind library provides a family of _Unwind_* functions implementing
79 the language-neutral stack unwinding portion of the Itanium C++ ABI (Level
80 I). It is a dependency of the C++ ABI library, and sometimes is a
81 dependency of other runtimes.
82 '';
83 };
84} // (if postUnpack != "" then { inherit postUnpack; } else {})
85 // (if (lib.versionAtLeast release_version "15") then { inherit postInstall; } else {})
86 // (if prePatch != "" then { inherit prePatch; } else {})
87 // (if postPatch != "" then { inherit postPatch; } else {}))