diff options
Diffstat (limited to 'vcpkg/scripts/test_ports/vcpkg-ci-mimalloc')
4 files changed, 172 insertions, 0 deletions
diff --git a/vcpkg/scripts/test_ports/vcpkg-ci-mimalloc/build-type.diff b/vcpkg/scripts/test_ports/vcpkg-ci-mimalloc/build-type.diff new file mode 100644 index 0000000..7886576 --- /dev/null +++ b/vcpkg/scripts/test_ports/vcpkg-ci-mimalloc/build-type.diff @@ -0,0 +1,40 @@ +diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt +index c5fff1a..03a86ca 100644 +--- a/test/CMakeLists.txt ++++ b/test/CMakeLists.txt +@@ -20,6 +20,7 @@ find_package(mimalloc 2.2 CONFIG REQUIRED) + message(STATUS "Found mimalloc installed at: ${MIMALLOC_LIBRARY_DIR} (${MIMALLOC_VERSION_DIR})") + + ++if(BUILD_SHARED_LIBS) + # link with a dynamic shared library + # use `LD_PRELOAD` to actually override malloc/free at runtime with mimalloc + add_executable(dynamic-override main-override.c) +@@ -27,15 +28,19 @@ target_link_libraries(dynamic-override PUBLIC mimalloc) + + add_executable(dynamic-override-cxx main-override.cpp) + target_link_libraries(dynamic-override-cxx PUBLIC mimalloc) ++endif() + + ++if(0) + # overriding with a static object file works reliable as the symbols in the + # object file have priority over those in library files + add_executable(static-override-obj main-override.c ${MIMALLOC_OBJECT_DIR}/mimalloc${CMAKE_C_OUTPUT_EXTENSION}) + target_include_directories(static-override-obj PUBLIC ${MIMALLOC_INCLUDE_DIR}) + target_link_libraries(static-override-obj PUBLIC mimalloc-static) ++endif() + + ++if(NOT BUILD_SHARED_LIBS AND NOT WIN32) + # overriding with a static library works too if using the `mimalloc-override.h` + # header to redefine malloc/free. (the library already overrides new/delete) + add_executable(static-override-static main-override-static.c) +@@ -49,6 +54,7 @@ target_link_libraries(static-override PUBLIC mimalloc-static) + + add_executable(static-override-cxx main-override.cpp) + target_link_libraries(static-override-cxx PUBLIC mimalloc-static) ++endif() + + + ## test memory errors diff --git a/vcpkg/scripts/test_ports/vcpkg-ci-mimalloc/portfile.cmake b/vcpkg/scripts/test_ports/vcpkg-ci-mimalloc/portfile.cmake new file mode 100644 index 0000000..8a46d4c --- /dev/null +++ b/vcpkg/scripts/test_ports/vcpkg-ci-mimalloc/portfile.cmake @@ -0,0 +1,40 @@ +set(VCPKG_POLICY_EMPTY_PACKAGE enabled) + +vcpkg_find_acquire_program(PKGCONFIG) + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO microsoft/mimalloc + REF "v${VERSION}" + SHA512 55262050f63868e3029cd929a74d312dc0f34b606534b1d0b3735eecc8eed68aae97523a50228b4ac4044e1e03192f2909440e3a27607e2d364607ac0bda828f + HEAD_REF master + PATCHES + build-type.diff +) +# Ensure that the test uses the installed mimalloc only +file(REMOVE_RECURSE + "${SOURCE_PATH}/bin" + "${SOURCE_PATH}/include" + "${SOURCE_PATH}/src" +) + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}/test" + OPTIONS + "-DCMAKE_PROJECT_INCLUDE=${CURRENT_PORT_DIR}/vcpkg-tests.cmake" + "-DPKG_CONFIG_EXECUTABLE=${PKGCONFIG}" +) + +set(ENV{MIMALLOC_VERBOSE} 1) +set(ENV{MIMALLOC_SHOW_ERRORS} 1) +set(ENV{MIMALLOC_DISABLE_REDIRECT} 1) + +vcpkg_cmake_install(ADD_BIN_TO_PATH) + +if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic" OR NOT VCPKG_TARGET_IS_WINDOWS) + vcpkg_copy_tools(TOOL_NAMES pkgconfig-override-cxx AUTO_CLEAN) +endif() + +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug") + +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") diff --git a/vcpkg/scripts/test_ports/vcpkg-ci-mimalloc/vcpkg-tests.cmake b/vcpkg/scripts/test_ports/vcpkg-ci-mimalloc/vcpkg-tests.cmake new file mode 100644 index 0000000..659cb7d --- /dev/null +++ b/vcpkg/scripts/test_ports/vcpkg-ci-mimalloc/vcpkg-tests.cmake @@ -0,0 +1,59 @@ +macro(deferred_tests) + +find_package(PkgConfig REQUIRED) + +# Legacy variables + +message(STATUS "MIMALLOC_INCLUDE_DIR: ${MIMALLOC_INCLUDE_DIR}") +message(STATUS "MIMALLOC_LIBRARY_DIR: ${MIMALLOC_LIBRARY_DIR}") +find_file(mimalloc_h NAMES mimalloc.h PATHS "${MIMALLOC_INCLUDE_DIR}" NO_DEFAULT_PATH REQUIRED) +set(names + mimalloc + mimalloc-secure + mimalloc-static + mimalloc-static-secure + mimalloc-debug + mimalloc-secure-debug + mimalloc-static-debug + mimalloc-static-secure-debug +) +find_library(mimalloc_lib NAMES ${names} PATHS "${MIMALLOC_LIBRARY_DIR}" NO_DEFAULT_PATH REQUIRED) + +# pkgconfig + +pkg_check_modules(PC_MIMALLOC mimalloc IMPORTED_TARGET REQUIRED) + +add_executable(pkgconfig-override $<IF:$<BOOL:${BUILD_SHARED_LIBS}>,main-override.c,main-override-static.c>) +target_link_libraries(pkgconfig-override PRIVATE PkgConfig::PC_MIMALLOC) + +if(BUILD_SHARED_LIBS OR NOT WIN32) + add_executable(pkgconfig-override-cxx main-override.cpp) + target_link_libraries(pkgconfig-override-cxx PRIVATE PkgConfig::PC_MIMALLOC) +endif() + +# Runtime + +if(NOT CMAKE_CROSSCOMPILING) + if(BUILD_SHARED_LIBS) + add_custom_target(run-dynamic-override ALL COMMAND $<TARGET_NAME:dynamic-override>) + add_custom_target(run-dynamic-override-cxx ALL COMMAND $<TARGET_NAME:dynamic-override-cxx>) + elseif(NOT WIN32) + add_custom_target(run-static-override ALL COMMAND $<TARGET_NAME:static-override>) + add_custom_target(run-static-override-cxx ALL COMMAND $<TARGET_NAME:static-override-cxx>) + endif() + if(TARGET pkgconfig-override-cxx) + add_custom_target(run-pkgconfig-override-cxx ALL COMMAND $<TARGET_NAME:pkgconfig-override-cxx>) + endif() +endif() + +# Deployment + +if(TARGET pkgconfig-override-cxx) + install(TARGETS pkgconfig-override-cxx) +else() + install(CODE [[ # placeholder # ]]) +endif() + +endmacro() + +cmake_language(DEFER CALL deferred_tests) diff --git a/vcpkg/scripts/test_ports/vcpkg-ci-mimalloc/vcpkg.json b/vcpkg/scripts/test_ports/vcpkg-ci-mimalloc/vcpkg.json new file mode 100644 index 0000000..9c453dd --- /dev/null +++ b/vcpkg/scripts/test_ports/vcpkg-ci-mimalloc/vcpkg.json @@ -0,0 +1,33 @@ +{ + "name": "vcpkg-ci-mimalloc", + "version": "2.2.3", + "description": "Validates mimalloc", + "dependencies": [ + "mimalloc", + { + "name": "vcpkg-cmake", + "host": true + } + ], + "features": { + "ci": { + "description": "Test feature permutation", + "dependencies": [ + { + "name": "mimalloc", + "features": [ + "override" + ], + "platform": "native & !(windows & static)" + }, + { + "name": "mimalloc", + "features": [ + "secure" + ], + "platform": "arm64 & static" + } + ] + } + } +} |