at master 6.0 kB view raw
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 = [ ./gnu-install-dirs.patch ]; 74 75 nativeBuildInputs = [ 76 cmake 77 python3 78 which 79 swig 80 lit 81 makeWrapper 82 lua5_3 83 ] 84 ++ lib.optionals enableManpages [ 85 python3.pkgs.sphinx 86 python3.pkgs.myst-parser 87 ] 88 # TODO: Clean up on `staging`. 89 ++ [ 90 ninja 91 ]; 92 93 buildInputs = [ 94 ncurses 95 zlib 96 libedit 97 libxml2 98 libllvm 99 # Starting with LLVM 16, the resource dir patch is no longer enough to get 100 # libclang into the rpath of the lldb executables. By putting it into 101 # buildInputs cc-wrapper will set up rpath correctly for us. 102 (lib.getLib libclang) 103 ] 104 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 105 darwin.bootstrap_cmds 106 ]; 107 108 hardeningDisable = [ "format" ]; 109 110 cmakeFlags = [ 111 (lib.cmakeBool "LLDB_INCLUDE_TESTS" finalAttrs.finalPackage.doCheck) 112 (lib.cmakeBool "LLVM_ENABLE_RTTI" false) 113 (lib.cmakeFeature "Clang_DIR" "${lib.getDev libclang}/lib/cmake") 114 (lib.cmakeFeature "LLVM_EXTERNAL_LIT" "${lit}/bin/lit") 115 ] 116 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 117 (lib.cmakeBool "LLDB_USE_SYSTEM_DEBUGSERVER" true) 118 ] 119 ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [ 120 (lib.cmakeFeature "LLDB_CODESIGN_IDENTITY" "") # codesigning makes nondeterministic 121 ] 122 # TODO: Clean up on `staging`. 123 ++ [ 124 (lib.cmakeFeature "CLANG_RESOURCE_DIR" "../../../../${lib.getLib libclang}") 125 ] 126 ++ lib.optionals enableManpages [ 127 (lib.cmakeBool "LLVM_ENABLE_SPHINX" true) 128 (lib.cmakeBool "SPHINX_OUTPUT_MAN" true) 129 (lib.cmakeBool "SPHINX_OUTPUT_HTML" false) 130 # docs reference `automodapi` but it's not added to the extensions list when 131 # only building the manpages: 132 # https://github.com/llvm/llvm-project/blob/af6ec9200b09039573d85e349496c4f5b17c3d7f/lldb/docs/conf.py#L54 133 # 134 # so, we just ignore the resulting errors 135 (lib.cmakeBool "SPHINX_WARNINGS_AS_ERRORS" false) 136 ] 137 ++ lib.optionals finalAttrs.finalPackage.doCheck [ 138 (lib.cmakeFeature "LLDB_TEST_C_COMPILER" "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc") 139 (lib.cmakeFeature "-DLLDB_TEST_CXX_COMPILER" "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++") 140 ] 141 ++ devExtraCmakeFlags; 142 143 doCheck = false; 144 doInstallCheck = false; 145 146 # TODO: cleanup with mass-rebuild 147 installCheckPhase = '' 148 if [ ! -e ''${!outputLib}/${python3.sitePackages}/lldb/_lldb*.so ] ; then 149 echo "ERROR: python files not installed where expected!"; 150 return 1; 151 fi 152 if [ ! -e "''${!outputLib}/lib/lua/${lua5_3.luaversion}/lldb.so" ] ; then 153 echo "ERROR: lua files not installed where expected!"; 154 return 1; 155 fi 156 ''; 157 158 postInstall = '' 159 wrapProgram $out/bin/lldb --prefix PYTHONPATH : ''${!outputLib}/${python3.sitePackages}/ 160 161 # Editor support 162 # vscode: 163 install -D ../tools/${vscodeExt.name}/package.json $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/package.json 164 mkdir -p $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/bin 165 ln -s $out/bin/*${vscodeExt.name} $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/bin 166 ''; 167 168 passthru.vscodeExtName = vscodeExt.name; 169 passthru.vscodeExtPublisher = "llvm"; 170 passthru.vscodeExtUniqueId = "llvm-org.${vscodeExt.name}-${vscodeExt.version}"; 171 172 meta = llvm_meta // { 173 homepage = "https://lldb.llvm.org/"; 174 description = "Next-generation high-performance debugger"; 175 longDescription = '' 176 LLDB is a next generation, high-performance debugger. It is built as a set 177 of reusable components which highly leverage existing libraries in the 178 larger LLVM Project, such as the Clang expression parser and LLVM 179 disassembler. 180 ''; 181 mainProgram = "lldb"; 182 }; 183 } 184 // lib.optionalAttrs enableManpages { 185 pname = "lldb-manpages"; 186 187 # TODO: Remove on `staging`. 188 buildPhase = ""; 189 190 ninjaFlags = [ "docs-lldb-man" ]; 191 192 propagatedBuildInputs = [ ]; 193 194 # manually install lldb man page 195 installPhase = '' 196 mkdir -p $out/share/man/man1 197 install docs/man/lldb.1 -t $out/share/man/man1/ 198 ''; 199 200 postPatch = null; 201 postInstall = null; 202 203 outputs = [ "out" ]; 204 205 doCheck = false; 206 207 meta = llvm_meta // { 208 description = "man pages for LLDB ${version}"; 209 }; 210 } 211)