Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at flake-libs 110 lines 3.9 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchFromGitHub, 5 fetchpatch, 6 autogen, 7 autoconf, 8 automake, 9 # By default, jemalloc puts a je_ prefix onto all its symbols on OSX, which 10 # then stops downstream builds (mariadb in particular) from detecting it. This 11 # option should remove the prefix and give us a working jemalloc. 12 # Causes segfaults with some software (ex. rustc), but defaults to true for backward 13 # compatibility. 14 stripPrefix ? stdenv.hostPlatform.isDarwin, 15 disableInitExecTls ? false, 16}: 17 18stdenv.mkDerivation rec { 19 pname = "jemalloc"; 20 version = "5.3.0"; 21 22 src = fetchFromGitHub { 23 owner = "jemalloc"; 24 repo = "jemalloc"; 25 tag = version; 26 hash = "sha256-bb0OhZVXyvN+hf9BpPSykn5cGm87a0C+Y/iXKt9wTSs="; 27 }; 28 29 patches = [ 30 # fix tests under --with-jemalloc-prefix=, see https://github.com/jemalloc/jemalloc/pull/2340 31 (fetchpatch { 32 url = "https://github.com/jemalloc/jemalloc/commit/d00ecee6a8dfa90afcb1bbc0858985c17bef6559.patch"; 33 hash = "sha256-N5i4IxGJ4SSAgFiq5oGRnrNeegdk2flw9Sh2mP0yl4c="; 34 }) 35 # fix linking with libc++, can be removed in the next update (after 5.3.0). 36 # https://github.com/jemalloc/jemalloc/pull/2348 37 (fetchpatch { 38 url = "https://github.com/jemalloc/jemalloc/commit/4422f88d17404944a312825a1aec96cd9dc6c165.patch"; 39 hash = "sha256-dunkE7XHzltn5bOb/rSHqzpRniAFuGubBStJeCxh0xo="; 40 }) 41 # -O3 appears to introduce an unreproducibility where 42 # `rtree_read.constprop.0` shows up in some builds but 43 # not others, so we fall back to O2: 44 ./o3-to-o2.patch 45 ]; 46 47 nativeBuildInputs = [ 48 autogen 49 autoconf 50 automake 51 ]; 52 53 # TODO: switch to autoreconfHook when updating beyond 5.3.0 54 # https://github.com/jemalloc/jemalloc/issues/2346 55 configureScript = "./autogen.sh"; 56 57 configureFlags = 58 [ 59 "--with-version=${version}-0-g0000000000000000000000000000000000000000" 60 "--with-lg-vaddr=${with stdenv.hostPlatform; toString (if isILP32 then 32 else parsed.cpu.bits)}" 61 ] 62 # see the comment on stripPrefix 63 ++ lib.optional stripPrefix "--with-jemalloc-prefix=" 64 ++ lib.optional disableInitExecTls "--disable-initial-exec-tls" 65 # jemalloc is unable to correctly detect transparent hugepage support on 66 # ARM (https://github.com/jemalloc/jemalloc/issues/526), and the default 67 # kernel ARMv6/7 kernel does not enable it, so we explicitly disable support 68 ++ lib.optionals (stdenv.hostPlatform.isAarch32 && lib.versionOlder version "5") [ 69 "--disable-thp" 70 "je_cv_thp=no" 71 ] 72 # The upstream default is dependent on the builders' page size 73 # https://github.com/jemalloc/jemalloc/issues/467 74 # https://sources.debian.org/src/jemalloc/5.3.0-3/debian/rules/ 75 ++ [ 76 ( 77 if (stdenv.hostPlatform.isAarch64 || stdenv.hostPlatform.isLoongArch64) then 78 "--with-lg-page=16" 79 else 80 "--with-lg-page=12" 81 ) 82 ] 83 # See https://github.com/jemalloc/jemalloc/issues/1997 84 # Using a value of 48 should work on both emulated and native x86_64-darwin. 85 ++ lib.optional (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) "--with-lg-vaddr=48"; 86 87 env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.hostPlatform.isDarwin "-Wno-error=array-bounds"; 88 89 # Tries to link test binaries binaries dynamically and fails 90 doCheck = !stdenv.hostPlatform.isStatic; 91 92 doInstallCheck = true; 93 installCheckPhase = '' 94 ! grep missing_version_try_git_fetch_tags $out/include/jemalloc/jemalloc.h 95 ''; 96 97 # Parallel builds break reproducibility. 98 enableParallelBuilding = false; 99 100 meta = with lib; { 101 homepage = "https://jemalloc.net/"; 102 description = "General purpose malloc(3) implementation"; 103 longDescription = '' 104 malloc(3)-compatible memory allocator that emphasizes fragmentation 105 avoidance and scalable concurrency support. 106 ''; 107 license = licenses.bsd2; 108 platforms = platforms.all; 109 }; 110}