diff options
| author | Ethan Morgan <ethan@gweithio.com> | 2026-02-14 16:44:06 +0000 |
|---|---|---|
| committer | Ethan Morgan <ethan@gweithio.com> | 2026-02-14 16:44:06 +0000 |
| commit | 54409423f767d8b1cf30cb7d0efca6b4ca138823 (patch) | |
| tree | d915ac7828703ce4b963efdd9728a1777ba18c1e /vcpkg/ports/mimalloc | |
Diffstat (limited to 'vcpkg/ports/mimalloc')
| -rw-r--r-- | vcpkg/ports/mimalloc/pkgconfig-cxx.diff | 19 | ||||
| -rw-r--r-- | vcpkg/ports/mimalloc/portfile.cmake | 58 | ||||
| -rw-r--r-- | vcpkg/ports/mimalloc/usage | 9 | ||||
| -rw-r--r-- | vcpkg/ports/mimalloc/vcpkg-cmake-wrapper.cmake | 21 | ||||
| -rw-r--r-- | vcpkg/ports/mimalloc/vcpkg.json | 28 |
5 files changed, 135 insertions, 0 deletions
diff --git a/vcpkg/ports/mimalloc/pkgconfig-cxx.diff b/vcpkg/ports/mimalloc/pkgconfig-cxx.diff new file mode 100644 index 0000000..52c0ac3 --- /dev/null +++ b/vcpkg/ports/mimalloc/pkgconfig-cxx.diff @@ -0,0 +1,19 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 5cc7ec5..578d235 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -680,8 +680,13 @@ endif() + + + # pkg-config file support ++set(mi_cxx_libraries "") ++if(MI_USE_CXX) ++ set(mi_cxx_libraries ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES}) ++ list(REMOVE_ITEM mi_cxx_libraries ${CMAKE_C_IMPLICIT_LINK_LIBRARIES}) ++endif() + set(mi_pc_libraries "") +-foreach(item IN LISTS mi_libraries) ++foreach(item IN LISTS mi_libraries mi_cxx_libraries) + if(item MATCHES " *[-].*") + set(mi_pc_libraries "${mi_pc_libraries} ${item}") + else() diff --git a/vcpkg/ports/mimalloc/portfile.cmake b/vcpkg/ports/mimalloc/portfile.cmake new file mode 100644 index 0000000..963ca6c --- /dev/null +++ b/vcpkg/ports/mimalloc/portfile.cmake @@ -0,0 +1,58 @@ +vcpkg_from_github(
+ OUT_SOURCE_PATH SOURCE_PATH
+ REPO microsoft/mimalloc
+ REF "v${VERSION}"
+ SHA512 55262050f63868e3029cd929a74d312dc0f34b606534b1d0b3735eecc8eed68aae97523a50228b4ac4044e1e03192f2909440e3a27607e2d364607ac0bda828f
+ HEAD_REF master
+ PATCHES
+ pkgconfig-cxx.diff
+)
+
+vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
+ FEATURES
+ override MI_OVERRIDE
+ secure MI_SECURE
+)
+string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" MI_BUILD_STATIC)
+string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" MI_BUILD_SHARED)
+
+vcpkg_cmake_configure(
+ SOURCE_PATH "${SOURCE_PATH}"
+ OPTIONS
+ ${FEATURE_OPTIONS}
+ -DMI_USE_CXX=ON
+ -DMI_BUILD_OBJECT=OFF
+ -DMI_BUILD_TESTS=OFF
+ -DMI_BUILD_STATIC=${MI_BUILD_STATIC}
+ -DMI_BUILD_SHARED=${MI_BUILD_SHARED}
+ -DMI_INSTALL_TOPLEVEL=ON
+ OPTIONS_DEBUG
+ -DMI_DEBUG_FULL=ON
+ OPTIONS_RELEASE
+ -DMI_DEBUG_FULL=OFF
+)
+
+vcpkg_cmake_install()
+
+vcpkg_copy_pdbs()
+
+file(COPY
+ "${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake"
+ "${CMAKE_CURRENT_LIST_DIR}/usage"
+ DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}"
+)
+vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/mimalloc)
+
+if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
+ vcpkg_replace_string(
+ "${CURRENT_PACKAGES_DIR}/include/mimalloc.h"
+ "!defined(MI_SHARED_LIB)"
+ "0 // !defined(MI_SHARED_LIB)"
+ )
+endif()
+file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
+file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
+
+vcpkg_fixup_pkgconfig()
+
+vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
diff --git a/vcpkg/ports/mimalloc/usage b/vcpkg/ports/mimalloc/usage new file mode 100644 index 0000000..df1eac2 --- /dev/null +++ b/vcpkg/ports/mimalloc/usage @@ -0,0 +1,9 @@ +mimalloc provides CMake targets: + + find_package(mimalloc CONFIG REQUIRED) + target_link_libraries(main PRIVATE $<IF:$<TARGET_EXISTS:mimalloc-static>,mimalloc-static,mimalloc>) + +To ensure the mimalloc-override.dll is loaded at runtime on Windows with +dynamic linkage, it is suggested to insert some call to the mimalloc API +in the main function, eg. `mi_version()`. Cf. +https://github.com/microsoft/mimalloc/blob/dev/readme.md#dynamic-override-on-windows diff --git a/vcpkg/ports/mimalloc/vcpkg-cmake-wrapper.cmake b/vcpkg/ports/mimalloc/vcpkg-cmake-wrapper.cmake new file mode 100644 index 0000000..15ad847 --- /dev/null +++ b/vcpkg/ports/mimalloc/vcpkg-cmake-wrapper.cmake @@ -0,0 +1,21 @@ +_find_package(${ARGS})
+
+if(CMAKE_CURRENT_LIST_DIR STREQUAL "${MIMALLOC_CMAKE_DIR}/${MIMALLOC_VERSION_DIR}")
+ set(MIMALLOC_INCLUDE_DIR "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include")
+ # As in vcpkg.cmake
+ if(NOT DEFINED CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE MATCHES "^[Dd][Ee][Bb][Uu][Gg]$")
+ set(MIMALLOC_LIBRARY_DIR "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/lib")
+ else()
+ set(MIMALLOC_LIBRARY_DIR "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib")
+ endif()
+ set(MIMALLOC_OBJECT_DIR "MIMALLOC_OBJECT_DIR-NOTFOUND") # not installed
+ set(MIMALLOC_TARGET_DIR "${MIMALLOC_LIBRARY_DIR}")
+endif()
+
+if(TARGET mimalloc AND NOT TARGET mimalloc-static)
+ add_library(mimalloc-static INTERFACE IMPORTED)
+ set_target_properties(mimalloc-static PROPERTIES INTERFACE_LINK_LIBRARIES mimalloc)
+elseif(TARGET mimalloc-static AND NOT TARGET mimalloc)
+ add_library(mimalloc INTERFACE IMPORTED)
+ set_target_properties(mimalloc PROPERTIES INTERFACE_LINK_LIBRARIES mimalloc-static)
+endif()
diff --git a/vcpkg/ports/mimalloc/vcpkg.json b/vcpkg/ports/mimalloc/vcpkg.json new file mode 100644 index 0000000..c93fcb1 --- /dev/null +++ b/vcpkg/ports/mimalloc/vcpkg.json @@ -0,0 +1,28 @@ +{ + "name": "mimalloc", + "version": "2.2.3", + "port-version": 1, + "description": "Compact general purpose allocator with excellent performance", + "homepage": "https://github.com/microsoft/mimalloc", + "license": "MIT", + "supports": "!uwp", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ], + "features": { + "override": { + "description": "Override the standard malloc interface (i.e. define entry points for 'malloc', 'free', etc)", + "supports": "!windows | !static" + }, + "secure": { + "description": "Use full security mitigations (like guard pages, allocation randomization, double-free mitigation, and free-list corruption detection)" + } + } +} |