nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ lib, stdenv, llvm_meta
2, runCommand
3, monorepoSrc
4, cmake
5, zlib
6, ncurses
7, swig
8, which
9, libedit
10, libxml2
11, libllvm
12, libclang
13, python3
14, version
15, libobjc
16, xpc
17, Foundation
18, bootstrap_cmds
19, Carbon
20, Cocoa
21, lit
22, makeWrapper
23, darwin
24, enableManpages ? false
25, lua5_3
26}:
27
28stdenv.mkDerivation (rec {
29 pname = "lldb";
30 inherit version;
31
32 src = runCommand "${pname}-src-${version}" {} ''
33 mkdir -p "$out"
34 cp -r ${monorepoSrc}/cmake "$out"
35 cp -r ${monorepoSrc}/${pname} "$out"
36 '';
37
38 sourceRoot = "${src.name}/${pname}";
39
40 patches = [
41 ./procfs.patch
42 (runCommand "resource-dir.patch" {
43 clangLibDir = "${libclang.lib}/lib";
44 } ''
45 substitute '${./resource-dir.patch}' "$out" --subst-var clangLibDir
46 '')
47 ./gnu-install-dirs.patch
48 ]
49 # This is a stopgap solution if/until the macOS SDK used for x86_64 is
50 # updated.
51 #
52 # The older 10.12 SDK used on x86_64 as of this writing has a `mach/machine.h`
53 # header that does not define `CPU_SUBTYPE_ARM64E` so we replace the one use
54 # of this preprocessor symbol in `lldb` with its expansion.
55 #
56 # See here for some context:
57 # https://github.com/NixOS/nixpkgs/pull/194634#issuecomment-1272129132
58 ++ lib.optional (
59 stdenv.targetPlatform.isDarwin
60 && !stdenv.targetPlatform.isAarch64
61 && (lib.versionOlder darwin.apple_sdk.sdk.version "11.0")
62 ) ./cpu_subtype_arm64e_replacement.patch;
63
64 outputs = [ "out" "lib" "dev" ];
65
66 nativeBuildInputs = [
67 cmake python3 which swig lit makeWrapper lua5_3
68 ] ++ lib.optionals enableManpages [
69 python3.pkgs.sphinx python3.pkgs.recommonmark
70 ];
71
72 buildInputs = [
73 ncurses
74 zlib
75 libedit
76 libxml2
77 libllvm
78 ] ++ lib.optionals stdenv.isDarwin [
79 libobjc
80 xpc
81 Foundation
82 bootstrap_cmds
83 Carbon
84 Cocoa
85 ];
86
87 hardeningDisable = [ "format" ];
88
89 cmakeFlags = [
90 "-DLLDB_INCLUDE_TESTS=${if doCheck then "YES" else "NO"}"
91 "-DLLVM_ENABLE_RTTI=OFF"
92 "-DClang_DIR=${libclang.dev}/lib/cmake"
93 "-DLLVM_EXTERNAL_LIT=${lit}/bin/lit"
94 ] ++ lib.optionals stdenv.isDarwin [
95 "-DLLDB_USE_SYSTEM_DEBUGSERVER=ON"
96 ] ++ lib.optionals (!stdenv.isDarwin) [
97 "-DLLDB_CODESIGN_IDENTITY=" # codesigning makes nondeterministic
98 ] ++ lib.optionals enableManpages [
99 "-DLLVM_ENABLE_SPHINX=ON"
100 "-DSPHINX_OUTPUT_MAN=ON"
101 "-DSPHINX_OUTPUT_HTML=OFF"
102 ] ++ lib.optionals doCheck [
103 "-DLLDB_TEST_C_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"
104 "-DLLDB_TEST_CXX_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++"
105 ];
106
107 doCheck = false;
108
109 doInstallCheck = true;
110
111 installCheckPhase = ''
112 if [ ! -e $lib/${python3.sitePackages}/lldb/_lldb*.so ] ; then
113 echo "ERROR: python files not installed where expected!";
114 return 1;
115 fi
116 if [ ! -e "$lib/lib/lua/${lua5_3.luaversion}/lldb.so" ] ; then
117 echo "ERROR: lua files not installed where expected!";
118 return 1;
119 fi
120 '';
121
122 postInstall = ''
123 wrapProgram $out/bin/lldb --prefix PYTHONPATH : $lib/${python3.sitePackages}/
124
125 # Editor support
126 # vscode:
127 install -D ../tools/lldb-vscode/package.json $out/share/vscode/extensions/llvm-org.lldb-vscode-0.1.0/package.json
128 mkdir -p $out/share/vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin
129 ln -s $out/bin/lldb-vscode $out/share/vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin
130 '';
131
132 meta = llvm_meta // {
133 homepage = "https://lldb.llvm.org/";
134 description = "A next-generation high-performance debugger";
135 longDescription = ''
136 LLDB is a next generation, high-performance debugger. It is built as a set
137 of reusable components which highly leverage existing libraries in the
138 larger LLVM Project, such as the Clang expression parser and LLVM
139 disassembler.
140 '';
141 };
142} // lib.optionalAttrs enableManpages {
143 pname = "lldb-manpages";
144
145 buildPhase = ''
146 make docs-lldb-man
147 '';
148
149 propagatedBuildInputs = [];
150
151 # manually install lldb man page
152 installPhase = ''
153 mkdir -p $out/share/man/man1
154 install docs/man/lldb.1 -t $out/share/man/man1/
155 '';
156
157 postPatch = null;
158 postInstall = null;
159
160 outputs = [ "out" ];
161
162 doCheck = false;
163
164 meta = llvm_meta // {
165 description = "man pages for LLDB ${version}";
166 };
167})