Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mimalloc: add version 1.7.7/2.0.7, support conan v2 #14174

Merged
merged 13 commits into from
Nov 29, 2022
7 changes: 0 additions & 7 deletions recipes/mimalloc/all/CMakeLists.txt

This file was deleted.

45 changes: 34 additions & 11 deletions recipes/mimalloc/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"2.0.7":
url: "https://github.com/microsoft/mimalloc/archive/v2.0.7.tar.gz"
sha256: "f23aac6c73594e417af50cb38f1efed88ef1dc14a490f0eff07c7f7b079810a4"
"2.0.6":
url: "https://github.com/microsoft/mimalloc/archive/v2.0.6.tar.gz"
sha256: "9f05c94cc2b017ed13698834ac2a3567b6339a8bde27640df5a1581d49d05ce5"
Expand All @@ -11,6 +14,9 @@ sources:
"2.0.2":
url: "https://github.com/microsoft/mimalloc/archive/v2.0.2.tar.gz"
sha256: "c81a5f443f72373e3105172d6a935e29b0dabd13ba387c080bc444586cbe3021"
"1.7.7":
url: "https://github.com/microsoft/mimalloc/archive/v1.7.7.tar.gz"
sha256: "0f6663be1e1764851bf9563fcf7a6b3330e23b933eb4737dd07e3289b87895fe"
"1.7.6":
url: "https://github.com/microsoft/mimalloc/archive/v1.7.6.tar.gz"
sha256: "d74f86ada2329016068bc5a243268f1f555edd620b6a7d6ce89295e7d6cf18da"
Expand All @@ -21,28 +27,45 @@ sources:
url: "https://github.com/microsoft/mimalloc/archive/v1.6.7.tar.gz"
sha256: "111b718b496f297f128d842880e72e90e33953cf00b45ba0ccd2167e7340ed17"
patches:
"2.0.7":
- patch_file: "patches/2.0.7-0001-change-install-paths.patch"
patch_description: "fix install paths"
patch_type: "conan"
"2.0.6":
- patch_file: "patches/2.0.6-0001-change-install-paths.patch"
base_path: "source_subfolder"
patch_description: "fix install paths"
patch_type: "conan"
"2.0.5":
- patch_file: "patches/2.0.6-0001-change-install-paths.patch"
base_path: "source_subfolder"
patch_description: "fix install paths"
patch_type: "conan"
"2.0.3":
- patch_file: "patches/2.0.3-0001-change-install-paths-avoid-symlink.patch"
base_path: "source_subfolder"
patch_description: "fix install paths, disable creating symlink"
patch_type: "conan"
"2.0.2":
- patch_file: "patches/2.0.2-0001-change-install-paths-avoid-symlink.patch"
base_path: "source_subfolder"
patch_description: "fix install paths, disable creating symlink"
patch_type: "conan"
- patch_file: "patches/2.0.2-0002-include-cstddef-to-get-std-size-t.patch"
base_path: "source_subfolder"
patch_description: "include stddef"
patch_type: "portability"
"1.7.7":
- patch_file: "patches/1.7.7-0001-change-install-paths.patch"
patch_description: "fix install paths"
patch_type: "conan"
"1.7.6":
- patch_file: "patches/1.7.6-0001-change-install-paths-avoid-symlink.patch"
base_path: "source_subfolder"
- patch_file: "patches/1.7.5-0001-change-install-paths.patch"
patch_description: "fix install paths"
patch_type: "conan"
"1.7.5":
- patch_file: "patches/1.7.5-0001-change-install-paths-avoid-symlink.patch"
base_path: "source_subfolder"
- patch_file: "patches/1.7.5-0001-change-install-paths.patch"
patch_description: "fix install paths"
patch_type: "conan"
"1.6.7":
- patch_file: "patches/1.6.7-0001-change-install-paths-avoid-symlink.patch"
base_path: "source_subfolder"
patch_description: "fix install paths, disable creating symlink"
patch_type: "conan"
- patch_file: "patches/1.6.7-0002-include-cstddef-to-get-std-size-t.patch"
base_path: "source_subfolder"
patch_description: "include stddef"
patch_type: "portability"
168 changes: 81 additions & 87 deletions recipes/mimalloc/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
from conan.tools import microsoft

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.microsoft import check_min_vs, is_msvc, msvc_runtime_flag, VCVars
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir, replace_in_file, save, collect_libs
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
import os
import shutil
import textwrap
import functools

required_conan_version = ">=1.45.0"
required_conan_version = ">=1.53.0"


class MimallocConan(ConanFile):
Expand Down Expand Up @@ -36,15 +38,10 @@ class MimallocConan(ConanFile):
"single_object": False,
}

generators = "cmake"

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"
def _min_cppstd(self):
return 17

