nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
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
33let
34 vscodeExt = {
35 name = "lldb-dap";
36 version = "0.2.0";
37 };
38in
39
40stdenv.mkDerivation (
41 finalAttrs:
42 {
43 passthru.monorepoSrc = monorepoSrc;
44 pname = "lldb";
45 inherit version;
46
47 src =
48 if monorepoSrc != null then
49 runCommand "lldb-src-${version}" { inherit (monorepoSrc) passthru; } (
50 ''
51 mkdir -p "$out"
52 cp -r ${monorepoSrc}/cmake "$out"
53 cp -r ${monorepoSrc}/lldb "$out"
54 ''
55 + lib.optionalString (lib.versionAtLeast release_version "19" && enableManpages) ''
56 mkdir -p "$out/llvm"
57 cp -r ${monorepoSrc}/llvm/docs "$out/llvm/docs"
58 ''
59 )
60 else
61 src;
62
63 # There is no `lib` output because some of the files in `$out/lib` depend on files in `$out/bin`.
64 # For example, `$out/lib/python3.12/site-packages/lldb/lldb-argdumper` is a symlink to `$out/bin/lldb-argdumper`.
65 # Also, LLDB expects to find the path to `bin` relative to `lib` on Darwin.
66 outputs = [
67 "out"
68 "dev"
69 ];
70
71 sourceRoot = "${finalAttrs.src.name}/lldb";
72
73 patches = [
74 ./gnu-install-dirs.patch
75 ]
76 ++ lib.optional (lib.versions.major release_version == "18") [
77 # Fix build with gcc15
78 # https://github.com/llvm/llvm-project/commit/bb59f04e7e75dcbe39f1bf952304a157f0035314
79 ./lldb-add-include-cstdint.patch
80 ];
81
82 nativeBuildInputs = [
83 cmake
84 ninja
85 python3
86 which
87 swig
88 lit
89 makeWrapper
90 lua5_3
91 ]
92 ++ lib.optionals enableManpages [
93 python3.pkgs.sphinx
94 python3.pkgs.myst-parser
95 ];
96
97 buildInputs = [
98 ncurses
99 zlib
100 libedit
101 libxml2
102 libllvm
103 # Starting with LLVM 16, the resource dir patch is no longer enough to get
104 # libclang into the rpath of the lldb executables. By putting it into
105 # buildInputs cc-wrapper will set up rpath correctly for us.
106 (lib.getLib libclang)
107 ]
108 ++ lib.optionals stdenv.hostPlatform.isDarwin [
109 darwin.bootstrap_cmds
110 ];
111
112 hardeningDisable = [ "format" ];
113
114 cmakeFlags = [
115 (lib.cmakeBool "LLDB_INCLUDE_TESTS" finalAttrs.finalPackage.doCheck)
116 (lib.cmakeBool "LLVM_ENABLE_RTTI" false)
117 (lib.cmakeFeature "Clang_DIR" "${lib.getDev libclang}/lib/cmake")
118 (lib.cmakeFeature "LLVM_EXTERNAL_LIT" "${lit}/bin/lit")
119 (lib.cmakeFeature "CLANG_RESOURCE_DIR" "../../../../${lib.getLib libclang}")
120 ]
121 ++ lib.optionals stdenv.hostPlatform.isDarwin [
122 (lib.cmakeBool "LLDB_USE_SYSTEM_DEBUGSERVER" true)
123 ]
124 ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [
125 (lib.cmakeFeature "LLDB_CODESIGN_IDENTITY" "") # codesigning makes nondeterministic
126 ]
127 ++ lib.optionals enableManpages [
128 (lib.cmakeBool "LLVM_ENABLE_SPHINX" true)
129 (lib.cmakeBool "SPHINX_OUTPUT_MAN" true)
130 (lib.cmakeBool "SPHINX_OUTPUT_HTML" false)
131 # docs reference `automodapi` but it's not added to the extensions list when
132 # only building the manpages:
133 # https://github.com/llvm/llvm-project/blob/af6ec9200b09039573d85e349496c4f5b17c3d7f/lldb/docs/conf.py#L54
134 #
135 # so, we just ignore the resulting errors
136 (lib.cmakeBool "SPHINX_WARNINGS_AS_ERRORS" false)
137 ]
138 ++ lib.optionals finalAttrs.finalPackage.doCheck [
139 (lib.cmakeFeature "LLDB_TEST_C_COMPILER" "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc")
140 (lib.cmakeFeature "-DLLDB_TEST_CXX_COMPILER" "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++")
141 ]
142 ++ devExtraCmakeFlags;
143
144 doCheck = false;
145 doInstallCheck = false;
146
147 # TODO: cleanup with mass-rebuild
148 installCheckPhase = ''
149 if [ ! -e ''${!outputLib}/${python3.sitePackages}/lldb/_lldb*.so ] ; then
150 echo "ERROR: python files not installed where expected!";
151 return 1;
152 fi
153 if [ ! -e "''${!outputLib}/lib/lua/${lua5_3.luaversion}/lldb.so" ] ; then
154 echo "ERROR: lua files not installed where expected!";
155 return 1;
156 fi
157 '';
158
159 postInstall = ''
160 wrapProgram $out/bin/lldb --prefix PYTHONPATH : ''${!outputLib}/${python3.sitePackages}/
161
162 # Editor support
163 # vscode:
164 install -D ../tools/${vscodeExt.name}/package.json $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/package.json
165 mkdir -p $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/bin
166 ln -s $out/bin/*${vscodeExt.name} $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/bin
167 '';
168
169 passthru.vscodeExtName = vscodeExt.name;
170 passthru.vscodeExtPublisher = "llvm";
171 passthru.vscodeExtUniqueId = "llvm-org.${vscodeExt.name}-${vscodeExt.version}";
172
173 meta = llvm_meta // {
174 homepage = "https://lldb.llvm.org/";
175 description = "Next-generation high-performance debugger";
176 longDescription = ''
177 LLDB is a next generation, high-performance debugger. It is built as a set
178 of reusable components which highly leverage existing libraries in the
179 larger LLVM Project, such as the Clang expression parser and LLVM
180 disassembler.
181 '';
182 mainProgram = "lldb";
183 };
184 }
185 // lib.optionalAttrs enableManpages {
186 pname = "lldb-manpages";
187
188 ninjaFlags = [ "docs-lldb-man" ];
189
190 propagatedBuildInputs = [ ];
191
192 # manually install lldb man page
193 installPhase = ''
194 mkdir -p $out/share/man/man1
195 install docs/man/lldb.1 -t $out/share/man/man1/
196 '';
197
198 postPatch = null;
199 postInstall = null;
200
201 outputs = [ "out" ];
202
203 doCheck = false;
204
205 meta = llvm_meta // {
206 description = "man pages for LLDB ${version}";
207 };
208 }
209)