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