1{
2 lib,
3 stdenv,
4 llvm_meta,
5 release_version,
6 cmake,
7 zlib,
8 ncurses,
9 swig,
10 which,
11 libedit,
12 libxml2,
13 libllvm,
14 libclang,
15 python3,
16 version,
17 darwin,
18 lit,
19 makeWrapper,
20 lua5_3,
21 ninja,
22 runCommand,
23 src ? null,
24 monorepoSrc ? null,
25 enableManpages ? false,
26 devExtraCmakeFlags ? [ ],
27 getVersionFile,
28 fetchpatch,
29 fetchpatch2,
30 replaceVars,
31 ...
32}:
33
34let
35 vscodeExt = {
36 name = if lib.versionAtLeast release_version "18" then "lldb-dap" else "lldb-vscode";
37 version = if lib.versionAtLeast release_version "18" then "0.2.0" else "0.1.0";
38 };
39in
40
41stdenv.mkDerivation (
42 finalAttrs:
43 {
44 passthru.monorepoSrc = monorepoSrc;
45 pname = "lldb";
46 inherit version;
47
48 src =
49 if monorepoSrc != null then
50 runCommand "lldb-src-${version}" { inherit (monorepoSrc) passthru; } (
51 ''
52 mkdir -p "$out"
53 ''
54 + lib.optionalString (lib.versionAtLeast release_version "14") ''
55 cp -r ${monorepoSrc}/cmake "$out"
56 ''
57 + ''
58 cp -r ${monorepoSrc}/lldb "$out"
59 ''
60 + lib.optionalString (lib.versionAtLeast release_version "19" && enableManpages) ''
61 mkdir -p "$out/llvm"
62 cp -r ${monorepoSrc}/llvm/docs "$out/llvm/docs"
63 ''
64 )
65 else
66 src;
67
68 # There is no `lib` output because some of the files in `$out/lib` depend on files in `$out/bin`.
69 # For example, `$out/lib/python3.12/site-packages/lldb/lldb-argdumper` is a symlink to `$out/bin/lldb-argdumper`.
70 # Also, LLDB expects to find the path to `bin` relative to `lib` on Darwin.
71 outputs = [
72 "out"
73 "dev"
74 ];
75
76 sourceRoot = lib.optional (lib.versionAtLeast release_version "13") "${finalAttrs.src.name}/lldb";
77
78 patches =
79 let
80 resourceDirPatch =
81 (replaceVars (getVersionFile "lldb/resource-dir.patch") {
82 clangLibDir = "${lib.getLib libclang}/lib";
83 }).overrideAttrs
84 (_: _: { name = "resource-dir.patch"; });
85 in
86 lib.optionals (lib.versionOlder release_version "15") [
87 # Fixes for SWIG 4
88 (fetchpatch2 {
89 url = "https://github.com/llvm/llvm-project/commit/81fc5f7909a4ef5a8d4b5da2a10f77f7cb01ba63.patch?full_index=1";
90 stripLen = 1;
91 hash = "sha256-Znw+C0uEw7lGETQLKPBZV/Ymo2UigZS+Hv/j1mUo7p0=";
92 })
93 (fetchpatch2 {
94 url = "https://github.com/llvm/llvm-project/commit/f0a25fe0b746f56295d5c02116ba28d2f965c175.patch?full_index=1";
95 stripLen = 1;
96 hash = "sha256-QzVeZzmc99xIMiO7n//b+RNAvmxghISKQD93U2zOgFI=";
97 })
98 ]
99 ++ lib.optionals (lib.versionOlder release_version "16") [
100 # Fixes for SWIG 4
101 (fetchpatch2 {
102 url = "https://github.com/llvm/llvm-project/commit/ba35c27ec9aa9807f5b4be2a0c33ca9b045accc7.patch?full_index=1";
103 stripLen = 1;
104 hash = "sha256-LXl+WbpmWZww5xMDrle3BM2Tw56v8k9LO1f1Z1/wDTs=";
105 })
106 (fetchpatch2 {
107 url = "https://github.com/llvm/llvm-project/commit/9ec115978ea2bdfc60800cd3c21264341cdc8b0a.patch?full_index=1";
108 stripLen = 1;
109 hash = "sha256-u0zSejEjfrH3ZoMFm1j+NVv2t5AP9cE5yhsrdTS1dG4=";
110 })
111
112 # FIXME: do we need this after 15?
113 (getVersionFile "lldb/procfs.patch")
114 ]
115 ++ lib.optional (lib.versionOlder release_version "18") (fetchpatch {
116 name = "libcxx-19-char_traits.patch";
117 url = "https://github.com/llvm/llvm-project/commit/68744ffbdd7daac41da274eef9ac0d191e11c16d.patch";
118 stripLen = 1;
119 hash = "sha256-QCGhsL/mi7610ZNb5SqxjRGjwJeK2rwtsFVGeG3PUGc=";
120 })
121 ++ lib.optionals (lib.versionOlder release_version "17") [
122 resourceDirPatch
123 (fetchpatch {
124 name = "add-cstdio.patch";
125 url = "https://github.com/llvm/llvm-project/commit/73e15b5edb4fa4a77e68c299a6e3b21e610d351f.patch";
126 stripLen = 1;
127 hash = "sha256-eFcvxZaAuBsY/bda1h9212QevrXyvCHw8Cr9ngetDr0=";
128 })
129 ]
130 ++ lib.optional (lib.versionOlder release_version "14") (
131 getVersionFile "lldb/gnu-install-dirs.patch"
132 )
133 ++ lib.optional (lib.versionAtLeast release_version "14") ./gnu-install-dirs.patch;
134
135 nativeBuildInputs = [
136 cmake
137 python3
138 which
139 swig
140 lit
141 makeWrapper
142 lua5_3
143 ]
144 ++ lib.optionals enableManpages [
145 python3.pkgs.sphinx
146 ]
147 ++ lib.optionals (lib.versionOlder release_version "18" && enableManpages) [
148 python3.pkgs.recommonmark
149 ]
150 ++ lib.optionals (lib.versionAtLeast release_version "18" && enableManpages) [
151 python3.pkgs.myst-parser
152 ]
153 ++ lib.optionals (lib.versionAtLeast release_version "14") [
154 ninja
155 ];
156
157 buildInputs = [
158 ncurses
159 zlib
160 libedit
161 libxml2
162 libllvm
163 ]
164 ++ lib.optionals (lib.versionAtLeast release_version "16") [
165 # Starting with LLVM 16, the resource dir patch is no longer enough to get
166 # libclang into the rpath of the lldb executables. By putting it into
167 # buildInputs cc-wrapper will set up rpath correctly for us.
168 (lib.getLib libclang)
169 ]
170 ++ lib.optionals stdenv.hostPlatform.isDarwin [
171 darwin.bootstrap_cmds
172 ];
173
174 hardeningDisable = [ "format" ];
175
176 cmakeFlags = [
177 (lib.cmakeBool "LLDB_INCLUDE_TESTS" finalAttrs.finalPackage.doCheck)
178 (lib.cmakeBool "LLVM_ENABLE_RTTI" false)
179 (lib.cmakeFeature "Clang_DIR" "${lib.getDev libclang}/lib/cmake")
180 (lib.cmakeFeature "LLVM_EXTERNAL_LIT" "${lit}/bin/lit")
181 ]
182 ++ lib.optionals stdenv.hostPlatform.isDarwin [
183 (lib.cmakeBool "LLDB_USE_SYSTEM_DEBUGSERVER" true)
184 ]
185 ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [
186 (lib.cmakeFeature "LLDB_CODESIGN_IDENTITY" "") # codesigning makes nondeterministic
187 ]
188 ++ lib.optionals (lib.versionAtLeast release_version "17") [
189 (lib.cmakeFeature "CLANG_RESOURCE_DIR" "../../../../${lib.getLib libclang}")
190 ]
191 ++ lib.optionals enableManpages (
192 [
193 (lib.cmakeBool "LLVM_ENABLE_SPHINX" true)
194 (lib.cmakeBool "SPHINX_OUTPUT_MAN" true)
195 (lib.cmakeBool "SPHINX_OUTPUT_HTML" false)
196 ]
197 ++ lib.optionals (lib.versionAtLeast release_version "15") [
198 # docs reference `automodapi` but it's not added to the extensions list when
199 # only building the manpages:
200 # https://github.com/llvm/llvm-project/blob/af6ec9200b09039573d85e349496c4f5b17c3d7f/lldb/docs/conf.py#L54
201 #
202 # so, we just ignore the resulting errors
203 (lib.cmakeBool "SPHINX_WARNINGS_AS_ERRORS" false)
204 ]
205 )
206 ++ lib.optionals finalAttrs.finalPackage.doCheck [
207 (lib.cmakeFeature "LLDB_TEST_C_COMPILER" "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc")
208 (lib.cmakeFeature "-DLLDB_TEST_CXX_COMPILER" "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++")
209 ]
210 ++ devExtraCmakeFlags;
211
212 doCheck = false;
213 doInstallCheck = lib.versionOlder release_version "15";
214
215 # TODO: cleanup with mass-rebuild
216 installCheckPhase = ''
217 if [ ! -e ''${!outputLib}/${python3.sitePackages}/lldb/_lldb*.so ] ; then
218 echo "ERROR: python files not installed where expected!";
219 return 1;
220 fi
221 '' # Something lua is built on older versions but this file doesn't exist.
222 + lib.optionalString (lib.versionAtLeast release_version "14") ''
223 if [ ! -e "''${!outputLib}/lib/lua/${lua5_3.luaversion}/lldb.so" ] ; then
224 echo "ERROR: lua files not installed where expected!";
225 return 1;
226 fi
227 '';
228
229 postInstall = ''
230 wrapProgram $out/bin/lldb --prefix PYTHONPATH : ''${!outputLib}/${python3.sitePackages}/
231
232 # Editor support
233 # vscode:
234 install -D ../tools/${vscodeExt.name}/package.json $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/package.json
235 mkdir -p $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/bin
236 ln -s $out/bin/*${
237 if lib.versionAtLeast release_version "18" then vscodeExt.name else "-vscode"
238 } $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/bin
239 '';
240
241 passthru.vscodeExtName = vscodeExt.name;
242 passthru.vscodeExtPublisher = "llvm";
243 passthru.vscodeExtUniqueId = "llvm-org.${vscodeExt.name}-${vscodeExt.version}";
244
245 meta = llvm_meta // {
246 homepage = "https://lldb.llvm.org/";
247 description = "Next-generation high-performance debugger";
248 longDescription = ''
249 LLDB is a next generation, high-performance debugger. It is built as a set
250 of reusable components which highly leverage existing libraries in the
251 larger LLVM Project, such as the Clang expression parser and LLVM
252 disassembler.
253 '';
254 broken = lib.versionOlder release_version "14";
255 mainProgram = "lldb";
256 };
257 }
258 // lib.optionalAttrs enableManpages {
259 pname = "lldb-manpages";
260
261 buildPhase = lib.optionalString (lib.versionOlder release_version "15") ''
262 make ${if (lib.versionOlder release_version "12") then "docs-man" else "docs-lldb-man"}
263 '';
264
265 ninjaFlags = lib.optionals (lib.versionAtLeast release_version "15") [ "docs-lldb-man" ];
266
267 propagatedBuildInputs = [ ];
268
269 # manually install lldb man page
270 installPhase = ''
271 mkdir -p $out/share/man/man1
272 install docs/man/lldb.1 -t $out/share/man/man1/
273 '';
274
275 postPatch = null;
276 postInstall = null;
277
278 outputs = [ "out" ];
279
280 doCheck = false;
281
282 meta = llvm_meta // {
283 description = "man pages for LLDB ${version}";
284 };
285 }
286)