@property
def _compilers_minimum_version(self):
Expand All @@ -56,56 +53,54 @@ def _compilers_minimum_version(self):
}

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

# single_object and inject are options
# only when overriding on Unix-like platforms:
if microsoft.is_msvc(self):
if is_msvc(self):
del self.options.single_object
del self.options.inject

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options.rm_safe("fPIC")

# single_object is valid only for static
# override:
if self.options.get_safe("single_object"):
del self.options.single_object
self.options.rm_safe("single_object")

# inject is valid only for Unix-like dynamic override:
if not self.options.shared and self.options.get_safe("inject"):
del self.options.inject
if not self.options.shared:
self.options.rm_safe("inject")

# single_object and inject are valid only when
# overriding on Unix-like platforms:
if not self.options.override:
if self.options.get_safe("single_object"):
del self.options.single_object
if self.options.get_safe("inject"):
del self.options.inject
self.options.rm_safe("single_object")
self.options.rm_safe("inject")

def layout(self):
cmake_layout(self, src_folder="src")

def validate(self):
# Currently, mimalloc/1.7.6,2.0.6 does not work properly with shared MD builds.
# Currently, mimalloc some version do not work properly with shared MD builds.
# https://github.com/conan-io/conan-center-index/pull/10333#issuecomment-1114110046
if self.version in ["1.7.6", "2.0.6"] and \
if self.version in ["1.7.6", "1.7.7", "2.0.6", "2.0.7"] and \
self.options.shared and \
microsoft.is_msvc(self) and \
"MD" in microsoft.msvc_runtime_flag(self):
is_msvc(self) and \
"MD" in msvc_runtime_flag(self):
raise ConanInvalidConfiguration(
"Currently, mimalloc/1.7.6,2.0.6 doesn't work properly with shared MD builds.")
f"Currently, {self.ref} doesn't work properly with shared MD builds in CCI. Contributions welcomed")

# Shared overriding requires dynamic runtime for MSVC:
if self.options.override and \
self.options.shared and \
microsoft.is_msvc(self) and \
"MT" in microsoft.msvc_runtime_flag(self):
if self.info.options.override and \
self.info.options.shared and \
is_msvc(self) and \
"MT" in msvc_runtime_flag(self):
raise ConanInvalidConfiguration(
"Dynamic runtime (MD/MDd) is required when using mimalloc as a shared library for override")

Expand All @@ -114,81 +109,80 @@ def validate(self):
self.options.get_safe("inject"):
raise ConanInvalidConfiguration("Single object is incompatible with library injection")

if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, "17")

minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)

if not minimum_version:
self.output.warn("mimalloc requires C++17. Your compiler is unknown. Assuming it supports C++17.")
elif tools.Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration("mimalloc requires a compiler that supports at least C++17")
if self.info.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)
check_min_vs(self, 191)
if not is_msvc(self):
minimum_version = self._compilers_minimum_version.get(str(self.info.settings.compiler), False)
if minimum_version and Version(self.info.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
if cmake.is_multi_configuration:
cmake.definitions["CMAKE_BUILD_TYPE"] = self.settings.build_type
cmake.definitions["MI_BUILD_TESTS"] = "OFF"
cmake.definitions["MI_BUILD_SHARED"] = self.options.shared
cmake.definitions["MI_BUILD_STATIC"] = not self.options.shared
cmake.definitions["MI_BUILD_OBJECT"] = self.options.get_safe("single_object", False)
cmake.definitions["MI_OVERRIDE"] = "ON" if self.options.override else "OFF"
cmake.definitions["MI_SECURE"] = "ON" if self.options.secure else "OFF"
if tools.Version(self.version) >= "1.7.0":
cmake.definitions["MI_INSTALL_TOPLEVEL"] = "ON"
cmake.configure(build_folder=self._build_subfolder)
return cmake
get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["MI_BUILD_TESTS"] = "OFF"
tc.variables["MI_BUILD_SHARED"] = self.options.shared
tc.variables["MI_BUILD_STATIC"] = not self.options.shared
tc.variables["MI_BUILD_OBJECT"] = self.options.get_safe("single_object", False)
tc.variables["MI_OVERRIDE"] = "ON" if self.options.override else "OFF"
tc.variables["MI_SECURE"] = "ON" if self.options.secure else "OFF"
if Version(self.version) >= "1.7.0":
tc.variables["MI_INSTALL_TOPLEVEL"] = "ON"
tc.generate()

if is_msvc(self):
vcvars = VCVars(self)
vcvars.generate()

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
if microsoft.is_msvc(self) and self.settings.arch == "x86":
tools.replace_path_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
"mimalloc-redirect.lib", "mimalloc-redirect32.lib")
with tools.vcvars(self.settings) if microsoft.is_msvc(self) else tools.no_op():
cmake = self._configure_cmake()
cmake.build()
apply_conandata_patches(self)
if is_msvc(self) and self.settings.arch == "x86":
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
"mimalloc-redirect.lib",
"mimalloc-redirect32.lib")
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
with tools.vcvars(self.settings) if microsoft.is_msvc(self) else tools.no_op():
cmake = self._configure_cmake()
cmake.install()
copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()

