From e4c8f2808ce1831a62685ce7f8957d871274f780 Mon Sep 17 00:00:00 2001 From: PerseoGI Date: Tue, 5 Nov 2024 10:57:35 +0100 Subject: [PATCH] mimalloc: Fix package error when single_object=True (#25250) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Uilian Ries Co-authored-by: Abril Rincón Blanco --- recipes/mimalloc/all/conanfile.py | 40 ++--------- .../mimalloc/all/test_package/CMakeLists.txt | 53 ++------------ .../mimalloc/all/test_package/conanfile.py | 57 ++------------- .../all/test_package/include_override.c | 11 --- .../all/test_package/include_override.cpp | 16 ----- recipes/mimalloc/all/test_package/mi_api.cpp | 13 ---- .../mimalloc/all/test_package/no_changes.c | 12 ---- .../mimalloc/all/test_package/no_changes.cpp | 8 --- .../test_package/{mi_api.c => test_package.c} | 4 +- .../all/test_v1_package/CMakeLists.txt | 10 --- .../mimalloc/all/test_v1_package/conanfile.py | 70 ------------------- 11 files changed, 17 insertions(+), 277 deletions(-) delete mode 100644 recipes/mimalloc/all/test_package/include_override.c delete mode 100644 recipes/mimalloc/all/test_package/include_override.cpp delete mode 100644 recipes/mimalloc/all/test_package/mi_api.cpp delete mode 100644 recipes/mimalloc/all/test_package/no_changes.c delete mode 100644 recipes/mimalloc/all/test_package/no_changes.cpp rename recipes/mimalloc/all/test_package/{mi_api.c => test_package.c} (69%) delete mode 100644 recipes/mimalloc/all/test_v1_package/CMakeLists.txt delete mode 100644 recipes/mimalloc/all/test_v1_package/conanfile.py diff --git a/recipes/mimalloc/all/conanfile.py b/recipes/mimalloc/all/conanfile.py index 881542551c915..1d36b7541ab29 100644 --- a/recipes/mimalloc/all/conanfile.py +++ b/recipes/mimalloc/all/conanfile.py @@ -1,15 +1,14 @@ from conan import ConanFile from conan.errors import ConanInvalidConfiguration from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout -from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir, replace_in_file, save, collect_libs +from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir, replace_in_file, collect_libs from conan.tools.microsoft import is_msvc, is_msvc_static_runtime, VCVars -from conan.tools.scm import Version from conan.tools.env import VirtualBuildEnv +from conan.tools.scm import Version import os import shutil -import textwrap -required_conan_version = ">=1.53.0" +required_conan_version = ">=2" class MimallocConan(ConanFile): @@ -75,7 +74,7 @@ def layout(self): def validate(self): # 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", "1.7.7", "2.0.6", "2.0.7"] and \ + if Version(self.version) == "1.7.6" and \ self.options.shared and \ is_msvc(self) and \ not is_msvc_static_runtime(self): @@ -110,8 +109,7 @@ def generate(self): tc.variables["MI_OVERRIDE"] = "ON" if self.options.override else "OFF" tc.variables["MI_SECURE"] = "ON" if self.options.secure else "OFF" tc.variables["MI_WIN_REDIRECT"] = "OFF" - if Version(self.version) >= "1.7.0": - tc.variables["MI_INSTALL_TOPLEVEL"] = "ON" + tc.variables["MI_INSTALL_TOPLEVEL"] = "ON" tc.generate() venv = VirtualBuildEnv(self) venv.generate(scope="build") @@ -141,8 +139,6 @@ def package(self): if self.options.get_safe("single_object"): 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)) @@ -158,27 +154,6 @@ def package(self): 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"} - ) - - def _create_cmake_module_alias_targets(self, module_file, targets): - content = "" - for alias, aliased in targets.items(): - content += textwrap.dedent(f"""\ - if(TARGET {aliased} AND NOT TARGET {alias}) - add_library({alias} INTERFACE IMPORTED) - set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased}) - endif() - """) - save(self, module_file, content) - - @property - def _module_file_rel_path(self): - return os.path.join("lib", "cmake", f"conan-official-{self.name}-targets.cmake") - @property def _obj_name(self): name = "mimalloc" @@ -204,11 +179,6 @@ def package_info(self): self.cpp_info.set_property("cmake_file_name", "mimalloc") self.cpp_info.set_property("cmake_target_name", "mimalloc" if self.options.shared else "mimalloc-static") - self.cpp_info.names["cmake_find_package"] = "mimalloc" - self.cpp_info.names["cmake_find_package_multi"] = "mimalloc" - self.cpp_info.build_modules["cmake_find_package"] = [self._module_file_rel_path] - self.cpp_info.build_modules["cmake_find_package_multi"] = [self._module_file_rel_path] - if self.options.get_safe("inject"): self.cpp_info.includedirs = [] self.cpp_info.libdirs = [] diff --git a/recipes/mimalloc/all/test_package/CMakeLists.txt b/recipes/mimalloc/all/test_package/CMakeLists.txt index cf60e66aa36cb..65c3184e9021a 100644 --- a/recipes/mimalloc/all/test_package/CMakeLists.txt +++ b/recipes/mimalloc/all/test_package/CMakeLists.txt @@ -1,51 +1,8 @@ -cmake_minimum_required(VERSION 3.8) -project(test_package LANGUAGES C CXX) - -enable_testing() - -option(BUILD_NO_CHANGES "Build no_changes sources" ON) -option(BUILD_INCLUDE_OVERRIDE "Build include_override sources" ON) -option(BUILD_MI_API "Build mi_api sources" ON) +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES C) find_package(mimalloc REQUIRED CONFIG) -if(TARGET mimalloc-static) - set(MIMALLOC_LIBS mimalloc-static) -else() - set(MIMALLOC_LIBS mimalloc) -endif() - -if(BUILD_NO_CHANGES) - add_executable(no_changes no_changes.c) - target_link_libraries(no_changes PRIVATE ${MIMALLOC_LIBS}) - target_compile_features(no_changes PRIVATE c_std_11) - add_test(NAME no_changes COMMAND no_changes) - - add_executable(no_changes_cpp no_changes.cpp) - target_link_libraries(no_changes_cpp PRIVATE ${MIMALLOC_LIBS}) - target_compile_features(no_changes_cpp PRIVATE cxx_std_17) - add_test(NAME no_changes_cpp COMMAND no_changes_cpp) -endif() - -if(BUILD_INCLUDE_OVERRIDE) - add_executable(include_override include_override.c) - target_link_libraries(include_override PRIVATE ${MIMALLOC_LIBS}) - target_compile_features(include_override PRIVATE c_std_11) - add_test(NAME include_override COMMAND include_override) - - add_executable(include_override_cpp include_override.cpp) - target_link_libraries(include_override_cpp PRIVATE ${MIMALLOC_LIBS}) - target_compile_features(include_override_cpp PRIVATE cxx_std_17) - add_test(NAME include_override_cpp COMMAND include_override_cpp) -endif() - -if(BUILD_MI_API) - add_executable(mi_api mi_api.c) - target_link_libraries(mi_api PRIVATE ${MIMALLOC_LIBS}) - target_compile_features(mi_api PRIVATE c_std_11) - add_test(NAME mi_api COMMAND mi_api) - add_executable(mi_api_cpp mi_api.cpp) - target_link_libraries(mi_api_cpp PRIVATE ${MIMALLOC_LIBS}) - target_compile_features(mi_api_cpp PRIVATE cxx_std_17) - add_test(NAME mi_api_cpp COMMAND mi_api_cpp) -endif() +add_executable(${PROJECT_NAME} test_package.c) +target_link_libraries(${PROJECT_NAME} PRIVATE $,mimalloc,mimalloc-static>) +target_compile_features(${PROJECT_NAME} PRIVATE c_std_99) diff --git a/recipes/mimalloc/all/test_package/conanfile.py b/recipes/mimalloc/all/test_package/conanfile.py index 73d57fff7f138..81b2d147a96f2 100644 --- a/recipes/mimalloc/all/test_package/conanfile.py +++ b/recipes/mimalloc/all/test_package/conanfile.py @@ -1,16 +1,12 @@ from conan import ConanFile -from conan.tools.build import build_jobs, can_run -from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout -from conan.tools.env import Environment -from conan.tools.files import chdir +from conan.tools.build import can_run +from conan.tools.cmake import CMake, cmake_layout import os -import functools class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "CMakeDeps", "VirtualRunEnv" - test_type = "explicit" + generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" def layout(self): cmake_layout(self) @@ -18,49 +14,6 @@ def layout(self): def requirements(self): self.requires(self.tested_reference_str) - @functools.lru_cache(1) - def _test_files(self): - # No override: - if not self.dependencies["mimalloc"].options.override: - return ["mi_api"] - # Injected override - elif self.dependencies["mimalloc"].options.get_safe("inject"): - if self.settings.os == "Macos": - # Could not simulate Macos preload, so just ignore it - return [] - return ["no_changes"] - # Non injected override - return ["include_override", "mi_api"] - - @property - def _lib_name(self): - name = "mimalloc" if self.settings.os == "Windows" else "libmimalloc" - if self.settings.os == "Windows" and not self.dependencies["mimalloc"].options.shared: - name += "-static" - if self.dependencies["mimalloc"].options.secure: - name += "-secure" - if self.settings.build_type not in ("Release", "RelWithDebInfo", "MinSizeRel"): - name += f"-{str(self.settings.build_type).lower()}" - return name - - def generate(self): - tc = CMakeToolchain(self) - tc.variables["BUILD_NO_CHANGES"] = "no_changes" in self._test_files() - tc.variables["BUILD_INCLUDE_OVERRIDE"] = "include_override" in self._test_files() - tc.variables["BUILD_MI_API"] = "mi_api" in self._test_files() - tc.generate() - - env = Environment() - env.define("MIMALLOC_VERBOSE", "1") - if self.dependencies["mimalloc"].options.get_safe("inject"): - if self.settings.os == "Linux": - env.define("LD_PRELOAD", f"{self._lib_name}.so") - elif self.settings.os == "Macos": - env.define("DYLD_FORCE_FLAT_NAMESPACE", "1") - insert_library = os.path.join(self.dependencies["mimalloc"].cpp_info.libdirs[0], f"{self._lib_name}.dylib") - env.define("DYLD_INSERT_LIBRARIES", insert_library) - env.vars(self, scope="run").save_script("mimalloc_env_file") - def build(self): cmake = CMake(self) cmake.configure() @@ -68,5 +21,5 @@ def build(self): def test(self): if can_run(self): - with chdir(self, self.build_folder): - self.run(f"ctest --output-on-failure -C {self.settings.build_type} -j {build_jobs(self)}", env="conanrun") + bin_path = os.path.join(self.cpp.build.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/mimalloc/all/test_package/include_override.c b/recipes/mimalloc/all/test_package/include_override.c deleted file mode 100644 index 5e54990b98f79..0000000000000 --- a/recipes/mimalloc/all/test_package/include_override.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "mimalloc-override.h" - -#include - -int main() { - void *data = malloc(1024); - free(data); - - printf("mimalloc version %d\n", mi_version()); - return 0; -} diff --git a/recipes/mimalloc/all/test_package/include_override.cpp b/recipes/mimalloc/all/test_package/include_override.cpp deleted file mode 100644 index edcb49e3434ee..0000000000000 --- a/recipes/mimalloc/all/test_package/include_override.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#ifdef _WIN32 -#include -#else -#include -#endif - -#include -#include - -int main() { - auto *data = new int(1024); - delete data; - - std::cout << "mimalloc version " << mi_version() << "\n"; - return 0; -} diff --git a/recipes/mimalloc/all/test_package/mi_api.cpp b/recipes/mimalloc/all/test_package/mi_api.cpp deleted file mode 100644 index a361ab757bf42..0000000000000 --- a/recipes/mimalloc/all/test_package/mi_api.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "mimalloc.h" - -#include -#include - -int main() { - std::vector> vec; - vec.push_back(1); - vec.pop_back(); - - std::cout << "mimalloc version " << mi_version() << "\n"; - return 0; -} diff --git a/recipes/mimalloc/all/test_package/no_changes.c b/recipes/mimalloc/all/test_package/no_changes.c deleted file mode 100644 index 51737c1ac50f0..0000000000000 --- a/recipes/mimalloc/all/test_package/no_changes.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int main() { - void *data = malloc(1024); - - memset(data, '6', 1024); - - free(data); - - return 0; -} diff --git a/recipes/mimalloc/all/test_package/no_changes.cpp b/recipes/mimalloc/all/test_package/no_changes.cpp deleted file mode 100644 index 7a5ad3df0f22c..0000000000000 --- a/recipes/mimalloc/all/test_package/no_changes.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include - -int main() { - auto *data = new int(1024); - delete data; - - return 0; -} diff --git a/recipes/mimalloc/all/test_package/mi_api.c b/recipes/mimalloc/all/test_package/test_package.c similarity index 69% rename from recipes/mimalloc/all/test_package/mi_api.c rename to recipes/mimalloc/all/test_package/test_package.c index 804f582034b95..f73b12d64f5d5 100644 --- a/recipes/mimalloc/all/test_package/mi_api.c +++ b/recipes/mimalloc/all/test_package/test_package.c @@ -4,8 +4,8 @@ #include int main() { - void *data = mi_malloc(1024); + void *data = mi_malloc(32); printf("mimalloc version %d\n", mi_version()); - return 0; + return EXIT_SUCCESS; } diff --git a/recipes/mimalloc/all/test_v1_package/CMakeLists.txt b/recipes/mimalloc/all/test_v1_package/CMakeLists.txt deleted file mode 100644 index 3f3fae06afa0a..0000000000000 --- a/recipes/mimalloc/all/test_v1_package/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -cmake_minimum_required(VERSION 3.8) -project(test_v1_package) - -enable_testing() - -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) - -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ - ${CMAKE_CURRENT_BINARY_DIR}/test_package/) diff --git a/recipes/mimalloc/all/test_v1_package/conanfile.py b/recipes/mimalloc/all/test_v1_package/conanfile.py deleted file mode 100644 index 7f8fb52960e7a..0000000000000 --- a/recipes/mimalloc/all/test_v1_package/conanfile.py +++ /dev/null @@ -1,70 +0,0 @@ -from conans import ConanFile, CMake, RunEnvironment, tools -from conans.errors import ConanException -import os -import functools - - -class TestPackageConan(ConanFile): - settings = "os", "arch", "compiler", "build_type" - generators = "cmake", "cmake_find_package_multi" - - def _mimalloc_option(self, name, default=None): - try: - return getattr(self.options["mimalloc"], name, default) - except (AttributeError, ConanException): - return default - - @functools.lru_cache(1) - def _test_files(self): - # No override: - if not self.options["mimalloc"].override: - return ["mi_api"] - # Injected override: - elif self._mimalloc_option("inject"): - if self.settings.os == "Macos": - # Could not simulate Macos preload, so just ignore it - return [] - return ["no_changes"] - # Non injected override: - return ["include_override", "mi_api"] - - def build(self): - cmake = CMake(self) - cmake.definitions["BUILD_NO_CHANGES"] = "no_changes" in self._test_files() - cmake.definitions["BUILD_INCLUDE_OVERRIDE"] = "include_override" in self._test_files() - cmake.definitions["BUILD_MI_API"] = "mi_api" in self._test_files() - cmake.configure() - cmake.build() - - @property - def _lib_name(self): - name = "mimalloc" if self.settings.os == "Windows" else "libmimalloc" - if self.settings.os == "Windows" and not self.options["mimalloc"].shared: - name += "-static" - if self.options["mimalloc"].secure: - name += "-secure" - if self.settings.build_type not in ("Release", "RelWithDebInfo", "MinSizeRel"): - name += f"-{str(self.settings.build_type).lower()}" - return name - - @property - def _environment(self): - environment = {"MIMALLOC_VERBOSE": "1"} - - if self._mimalloc_option("inject"): - if self.settings.os == "Linux": - environment["LD_PRELOAD"] = f"{self._lib_name}.so" - elif self.settings.os == "Macos": - env_build = RunEnvironment(self) - insert_library = os.path.join(env_build.vars["DYLD_LIBRARY_PATH"][0], f"{self._lib_name}.dylib") - - environment["DYLD_FORCE_FLAT_NAMESPACE"] = "1" - environment["DYLD_INSERT_LIBRARIES"] = insert_library - - return environment - - def test(self): - if tools.cross_building(self): - return - with tools.environment_append(self._environment): - self.run(f"ctest --output-on-failure -C {self.settings.build_type} -j {tools.cpu_count()}", run_environment=True)