nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 412 lines 14 kB view raw
1{ 2 lib, 3 stdenv, 4 icu, 5 zlib, 6 bzip2, 7 zstd, 8 xz, 9 python ? null, 10 fixDarwinDylibNames, 11 libiconv, 12 libxcrypt, 13 makePkgconfigItem, 14 copyPkgconfigItems, 15 boost-build, 16 fetchpatch, 17 which, 18 toolset ? 19 if stdenv.cc.isClang then 20 "clang" 21 else if stdenv.cc.isGNU then 22 "gcc" 23 else 24 null, 25 enableRelease ? true, 26 enableDebug ? false, 27 enableSingleThreaded ? false, 28 enableMultiThreaded ? true, 29 enableShared ? !(with stdenv.hostPlatform; isStatic || isMinGW), # problems for now 30 enableStatic ? !enableShared, 31 enablePython ? false, 32 enableNumpy ? false, 33 enableIcu ? stdenv.hostPlatform == stdenv.buildPlatform, 34 taggedLayout ? ( 35 (enableRelease && enableDebug) 36 || (enableSingleThreaded && enableMultiThreaded) 37 || (enableShared && enableStatic) 38 ), 39 patches ? [ ], 40 boostBuildPatches ? [ ], 41 useMpi ? false, 42 mpi, 43 extraB2Args ? [ ], 44 45 # Attributes inherit from specific versions 46 version, 47 src, 48 ... 49}: 50 51# We must build at least one type of libraries 52assert enableShared || enableStatic; 53 54assert enableNumpy -> enablePython; 55 56let 57 58 variant = lib.concatStringsSep "," ( 59 lib.optional enableRelease "release" ++ lib.optional enableDebug "debug" 60 ); 61 62 threading = lib.concatStringsSep "," ( 63 lib.optional enableSingleThreaded "single" ++ lib.optional enableMultiThreaded "multi" 64 ); 65 66 link = lib.concatStringsSep "," ( 67 lib.optional enableShared "shared" ++ lib.optional enableStatic "static" 68 ); 69 70 runtime-link = if enableShared then "shared" else "static"; 71 72 # To avoid library name collisions 73 layout = if taggedLayout then "tagged" else "system"; 74 75 needUserConfig = 76 stdenv.hostPlatform != stdenv.buildPlatform 77 || useMpi 78 || (stdenv.hostPlatform.isDarwin && enableShared); 79 80 b2Args = lib.concatStringsSep " " ( 81 [ 82 "--includedir=$dev/include" 83 "--libdir=$out/lib" 84 "-j$NIX_BUILD_CORES" 85 "--layout=${layout}" 86 "variant=${variant}" 87 "threading=${threading}" 88 "link=${link}" 89 ] 90 ++ lib.optionals (lib.versionAtLeast version "1.85") [ 91 ( 92 # The stacktrace from exception feature causes memory leaks when built 93 # with libc++. For all other standard library implementations, i.e. 94 # libstdc++, we must acknowledge this or stacktrace refuses to compile. 95 # Issue upstream: https://github.com/boostorg/stacktrace/issues/163 96 if (stdenv.cc.libcxx != null) then 97 "boost.stacktrace.from_exception=off" 98 else 99 "define=BOOST_STACKTRACE_LIBCXX_RUNTIME_MAY_CAUSE_MEMORY_LEAK" 100 ) 101 ] 102 # TODO: make this unconditional 103 ++ 104 lib.optionals 105 ( 106 stdenv.hostPlatform != stdenv.buildPlatform 107 || 108 # required on mips; see 61d9f201baeef4c4bb91ad8a8f5f89b747e0dfe4 109 (stdenv.hostPlatform.isMips && lib.versionAtLeast version "1.79") 110 ) 111 [ 112 "address-model=${toString stdenv.hostPlatform.parsed.cpu.bits}" 113 "architecture=${ 114 if stdenv.hostPlatform.isMips64 then 115 if lib.versionOlder version "1.78" then "mips1" else "mips" 116 else if stdenv.hostPlatform.isS390 then 117 "s390x" 118 else 119 toString stdenv.hostPlatform.parsed.cpu.family 120 }" 121 # env in host triplet for Mach-O is "macho", but boost binary format for Mach-O is "mach-o" 122 "binary-format=${ 123 if stdenv.hostPlatform.isMacho then 124 "mach-o" 125 else 126 toString stdenv.hostPlatform.parsed.kernel.execFormat.name 127 }" 128 "target-os=${ 129 if stdenv.hostPlatform.isCygwin then "cygwin" else toString stdenv.hostPlatform.parsed.kernel.name 130 }" 131 132 # adapted from table in boost manual 133 # https://www.boost.org/doc/libs/1_66_0/libs/context/doc/html/context/architectures.html 134 "abi=${ 135 if stdenv.hostPlatform.parsed.cpu.family == "arm" then 136 "aapcs" 137 else if (stdenv.hostPlatform.isWindows || stdenv.hostPlatform.isCygwin) then 138 "ms" 139 else if stdenv.hostPlatform.isMips32 then 140 "o32" 141 else if stdenv.hostPlatform.isMips64n64 then 142 "n64" 143 else 144 "sysv" 145 }" 146 ] 147 ++ lib.optional (link != "static") "runtime-link=${runtime-link}" 148 ++ lib.optional (variant == "release") "debug-symbols=off" 149 ++ lib.optional (toolset != null) "toolset=${toolset}" 150 ++ lib.optional (!enablePython) "--without-python" 151 ++ lib.optional needUserConfig "--user-config=user-config.jam" 152 ++ lib.optional (stdenv.buildPlatform.isDarwin && stdenv.hostPlatform.isLinux) "pch=off" 153 ++ lib.optionals stdenv.hostPlatform.isMinGW [ 154 "threadapi=win32" 155 ] 156 ++ extraB2Args 157 ); 158 159in 160 161stdenv.mkDerivation { 162 pname = "boost"; 163 164 inherit src version; 165 166 patchFlags = [ ]; 167 168 patches = 169 patches 170 ++ lib.optional ( 171 lib.versionOlder version "1.88" && stdenv.hostPlatform.isDarwin 172 ) ./darwin-no-system-python.patch 173 ++ lib.optional (lib.versionOlder version "1.88") ./cmake-paths-173.patch 174 ++ lib.optional (lib.versionAtLeast version "1.88") ./cmake-paths-188.patch 175 ++ lib.optional (version == "1.77.0") (fetchpatch { 176 url = "https://github.com/boostorg/math/commit/7d482f6ebc356e6ec455ccb5f51a23971bf6ce5b.patch"; 177 relative = "include"; 178 sha256 = "sha256-KlmIbixcds6GyKYt1fx5BxDIrU7msrgDdYo9Va/KJR4="; 179 }) 180 # Fixes ABI detection 181 ++ lib.optional (version == "1.83.0") (fetchpatch { 182 url = "https://github.com/boostorg/context/commit/6fa6d5c50d120e69b2d8a1c0d2256ee933e94b3b.patch"; 183 stripLen = 1; 184 extraPrefix = "libs/context/"; 185 sha256 = "sha256-bCfLL7bD1Rn4Ie/P3X+nIcgTkbXdCX6FW7B9lHsmVW8="; 186 }) 187 # This fixes another issue regarding ill-formed constant expressions, which is a default error 188 # in clang 16 and will be a hard error in clang 17. 189 ++ lib.optional (lib.versionOlder version "1.80") (fetchpatch { 190 url = "https://github.com/boostorg/log/commit/77f1e20bd69c2e7a9e25e6a9818ae6105f7d070c.patch"; 191 relative = "include"; 192 hash = "sha256-6qOiGJASm33XzwoxVZfKJd7sTlQ5yd+MMFQzegXm5RI="; 193 }) 194 ++ lib.optionals (lib.versionOlder version "1.81") [ 195 # libc++ 15 dropped support for `std::unary_function` and `std::binary_function` in C++17+. 196 # C++17 is the default for clang 16, but clang 15 is also affected in that language mode. 197 # This patch is for Boost 1.80, but it also applies to earlier versions. 198 (fetchpatch { 199 url = "https://www.boost.org/patches/1_80_0/0005-config-libcpp15.patch"; 200 hash = "sha256-ULFMzKphv70unvPZ3o4vSP/01/xbSM9a2TlIV67eXDQ="; 201 }) 202 # This fixes another ill-formed contant expressions issue flagged by clang 16. 203 (fetchpatch { 204 url = "https://github.com/boostorg/numeric_conversion/commit/50a1eae942effb0a9b90724323ef8f2a67e7984a.patch"; 205 relative = "include"; 206 hash = "sha256-dq4SVgxkPJSC7Fvr59VGnXkM4Lb09kYDaBksCHo9C0s="; 207 }) 208 # This fixes an issue in Python 3.11 about Py_TPFLAGS_HAVE_GC 209 (fetchpatch { 210 name = "python311-compatibility.patch"; 211 url = "https://github.com/boostorg/python/commit/a218babc8daee904a83f550fb66e5cb3f1cb3013.patch"; 212 hash = "sha256-IHxLtJBx0xSy7QEr8FbCPofsjcPuSYzgtPwDlx1JM+4="; 213 stripLen = 1; 214 extraPrefix = "libs/python/"; 215 }) 216 ] 217 218 ++ lib.optional ( 219 lib.versionAtLeast version "1.81" && lib.versionOlder version "1.88" && stdenv.cc.isClang 220 ) ./fix-clang-target.patch 221 ++ 222 lib.optional (lib.versionAtLeast version "1.86" && lib.versionOlder version "1.87") 223 # Backport fix for NumPy 2 support. 224 ( 225 fetchpatch { 226 name = "boost-numpy-2-compatibility.patch"; 227 url = "https://github.com/boostorg/python/commit/0474de0f6cc9c6e7230aeb7164af2f7e4ccf74bf.patch"; 228 stripLen = 1; 229 extraPrefix = "libs/python/"; 230 hash = "sha256-0IHK55JSujYcwEVOuLkwOa/iPEkdAKQlwVWR42p/X2U="; 231 } 232 ) 233 234 ++ lib.optionals (version == "1.87.0") [ 235 # Fix operator<< for shared_ptr and intrusive_ptr 236 # https://github.com/boostorg/smart_ptr/issues/115 237 (fetchpatch { 238 url = "https://github.com/boostorg/smart_ptr/commit/e7433ba54596da97cb7859455cd37ca140305a9c.patch"; 239 relative = "include"; 240 hash = "sha256-9JvKQOAB19wQpWLNAhuB9eL8qKqXWTQHAJIXdLYMNG8="; 241 }) 242 # Fixes ABI detection on some platforms (like loongarch64) 243 (fetchpatch { 244 url = "https://github.com/boostorg/context/commit/63996e427b4470c7b99b0f4cafb94839ea3670b6.patch"; 245 stripLen = 1; 246 extraPrefix = "libs/context/"; 247 hash = "sha256-Z8uw2+4IEybqVcU25i/0XJKS16hi/+3MXUxs53ghjL0="; 248 }) 249 ]; 250 251 meta = { 252 homepage = "http://boost.org/"; 253 description = "Collection of C++ libraries"; 254 license = lib.licenses.boost; 255 platforms = lib.platforms.unix ++ lib.platforms.windows; 256 # boost-context lacks support for the N32 ABI on mips64. The build 257 # will succeed, but packages depending on boost-context will fail with 258 # a very cryptic error message. 259 badPlatforms = [ lib.systems.inspect.patterns.isMips64n32 ]; 260 broken = 261 enableNumpy && lib.versionOlder version "1.86" && lib.versionAtLeast python.pkgs.numpy.version "2"; 262 }; 263 264 passthru = { 265 inherit boostBuildPatches; 266 }; 267 268 preConfigure = 269 lib.optionalString useMpi '' 270 cat << EOF >> user-config.jam 271 using mpi : ${lib.getDev mpi}/bin/mpiCC ; 272 EOF 273 '' 274 # On darwin we need to add the `$out/lib` to the libraries' rpath explicitly, 275 # otherwise the dynamic linker is unable to resolve the reference to @rpath 276 # when the boost libraries want to load each other at runtime. 277 + lib.optionalString (stdenv.hostPlatform.isDarwin && enableShared) '' 278 cat << EOF >> user-config.jam 279 using clang-darwin : : ${stdenv.cc.targetPrefix}c++ 280 : <linkflags>"-rpath $out/lib/" 281 <archiver>$AR 282 <ranlib>$RANLIB 283 ; 284 EOF 285 '' 286 # b2 has trouble finding the correct compiler and tools for cross compilation 287 # since it apparently ignores $CC, $AR etc. Thus we need to set everything 288 # in user-config.jam. To keep things simple we just set everything in an 289 # uniform way for clang and gcc (which works thanks to our cc-wrapper). 290 # We pass toolset later which will make b2 invoke everything in the right 291 # way -- the other toolset in user-config.jam will be ignored. 292 + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' 293 cat << EOF >> user-config.jam 294 using gcc : cross : ${stdenv.cc.targetPrefix}c++ 295 : <archiver>$AR 296 <ranlib>$RANLIB 297 ; 298 299 using clang : cross : ${stdenv.cc.targetPrefix}c++ 300 : <archiver>$AR 301 <ranlib>$RANLIB 302 ; 303 EOF 304 '' 305 # b2 needs to be explicitly told how to find Python when cross-compiling 306 + lib.optionalString enablePython '' 307 cat << EOF >> user-config.jam 308 using python : : ${python.pythonOnBuildForHost.interpreter} 309 : ${python}/include/python${python.pythonVersion} 310 : ${python}/lib 311 ; 312 EOF 313 ''; 314 315 # Fix compilation to 32-bit ARM with clang in downstream packages 316 # https://github.com/ned14/outcome/pull/308 317 # https://github.com/boostorg/json/pull/1064 318 postPatch = lib.optionalString (version == "1.87.0") '' 319 substituteInPlace \ 320 boost/outcome/outcome_gdb.h \ 321 boost/outcome/experimental/status-code/status_code.hpp \ 322 boost/json/detail/gdb_printers.hpp \ 323 boost/unordered/unordered_printers.hpp \ 324 boost/interprocess/interprocess_printers.hpp \ 325 libs/json/pretty_printers/generate-gdb-header.py \ 326 --replace-fail ",@progbits,1" ",%progbits,1" 327 ''; 328 329 env = { 330 NIX_CFLAGS_LINK = lib.optionalString stdenv.hostPlatform.isDarwin "-headerpad_max_install_names"; 331 # copyPkgconfigItems will substitute these in the pkg-config file 332 includedir = "${placeholder "dev"}/include"; 333 libdir = "${placeholder "out"}/lib"; 334 }; 335 336 pkgconfigItems = [ 337 (makePkgconfigItem { 338 name = "boost"; 339 inherit version; 340 # Exclude other variables not needed by meson 341 variables = { 342 includedir = "@includedir@"; 343 libdir = "@libdir@"; 344 }; 345 }) 346 ]; 347 348 enableParallelBuilding = true; 349 350 nativeBuildInputs = [ 351 which 352 boost-build 353 copyPkgconfigItems 354 ] 355 ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; 356 buildInputs = [ 357 zlib 358 bzip2 359 libiconv 360 ] 361 ++ lib.optional (lib.versionAtLeast version "1.69") zstd 362 ++ [ xz ] 363 ++ lib.optional enableIcu icu 364 ++ lib.optionals enablePython [ 365 libxcrypt 366 python 367 ] 368 ++ lib.optional enableNumpy python.pkgs.numpy; 369 370 configureScript = "./bootstrap.sh"; 371 configurePlatforms = [ ]; 372 dontDisableStatic = true; 373 dontAddStaticConfigureFlags = true; 374 configureFlags = [ 375 "--includedir=$(dev)/include" 376 "--libdir=$(out)/lib" 377 "--with-bjam=b2" # prevent bootstrapping b2 in configurePhase 378 ] 379 ++ lib.optional (toolset != null) "--with-toolset=${toolset}" 380 ++ [ (if enableIcu then "--with-icu=${icu.dev}" else "--without-icu") ]; 381 382 buildPhase = '' 383 runHook preBuild 384 b2 ${b2Args} 385 runHook postBuild 386 ''; 387 388 installPhase = '' 389 runHook preInstall 390 391 # boostbook is needed by some applications 392 mkdir -p $dev/share/boostbook 393 cp -a tools/boostbook/{xsl,dtd} $dev/share/boostbook/ 394 395 # Let boost install everything else 396 b2 ${b2Args} install 397 398 runHook postInstall 399 ''; 400 401 postFixup = lib.optionalString stdenv.hostPlatform.isMinGW '' 402 $RANLIB "$out/lib/"*.a 403 ''; 404 405 outputs = [ 406 "out" 407 "dev" 408 ]; 409 setOutputFlags = false; 410 411 __structuredAttrs = true; 412}