Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ 2 lib, 3 stdenv, 4 fetchFromGitHub, 5 cmake, 6 ninja, 7 secureBuild ? false, 8}: 9 10let 11 soext = stdenv.hostPlatform.extensions.sharedLibrary; 12in 13stdenv.mkDerivation rec { 14 pname = "mimalloc"; 15 version = "3.1.5"; 16 17 src = fetchFromGitHub { 18 owner = "microsoft"; 19 repo = "mimalloc"; 20 rev = "v${version}"; 21 sha256 = "sha256-fk6nfyBFS1G0sJwUJVgTC1+aKd0We/JjsIYTO+IOfyg="; 22 }; 23 24 doCheck = !stdenv.hostPlatform.isStatic; 25 preCheck = 26 let 27 ldLibraryPathEnv = if stdenv.hostPlatform.isDarwin then "DYLD_LIBRARY_PATH" else "LD_LIBRARY_PATH"; 28 in 29 '' 30 export ${ldLibraryPathEnv}="$(pwd)/build:''${${ldLibraryPathEnv}}" 31 ''; 32 33 nativeBuildInputs = [ 34 cmake 35 ninja 36 ]; 37 cmakeFlags = [ 38 "-DMI_INSTALL_TOPLEVEL=ON" 39 ] 40 ++ lib.optionals secureBuild [ "-DMI_SECURE=ON" ] 41 ++ lib.optionals stdenv.hostPlatform.isStatic [ "-DMI_BUILD_SHARED=OFF" ] 42 ++ lib.optionals (!doCheck) [ "-DMI_BUILD_TESTS=OFF" ]; 43 44 postInstall = 45 let 46 rel = lib.versions.majorMinor version; 47 suffix = if stdenv.hostPlatform.isLinux then "${soext}.${rel}" else ".${rel}${soext}"; 48 in 49 '' 50 # first, move headers and cmake files, that's easy 51 mkdir -p $dev/lib 52 mv $out/lib/cmake $dev/lib/ 53 54 find $dev $out -type f 55 '' 56 + (lib.optionalString secureBuild '' 57 # pretend we're normal mimalloc 58 ln -sfv $out/lib/libmimalloc-secure${suffix} $out/lib/libmimalloc${suffix} 59 ln -sfv $out/lib/libmimalloc-secure${suffix} $out/lib/libmimalloc${soext} 60 ln -sfv $out/lib/libmimalloc-secure.a $out/lib/libmimalloc.a 61 ln -sfv $out/lib/mimalloc-secure.o $out/lib/mimalloc.o 62 ''); 63 64 outputs = [ 65 "out" 66 "dev" 67 ]; 68 69 meta = with lib; { 70 description = "Compact, fast, general-purpose memory allocator"; 71 homepage = "https://github.com/microsoft/mimalloc"; 72 license = licenses.bsd2; 73 platforms = platforms.unix; 74 maintainers = with maintainers; [ 75 kamadorueda 76 thoughtpolice 77 ]; 78 }; 79}