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