tools.rmdir(os.path.join(self.package_folder, "cmake"))
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))

if self.options.get_safe("single_object"):
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"),
"*.a")
rm(self, "*.a", os.path.join(self.package_folder, "lib"))
shutil.move(os.path.join(self.package_folder, self._obj_name + ".o"),
os.path.join(self.package_folder, "lib"))
shutil.copy(os.path.join(self.package_folder, "lib", self._obj_name + ".o"),
os.path.join(self.package_folder, "lib", self._obj_name))

if self.settings.os == "Windows" and self.options.shared:
if self.settings.arch == "x86_64":
self.copy("mimalloc-redirect.dll", src=os.path.join(self._source_subfolder, "bin"),
dst="bin")
copy(self, "mimalloc-redirect.dll",
src=os.path.join(self.source_folder, "bin"),
dst=os.path.join(self.package_folder, "bin"))
elif self.settings.arch == "x86":
self.copy("mimalloc-redirect32.dll", src=os.path.join(self._source_subfolder, "bin"),
dst="bin")
copy(self, "mimalloc-redirect32.dll",
src=os.path.join(self.source_folder, "bin"),
dst=os.path.join(self.package_folder, "bin"))

tools.rmdir(os.path.join(self.package_folder, "share"))
rmdir(self, os.path.join(self.package_folder, "share"))

cmake_target = "mimalloc" if self.options.shared else "mimalloc-static"
self._create_cmake_module_alias_targets(
os.path.join(self.package_folder, self._module_file_rel_path),
{cmake_target: "mimalloc::mimalloc"}
)

@staticmethod
def _create_cmake_module_alias_targets(module_file, targets):
def _create_cmake_module_alias_targets(self, module_file, targets):
content = ""
for alias, aliased in targets.items():
content += textwrap.dedent("""\
Expand All @@ -197,7 +191,7 @@ def _create_cmake_module_alias_targets(module_file, targets):
set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})
endif()
""".format(alias=alias, aliased=aliased))
tools.save(module_file, content)
save(self, module_file, content)

@property
def _module_subfolder(self):
Expand Down Expand Up @@ -254,7 +248,7 @@ def package_info(self):
self.cpp_info.libdirs = []
self.cpp_info.bindirs = []
else:
self.cpp_info.libs = tools.collect_libs(self)
self.cpp_info.libs = collect_libs(self)

if self.settings.os == "Linux":
self.cpp_info.system_libs.append("pthread")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b702300..d739857 100644
index 2bc0f76..f40e272 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -319,7 +319,7 @@ if(MI_BUILD_SHARED)
@@ -360,7 +360,7 @@ if(MI_BUILD_SHARED)
install(FILES "$<TARGET_FILE_DIR:mimalloc>/mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.dll" DESTINATION ${mi_install_libdir})
endif()

Expand All @@ -11,7 +11,7 @@ index b702300..d739857 100644
install(EXPORT mimalloc DESTINATION ${mi_install_cmakedir})
endif()

@@ -343,7 +343,7 @@ if (MI_BUILD_STATIC)
@@ -384,7 +384,7 @@ if (MI_BUILD_STATIC)
set_target_properties(mimalloc-static PROPERTIES OUTPUT_NAME ${mi_basename})
endif()

Expand Down
22 changes: 22 additions & 0 deletions recipes/mimalloc/all/patches/2.0.7-0001-change-install-paths.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2550f0d..da42112 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -360,7 +360,7 @@ if(MI_BUILD_SHARED)
install(FILES "$<TARGET_FILE_DIR:mimalloc>/mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.dll" DESTINATION ${mi_install_libdir})
endif()

- install(TARGETS mimalloc EXPORT mimalloc DESTINATION ${mi_install_libdir} LIBRARY)
+ install(TARGETS mimalloc EXPORT mimalloc RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
install(EXPORT mimalloc DESTINATION ${mi_install_cmakedir})
endif()

@@ -384,7 +384,7 @@ if (MI_BUILD_STATIC)
set_target_properties(mimalloc-static PROPERTIES OUTPUT_NAME ${mi_basename})
endif()

- install(TARGETS mimalloc-static EXPORT mimalloc DESTINATION ${mi_install_objdir} LIBRARY)
+ install(TARGETS mimalloc-static EXPORT mimalloc RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
install(EXPORT mimalloc DESTINATION ${mi_install_cmakedir})
endif()

Loading