-
-
Notifications
You must be signed in to change notification settings - Fork 16
mimalloc integration #2708
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
base: main
Are you sure you want to change the base?
mimalloc integration #2708
Changes from all commits
66cfe1d
0af17b8
c8a686c
5976b67
d80acb0
3a4b251
f463ad2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| /vendor/** linguist-generated=true | ||
| vendor/*.mask text eol=lf | ||
| *.sh text eol=lf | ||
| test/test/*.txt text eol=lf | ||
|
|
||
| # These fixtures are parser input, so their bytes, including their line | ||
| # endings, must reach the working directory exactly as committed on every | ||
| # platform | ||
| /test/json/stub_*.json -text | ||
| /test/yaml/stubs/** -text | ||
| /test/yaml/stubs/** -text |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,3 +12,5 @@ _deps | |
| Brewfile.lock.json | ||
| .DS_Store | ||
| .cache | ||
| out/ | ||
| CMakeSettings.json | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| if(NOT Mimalloc_FOUND) | ||
| set(MIMALLOC_DIR "${PROJECT_SOURCE_DIR}/vendor/mimalloc") | ||
|
|
||
| set(MI_INSTALL_TOPLEVEL ON CACHE BOOL "" FORCE) | ||
| set(MI_BUILD_SHARED ${BUILD_SHARED_LIBS} CACHE BOOL "" FORCE) | ||
| if(BUILD_SHARED_LIBS) | ||
| set(MI_BUILD_STATIC OFF CACHE BOOL "" FORCE) | ||
| set(MIMALLOC_TARGET mimalloc) | ||
| else() | ||
| set(MI_BUILD_STATIC ON CACHE BOOL "" FORCE) | ||
| set(MIMALLOC_TARGET mimalloc-static) | ||
| endif() | ||
| set(MI_BUILD_OBJECT OFF CACHE BOOL "" FORCE) | ||
| set(MI_BUILD_TESTS OFF CACHE BOOL "" FORCE) | ||
| set(MI_OVERRIDE ON CACHE BOOL "" FORCE) | ||
|
|
||
| set(SOURCEMETA_CORE_MIMALLOC_SKIP_INSTALL "${MI_SKIP_INSTALL}") | ||
| set(MI_SKIP_INSTALL ON) | ||
| add_subdirectory( | ||
| "${MIMALLOC_DIR}" | ||
| "${CMAKE_CURRENT_BINARY_DIR}/mimalloc" EXCLUDE_FROM_ALL) | ||
| set(MI_SKIP_INSTALL "${SOURCEMETA_CORE_MIMALLOC_SKIP_INSTALL}") | ||
| unset(SOURCEMETA_CORE_MIMALLOC_SKIP_INSTALL) | ||
|
|
||
| if(TARGET ${MIMALLOC_TARGET}) | ||
| set_target_properties(${MIMALLOC_TARGET} | ||
| PROPERTIES COMPILE_WARNING_AS_ERROR OFF) | ||
| set(Mimalloc_FOUND ON) | ||
|
|
||
| if(SOURCEMETA_CORE_INSTALL) | ||
| include(GNUInstallDirs) | ||
| if(BUILD_SHARED_LIBS) | ||
| install(TARGETS ${MIMALLOC_TARGET} | ||
| EXPORT mimalloc | ||
| RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" | ||
| COMPONENT sourcemeta_core | ||
| LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
| COMPONENT sourcemeta_core | ||
| NAMELINK_COMPONENT sourcemeta_core_dev | ||
| ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
| COMPONENT sourcemeta_core_dev) | ||
| else() | ||
| install(TARGETS ${MIMALLOC_TARGET} | ||
| EXPORT mimalloc | ||
| ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
| COMPONENT sourcemeta_core_dev) | ||
| endif() | ||
| install(EXPORT mimalloc | ||
| FILE mimalloc.cmake | ||
| DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/mimalloc" | ||
| COMPONENT sourcemeta_core_dev) | ||
| install(FILES | ||
| "${MIMALLOC_DIR}/include/mimalloc.h" | ||
| "${MIMALLOC_DIR}/include/mimalloc-new-delete.h" | ||
| "${MIMALLOC_DIR}/include/mimalloc-override.h" | ||
| "${MIMALLOC_DIR}/include/mimalloc-stats.h" | ||
| DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" | ||
| COMPONENT sourcemeta_core_dev) | ||
| install(FILES | ||
| "${MIMALLOC_DIR}/cmake/mimalloc-config.cmake" | ||
| "${MIMALLOC_DIR}/cmake/mimalloc-config-version.cmake" | ||
| DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/mimalloc" | ||
| COMPONENT sourcemeta_core_dev) | ||
| endif() | ||
| endif() | ||
| endif() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
| index 3189dec42426f4f3cbd88f54e72f8c5eb557073a..f76757cd3ae68624c2dbf1c6ad882bcae6c7bc15 100644 | ||
| --- a/CMakeLists.txt | ||
| +++ b/CMakeLists.txt | ||
| @@ -705,14 +705,18 @@ if(MI_BUILD_SHARED) | ||
| $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
| $<INSTALL_INTERFACE:${mi_install_incdir}> | ||
| ) | ||
| - install(TARGETS mimalloc EXPORT mimalloc ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) | ||
| - install(EXPORT mimalloc DESTINATION ${mi_install_cmakedir}) | ||
| + if(NOT MI_SKIP_INSTALL) | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| + install(TARGETS mimalloc EXPORT mimalloc ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) | ||
| + install(EXPORT mimalloc DESTINATION ${mi_install_cmakedir}) | ||
| + endif() | ||
|
|
||
| if(WIN32 AND NOT MINGW) | ||
| # On windows, the import library name for the dll would clash with the static mimalloc.lib library | ||
| # so we postfix the dll import library with `.dll.lib` (and also the .pdb debug file) | ||
| set_property(TARGET mimalloc PROPERTY ARCHIVE_OUTPUT_NAME "${mi_libname}.dll" ) | ||
| - install(FILES "$<TARGET_FILE_DIR:mimalloc>/${mi_libname}.dll.lib" DESTINATION ${CMAKE_INSTALL_LIBDIR}/mimalloc-${mi_version}) | ||
| + if(NOT MI_SKIP_INSTALL) | ||
| + install(FILES "$<TARGET_FILE_DIR:mimalloc>/${mi_libname}.dll.lib" DESTINATION ${CMAKE_INSTALL_LIBDIR}/mimalloc-${mi_version}) | ||
| + endif() | ||
| set_property(TARGET mimalloc PROPERTY PDB_NAME "${mi_libname}.dll") | ||
| # don't try to install the pdb since it may not be generated depending on the configuration | ||
| # install(FILES "$<TARGET_FILE_DIR:mimalloc>/${mi_libname}.dll.pdb" DESTINATION ${CMAKE_INSTALL_LIBDIR}) | ||
| @@ -740,7 +744,9 @@ if(MI_BUILD_SHARED) | ||
| add_custom_command(TARGET mimalloc POST_BUILD | ||
| COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/bin/mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.dll" $<TARGET_FILE_DIR:mimalloc> | ||
| COMMENT "Copy mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.dll to output directory") | ||
| - install(FILES "$<TARGET_FILE_DIR:mimalloc>/mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.dll" DESTINATION ${CMAKE_INSTALL_BINDIR}) | ||
| + if(NOT MI_SKIP_INSTALL) | ||
| + install(FILES "$<TARGET_FILE_DIR:mimalloc>/mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.dll" DESTINATION ${CMAKE_INSTALL_BINDIR}) | ||
| + endif() | ||
| endif() | ||
| endif() | ||
|
|
||
| @@ -757,17 +763,21 @@ if (MI_BUILD_STATIC) | ||
| $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
| $<INSTALL_INTERFACE:${mi_install_incdir}> | ||
| ) | ||
| - install(TARGETS mimalloc-static EXPORT mimalloc DESTINATION ${mi_install_objdir} LIBRARY) | ||
| - install(EXPORT mimalloc DESTINATION ${mi_install_cmakedir}) | ||
| + if(NOT MI_SKIP_INSTALL) | ||
| + install(TARGETS mimalloc-static EXPORT mimalloc DESTINATION ${mi_install_objdir} LIBRARY) | ||
| + install(EXPORT mimalloc DESTINATION ${mi_install_cmakedir}) | ||
| + endif() | ||
| endif() | ||
|
|
||
| -# install include files | ||
| -install(FILES include/mimalloc.h DESTINATION ${mi_install_incdir}) | ||
| -install(FILES include/mimalloc-override.h DESTINATION ${mi_install_incdir}) | ||
| -install(FILES include/mimalloc-new-delete.h DESTINATION ${mi_install_incdir}) | ||
| -install(FILES include/mimalloc-stats.h DESTINATION ${mi_install_incdir}) | ||
| -install(FILES cmake/mimalloc-config.cmake DESTINATION ${mi_install_cmakedir}) | ||
| -install(FILES cmake/mimalloc-config-version.cmake DESTINATION ${mi_install_cmakedir}) | ||
| +if(NOT MI_SKIP_INSTALL) | ||
| + # install include files | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| + install(FILES include/mimalloc.h DESTINATION ${mi_install_incdir}) | ||
| + install(FILES include/mimalloc-override.h DESTINATION ${mi_install_incdir}) | ||
| + install(FILES include/mimalloc-new-delete.h DESTINATION ${mi_install_incdir}) | ||
| + install(FILES include/mimalloc-stats.h DESTINATION ${mi_install_incdir}) | ||
| + install(FILES cmake/mimalloc-config.cmake DESTINATION ${mi_install_cmakedir}) | ||
| + install(FILES cmake/mimalloc-config-version.cmake DESTINATION ${mi_install_cmakedir}) | ||
| +endif() | ||
|
|
||
|
|
||
| # single object file for more predictable static overriding | ||
| @@ -798,9 +808,11 @@ if (MI_BUILD_OBJECT) | ||
|
|
||
| # the FILES expression can also be: $<TARGET_OBJECTS:mimalloc-obj> | ||
| # but that fails cmake versions less than 3.10 so we leave it as is for now | ||
| - install(FILES ${mimalloc-obj-static} | ||
| - DESTINATION ${mi_install_objdir} | ||
| - RENAME ${mi_libname}${CMAKE_C_OUTPUT_EXTENSION} ) | ||
| + if(NOT MI_SKIP_INSTALL) | ||
| + install(FILES ${mimalloc-obj-static} | ||
| + DESTINATION ${mi_install_objdir} | ||
| + RENAME ${mi_libname}${CMAKE_C_OUTPUT_EXTENSION} ) | ||
| + endif() | ||
| endif() | ||
|
|
||
|
|
||
| @@ -819,8 +831,10 @@ join_paths(mi_pc_includedir "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") | ||
| join_paths(mi_pc_libdir "\${prefix}" "${CMAKE_INSTALL_LIBDIR}") | ||
|
|
||
| configure_file(mimalloc.pc.in mimalloc.pc @ONLY) | ||
| -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/mimalloc.pc" | ||
| - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/") | ||
| +if(NOT MI_SKIP_INSTALL) | ||
| + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/mimalloc.pc" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The final hunk of this patch declares Prompt for AI agents |
||
| + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/") | ||
| +endif() | ||
|
|
||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: The new SOURCEMETA_CORE_ALLOCATOR option is declared at the top-level and immediately drives
find_package(Mimalloc REQUIRED), but the only target that ever links the resulting library is the benchmark (and benchmarks default OFF). So a user who picks "mimalloc" expecting the core library stack to use it gets nothing changed, while still paying for a full mimalloc configure/build and risking a hard configure failure from the REQUIRED find when only the non-benchmark build is wanted. Consider gating the find_package (and ideally the option's effect) behind SOURCEMATA_CORE_BENCHMARK, and either documenting that the allocator only applies to the benchmark or actually threading the link into the core libraries so the option does what its description says.Prompt for AI agents