2021-02-05 17:12:51 +00:00
|
|
|
{ lib, stdenv, fetchFromGitHub, cmake, ninja
|
2020-04-24 23:36:52 +00:00
|
|
|
, secureBuild ? false
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
soext = stdenv.hostPlatform.extensions.sharedLibrary;
|
|
|
|
in
|
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "mimalloc";
|
2022-12-28 21:21:41 +00:00
|
|
|
version = "2.0.9";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "microsoft";
|
|
|
|
repo = pname;
|
|
|
|
rev = "v${version}";
|
2022-12-28 21:21:41 +00:00
|
|
|
sha256 = "sha256-0gX0rEOWT6Lp5AyRyrK5GPTBvAqc5SxSaNJOc5GIgKc=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2022-03-05 16:20:37 +00:00
|
|
|
|
2023-01-20 10:41:00 +00:00
|
|
|
doCheck = !stdenv.hostPlatform.isStatic;
|
2022-03-05 16:20:37 +00:00
|
|
|
preCheck = let
|
|
|
|
ldLibraryPathEnv = if stdenv.isDarwin then "DYLD_LIBRARY_PATH" else "LD_LIBRARY_PATH";
|
|
|
|
in ''
|
|
|
|
export ${ldLibraryPathEnv}="$(pwd)/build:''${${ldLibraryPathEnv}}"
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
nativeBuildInputs = [ cmake ninja ];
|
2023-01-20 10:41:00 +00:00
|
|
|
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" ]
|
|
|
|
;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
postInstall = let
|
2021-02-05 17:12:51 +00:00
|
|
|
rel = lib.versions.majorMinor version;
|
2021-07-03 03:11:41 +00:00
|
|
|
suffix = if stdenv.isLinux then "${soext}.${rel}" else ".${rel}${soext}";
|
2020-04-24 23:36:52 +00:00
|
|
|
in ''
|
2021-07-03 03:11:41 +00:00
|
|
|
# first, move headers and cmake files, that's easy
|
|
|
|
mkdir -p $dev/lib
|
2022-03-05 16:20:37 +00:00
|
|
|
mv $out/lib/cmake $dev/lib/
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-03-05 16:20:37 +00:00
|
|
|
find $dev $out -type f
|
2021-07-03 03:11:41 +00:00
|
|
|
'' + (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
|
|
|
|
'');
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
outputs = [ "out" "dev" ];
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Compact, fast, general-purpose memory allocator";
|
|
|
|
homepage = "https://github.com/microsoft/mimalloc";
|
|
|
|
license = licenses.bsd2;
|
|
|
|
platforms = platforms.unix;
|
2022-03-05 16:20:37 +00:00
|
|
|
maintainers = with maintainers; [ kamadorueda thoughtpolice ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|