-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mimalloc: Fix package error when single_object=True (#25250)
Co-authored-by: Uilian Ries <[email protected]> Co-authored-by: Abril Rincón Blanco <[email protected]>
- Loading branch information
1 parent
3ddb2da
commit e4c8f28
Showing
11 changed files
with
17 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 $<IF:$<TARGET_EXISTS:mimalloc>,mimalloc,mimalloc-static>) | ||
target_compile_features(${PROJECT_NAME} PRIVATE c_std_99) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,25 @@ | ||
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) | ||
|
||
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() | ||
cmake.build() | ||
|
||
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") |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.