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