Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at flake-libs 290 lines 9.8 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}: 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 [ 137 cmake 138 python3 139 which 140 swig 141 lit 142 makeWrapper 143 lua5_3 144 ] 145 ++ lib.optionals enableManpages [ 146 python3.pkgs.sphinx 147 ] 148 ++ lib.optionals (lib.versionOlder release_version "18" && enableManpages) [ 149 python3.pkgs.recommonmark 150 ] 151 ++ lib.optionals (lib.versionAtLeast release_version "18" && enableManpages) [ 152 python3.pkgs.myst-parser 153 ] 154 ++ lib.optionals (lib.versionAtLeast release_version "14") [ 155 ninja 156 ]; 157 158 buildInputs = 159 [ 160 ncurses 161 zlib 162 libedit 163 libxml2 164 libllvm 165 ] 166 ++ lib.optionals (lib.versionAtLeast release_version "16") [ 167 # Starting with LLVM 16, the resource dir patch is no longer enough to get 168 # libclang into the rpath of the lldb executables. By putting it into 169 # buildInputs cc-wrapper will set up rpath correctly for us. 170 (lib.getLib libclang) 171 ] 172 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 173 darwin.bootstrap_cmds 174 ]; 175 176 hardeningDisable = [ "format" ]; 177 178 cmakeFlags = 179 [ 180 (lib.cmakeBool "LLDB_INCLUDE_TESTS" finalAttrs.finalPackage.doCheck) 181 (lib.cmakeBool "LLVM_ENABLE_RTTI" false) 182 (lib.cmakeFeature "Clang_DIR" "${lib.getDev libclang}/lib/cmake") 183 (lib.cmakeFeature "LLVM_EXTERNAL_LIT" "${lit}/bin/lit") 184 ] 185 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 186 (lib.cmakeBool "LLDB_USE_SYSTEM_DEBUGSERVER" true) 187 ] 188 ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [ 189 (lib.cmakeFeature "LLDB_CODESIGN_IDENTITY" "") # codesigning makes nondeterministic 190 ] 191 ++ lib.optionals (lib.versionAtLeast release_version "17") [ 192 (lib.cmakeFeature "CLANG_RESOURCE_DIR" "../../../../${lib.getLib libclang}") 193 ] 194 ++ lib.optionals enableManpages ( 195 [ 196 (lib.cmakeBool "LLVM_ENABLE_SPHINX" true) 197 (lib.cmakeBool "SPHINX_OUTPUT_MAN" true) 198 (lib.cmakeBool "SPHINX_OUTPUT_HTML" false) 199 ] 200 ++ lib.optionals (lib.versionAtLeast release_version "15") [ 201 # docs reference `automodapi` but it's not added to the extensions list when 202 # only building the manpages: 203 # https://github.com/llvm/llvm-project/blob/af6ec9200b09039573d85e349496c4f5b17c3d7f/lldb/docs/conf.py#L54 204 # 205 # so, we just ignore the resulting errors 206 (lib.cmakeBool "SPHINX_WARNINGS_AS_ERRORS" false) 207 ] 208 ) 209 ++ lib.optionals finalAttrs.finalPackage.doCheck [ 210 (lib.cmakeFeature "LLDB_TEST_C_COMPILER" "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc") 211 (lib.cmakeFeature "-DLLDB_TEST_CXX_COMPILER" "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++") 212 ] 213 ++ devExtraCmakeFlags; 214 215 doCheck = false; 216 doInstallCheck = lib.versionOlder release_version "15"; 217 218 # TODO: cleanup with mass-rebuild 219 installCheckPhase = 220 '' 221 if [ ! -e ''${!outputLib}/${python3.sitePackages}/lldb/_lldb*.so ] ; then 222 echo "ERROR: python files not installed where expected!"; 223 return 1; 224 fi 225 '' # Something lua is built on older versions but this file doesn't exist. 226 + lib.optionalString (lib.versionAtLeast release_version "14") '' 227 if [ ! -e "''${!outputLib}/lib/lua/${lua5_3.luaversion}/lldb.so" ] ; then 228 echo "ERROR: lua files not installed where expected!"; 229 return 1; 230 fi 231 ''; 232 233 postInstall = '' 234 wrapProgram $out/bin/lldb --prefix PYTHONPATH : ''${!outputLib}/${python3.sitePackages}/ 235 236 # Editor support 237 # vscode: 238 install -D ../tools/${vscodeExt.name}/package.json $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/package.json 239 mkdir -p $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/bin 240 ln -s $out/bin/*${ 241 if lib.versionAtLeast release_version "18" then vscodeExt.name else "-vscode" 242 } $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/bin 243 ''; 244 245 passthru.vscodeExtName = vscodeExt.name; 246 passthru.vscodeExtPublisher = "llvm"; 247 passthru.vscodeExtUniqueId = "llvm-org.${vscodeExt.name}-${vscodeExt.version}"; 248 249 meta = llvm_meta // { 250 homepage = "https://lldb.llvm.org/"; 251 description = "Next-generation high-performance debugger"; 252 longDescription = '' 253 LLDB is a next generation, high-performance debugger. It is built as a set 254 of reusable components which highly leverage existing libraries in the 255 larger LLVM Project, such as the Clang expression parser and LLVM 256 disassembler. 257 ''; 258 broken = lib.versionOlder release_version "14"; 259 mainProgram = "lldb"; 260 }; 261 } 262 // lib.optionalAttrs enableManpages { 263 pname = "lldb-manpages"; 264 265 buildPhase = lib.optionalString (lib.versionOlder release_version "15") '' 266 make ${if (lib.versionOlder release_version "12") then "docs-man" else "docs-lldb-man"} 267 ''; 268 269 ninjaFlags = lib.optionals (lib.versionAtLeast release_version "15") [ "docs-lldb-man" ]; 270 271 propagatedBuildInputs = [ ]; 272 273 # manually install lldb man page 274 installPhase = '' 275 mkdir -p $out/share/man/man1 276 install docs/man/lldb.1 -t $out/share/man/man1/ 277 ''; 278 279 postPatch = null; 280 postInstall = null; 281 282 outputs = [ "out" ]; 283 284 doCheck = false; 285 286 meta = llvm_meta // { 287 description = "man pages for LLDB ${version}"; 288 }; 289 } 290)