Unverified Commit d0601e79 authored by Wolfgang Walther's avatar Wolfgang Walther Committed by GitHub
Browse files

mimalloc: portability improvements (#415633)

parents eb38d199 d8c6c327
Loading
Loading
Loading
Loading
+23 −10
Original line number Diff line number Diff line
@@ -10,14 +10,14 @@
let
  soext = stdenv.hostPlatform.extensions.sharedLibrary;
in
stdenv.mkDerivation rec {
stdenv.mkDerivation (finalAttrs: {
  pname = "mimalloc";
  version = "3.1.5";

  src = fetchFromGitHub {
    owner = "microsoft";
    repo = "mimalloc";
    rev = "v${version}";
    tag = "v${finalAttrs.version}";
    sha256 = "sha256-fk6nfyBFS1G0sJwUJVgTC1+aKd0We/JjsIYTO+IOfyg=";
  };

@@ -34,16 +34,29 @@ stdenv.mkDerivation rec {
    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" ];
  cmakeFlags = lib.mapAttrsToList lib.cmakeBool {
    MI_INSTALL_TOPLEVEL = true;
    MI_SECURE = secureBuild;
    MI_BUILD_SHARED = stdenv.hostPlatform.hasSharedLibraries;
    MI_LIBC_MUSL = stdenv.hostPlatform.libc == "musl";
    MI_BUILD_TESTS = finalAttrs.doCheck;

    # MI_OPT_ARCH is inaccurate (e.g. it assumes aarch64 == armv8.1-a).
    # Nixpkgs's native platform configuration does a better job.
    MI_NO_OPT_ARCH = true;
  };

  postPatch = ''
    substituteInPlace cmake/mimalloc-config.cmake \
      --replace-fail 'string(REPLACE "/lib/cmake" "/lib" MIMALLOC_LIBRARY_DIR "''${MIMALLOC_CMAKE_DIR}")' \
                     "set(MIMALLOC_LIBRARY_DIR \"$out/lib\")" \
      --replace-fail 'string(REPLACE "/lib/cmake/" "/lib/" MIMALLOC_OBJECT_DIR "''${CMAKE_CURRENT_LIST_DIR}")' \
                     "set(MIMALLOC_OBJECT_DIR \"$out/lib\")"
  '';

  postInstall =
    let
      rel = lib.versions.majorMinor version;
      rel = lib.versions.majorMinor finalAttrs.version;
      suffix = if stdenv.hostPlatform.isLinux then "${soext}.${rel}" else ".${rel}${soext}";
    in
    ''
@@ -76,4 +89,4 @@ stdenv.mkDerivation rec {
      thoughtpolice
    ];
  };
}
})