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 && !stdenv.hostPlatform.isStatic,
16 devExtraCmakeFlags ? [ ],
17 getVersionFile,
18}:
19stdenv.mkDerivation (finalAttrs: {
20 pname = "libunwind";
21
22 inherit version;
23
24 # TODO: Remove on `staging`.
25 patches = [ ];
26
27 src =
28 if monorepoSrc != null then
29 runCommand "libunwind-src-${version}" { inherit (monorepoSrc) passthru; } ''
30 mkdir -p "$out"
31 cp -r ${monorepoSrc}/cmake "$out"
32 cp -r ${monorepoSrc}/libunwind "$out"
33 mkdir -p "$out/libcxx"
34 cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx"
35 cp -r ${monorepoSrc}/libcxx/utils "$out/libcxx"
36 mkdir -p "$out/llvm"
37 cp -r ${monorepoSrc}/llvm/cmake "$out/llvm"
38 cp -r ${monorepoSrc}/llvm/utils "$out/llvm"
39 cp -r ${monorepoSrc}/runtimes "$out"
40 ''
41 else
42 src;
43
44 sourceRoot = "${finalAttrs.src.name}/runtimes";
45
46 outputs = [
47 "out"
48 "dev"
49 ];
50
51 nativeBuildInputs = [
52 cmake
53 ninja
54 python3
55 ];
56
57 cmakeFlags = [
58 (lib.cmakeBool "LIBUNWIND_ENABLE_SHARED" enableShared)
59 (lib.cmakeFeature "LLVM_ENABLE_RUNTIMES" "libunwind")
60 ]
61 ++ devExtraCmakeFlags;
62
63 # TODO: Remove on `staging`.
64 prePatch = "";
65 postPatch = "";
66
67 postInstall =
68 lib.optionalString (enableShared && !stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isWindows)
69 ''
70 # libcxxabi wants to link to libunwind_shared.so (?).
71 ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so
72 ''
73 + lib.optionalString (enableShared && stdenv.hostPlatform.isWindows) ''
74 ln -s $out/lib/libunwind.dll.a $out/lib/libunwind_shared.dll.a
75 ''
76 + lib.optionalString (doFakeLibgcc && !stdenv.hostPlatform.isWindows) ''
77 ln -s $out/lib/libunwind.so $out/lib/libgcc_s.so
78 ln -s $out/lib/libunwind.so $out/lib/libgcc_s.so.1
79 ''
80 + lib.optionalString (doFakeLibgcc && stdenv.hostPlatform.isWindows) ''
81 ln -s $out/lib/libunwind.dll.a $out/lib/libgcc_s.dll.a
82 '';
83
84 meta = llvm_meta // {
85 # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst
86 homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library";
87 description = "LLVM's unwinder library";
88 longDescription = ''
89 The unwind library provides a family of _Unwind_* functions implementing
90 the language-neutral stack unwinding portion of the Itanium C++ ABI (Level
91 I). It is a dependency of the C++ ABI library, and sometimes is a
92 dependency of other runtimes.
93 '';
94 };
95})