Skip to content
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

[jemalloc] Support non-Windows #25227

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions ports/jemalloc/add-unix-support.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 55e6a5f..fa44dec 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -58,6 +58,7 @@ option(force_lazy_lock "Forcing lazy-lock to avoid allocator/threading bootstrap
# install_prefix - installation directory prefix
# with-xslroot=<path> XSL stylesheet root path
option(build-tests "Build tests" OFF)
+option(disable-zone-allocator "Disable zone allocator for Darwin" ON)

set (PACKAGE_NAME "jemalloc")
project (${PACKAGE_NAME} C)
@@ -205,7 +206,7 @@ set(abi "elf")

# Whether malloc_usable_size definition can use const argument
CHECK_INCLUDE_FILES (malloc.h HAVE_MALLOC_H)
-if(HAVE_MALLOC_H)
+if(HAVE_MALLOC_H OR APPLE)
set(JEMALLOC_USABLE_SIZE_CONST const)
endif()

@@ -492,6 +493,7 @@ if(NOT WIN32)
set(JEMALLOC_HAVE_SYSCALL 1)
endif()

+ include(CheckFunctionExists)
CHECK_FUNCTION_EXISTS(secure_getenv HAVE_SECURE_GETENV)
if(HAVE_SECURE_GETENV)
set(JEMALLOC_HAVE_SECURE_GETENV 1)
@@ -702,7 +704,7 @@ set(C_SRCS
src/witness.c
)

-if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
+if(CMAKE_SYSTEM_NAME MATCHES "Darwin" AND NOT disable-zone-allocator)
list(APPEND C_SRCS src/zone.c)
endif()

diff --git a/Utilities.cmake b/Utilities.cmake
index 8fe8bb4..755e390 100644
--- a/Utilities.cmake
+++ b/Utilities.cmake
@@ -628,17 +628,6 @@ function (ConfigureFile file_path output_path ExpandDefine)
# Use Powershell to convert autoconf file to a cmake conf file
# and see if that fixes the issue of line continuations and ; in the file
# PS Snipper
-file(TO_NATIVE_PATH "${file_path}" ntv_file_path)
-
-# This converts #undefs into #cmakedefines so configure_file can handle it
-set(PS_CMD
-"Get-Content \"${ntv_file_path}\" |
-ForEach {
-if($_ -match '^#undef[ \t]*[^ \t]*')
- { $_ -replace '^#undef[ \t]*([^ \t]*)','#cmakedefine $1 @$1@' } else {$_}
-} |
-Set-Content \"${ntv_file_path}.cmake\""
-)

if(EXISTS ${file_path})
if(NOT ${ExpandDefine})
@@ -646,17 +635,15 @@ if(EXISTS ${file_path})
else()
file(REMOVE ${file_path}.cmake)
# Convert autoconf .in into a cmake .in
- execute_process(COMMAND powershell -Command "${PS_CMD}"
- RESULT_VARIABLE error_level
- ERROR_VARIABLE error_output)
-
- if(NOT ${error_level} EQUAL 0)
- message(FATAL_ERROR "Powershell completed with ${error_level} : ${error_output}")
- endif()
+ file(RELATIVE_PATH ntv_file_relative_path "${CMAKE_SOURCE_DIR}" "${file_path}")
+ file(READ "${file_path}" NTV_FILE_CONTENT)
+ string(REGEX REPLACE "#( *)undef +([^ ][^\n]+)\n" "#\\1cmakedefine \\2 @\\2@ \n" NTV_FILE_CONTENT "${NTV_FILE_CONTENT}")
+ file(WRITE "${CMAKE_BINARY_DIR}/${ntv_file_relative_path}" "${NTV_FILE_CONTENT}")

- configure_file(${file_path}.cmake ${output_path} @ONLY NEWLINE_STYLE WIN32)
+ configure_file(${CMAKE_BINARY_DIR}/${ntv_file_relative_path} ${output_path} @ONLY NEWLINE_STYLE WIN32)
file(REMOVE ${file_path}.cmake)
endif()
+ include_directories("${CMAKE_SOURCE_DIR}/include")
else()
message(FATAL_ERROR "${file_path} not found")
endif()
@@ -728,18 +715,35 @@ set(SRC "${WORK_FOLDER}/getpagesize.c")
set(COMPILE_OUTPUT_FILE "${WORK_FOLDER}/getpagesize.log")

file(WRITE ${SRC}
-"#include <windows.h>\n"
"#include <stdio.h>\n"
+"#ifdef _WIN32\n"
+"#include <windows.h>\n"
+"#elif defined(__APPLE__)\n"
+"#include <sys/param.h>\n"
+"#include <sys/sysctl.h>\n"
+"#else\n"
+"#include <unistd.h>\n"
+"#endif\n"
"int main(int argc, const char** argv) {\n"
-"int result;\n"
"#ifdef _WIN32\n"
+"int result;\n"
"SYSTEM_INFO si;\n"
"GetSystemInfo(&si);\n"
"result = si.dwPageSize;\n"
+"printf(\"%d\", result);\n"
+"#elif defined(__APPLE__)\n"
+"int mib[2], value, pagesize;\n"
+"size_t size;\n"
+"mib[0] = CTL_HW;\n"
+"mib[1] = HW_PAGESIZE;\n"
+"size = sizeof value;\n"
+"if (sysctl(mib, 2, &value, &size, NULL, 0) == -1)\n"
+" pagesize = -1;\n"
+"pagesize = value;\n"
+"printf(\"%d\", pagesize);\n"
"#else\n"
-"result = sysconf(_SC_PAGESIZE);\n"
+"printf(\"%d\", getpagesize());\n"
"#endif\n"
-"printf(\"%d\", result);\n"
"return 0;\n"
"}\n"
)
@@ -776,6 +780,7 @@ function(JeCflagsAppend cflags APPEND_TO_VAR RESULT_VAR)

# Combine the result to try
set(TFLAGS "${${APPEND_TO_VAR}} ${cflags}")
+ include(CheckCCompilerFlag)
CHECK_C_COMPILER_FLAG(${TFLAGS} status)

if(status)
diff --git a/src/jemalloc.c b/src/jemalloc.c
index 38650ff..2b8c545 100644
--- a/src/jemalloc.c
+++ b/src/jemalloc.c
@@ -988,7 +988,7 @@ malloc_conf_init(void)
int saved_errno = errno;
const char *linkname =
# ifdef JEMALLOC_PREFIX
- "/etc/"JEMALLOC_PREFIX"malloc.conf"
+ "/etc/JEMALLOC_PREFIXmalloc.conf"
# else
"/etc/malloc.conf"
# endif
23 changes: 13 additions & 10 deletions ports/jemalloc/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
vcpkg_check_linkage(ONLY_DYNAMIC_LIBRARY)
if (VCPKG_TARGET_IS_WINDOWS)
vcpkg_check_linkage(ONLY_DYNAMIC_LIBRARY)
endif()

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
Expand All @@ -10,26 +12,27 @@ vcpkg_from_github(
fix-cmakelists.patch
fix-utilities.patch
fix-static-build.patch
add-unix-support.patch
)

if (VCPKG_CRT_LINKAGE STREQUAL "dynamic")
set(BUILD_STATIC_LIBRARY OFF)
else()
set(BUILD_STATIC_LIBRARY ON)
endif()
vcpkg_configure_cmake(
vcpkg_cmake_configure(
DISABLE_PARALLEL_CONFIGURE
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS -DGIT_FOUND=OFF -DCMAKE_DISABLE_FIND_PACKAGE_Git=ON -Dwithout-export=${BUILD_STATIC_LIBRARY}
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
-DGIT_FOUND=OFF
-DCMAKE_DISABLE_FIND_PACKAGE_Git=ON
-Dwithout-export=${BUILD_STATIC_LIBRARY}
)

vcpkg_install_cmake()

vcpkg_cmake_install()
vcpkg_copy_pdbs()

file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")

# Handle copyright
file(COPY ${SOURCE_PATH}/COPYING DESTINATION ${CURRENT_PACKAGES_DIR}/share/jemalloc)
file(RENAME ${CURRENT_PACKAGES_DIR}/share/jemalloc/COPYING ${CURRENT_PACKAGES_DIR}/share/jemalloc/copyright)
file(INSTALL "${SOURCE_PATH}/COPYING" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
14 changes: 11 additions & 3 deletions ports/jemalloc/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{
"name": "jemalloc",
"version-string": "4.3.1",
"port-version": 5,
"version": "4.3.1",
"port-version": 6,
"description": "jemalloc is a general purpose malloc(3) implementation that emphasizes fragmentation avoidance and scalable concurrency support",
"homepage": "https://github.com/jemalloc/jemalloc-cmake"
"homepage": "https://github.com/jemalloc/jemalloc-cmake",
"license": "BSD-2-Clause",
"supports": "!arm & !uwp & !(windows & static)",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
}
]
}
6 changes: 0 additions & 6 deletions scripts/ci.baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,6 @@ isal:x64-windows=fail
isal:x64-windows-static=fail
isal:x64-windows-static-md=fail
isal:x86-windows=fail
jemalloc:arm64-windows=fail
jemalloc:arm-uwp=fail
jemalloc:x64-linux=fail
jemalloc:x64-osx=fail
jemalloc:x64-uwp=fail
jemalloc:x64-windows-static=fail
jinja2cpplight:arm-uwp=fail
jinja2cpplight:x64-uwp=fail
kfr:arm64-windows=fail
Expand Down
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -3066,7 +3066,7 @@
},
"jemalloc": {
"baseline": "4.3.1",
"port-version": 5
"port-version": 6
},
"jinja2cpplight": {
"baseline": "2018-05-08",
Expand Down
5 changes: 5 additions & 0 deletions versions/j-/jemalloc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "b46ade047a817b79a86ba0647901d501f9f16bf1",
"version": "4.3.1",
"port-version": 6
},
{
"git-tree": "0ced62e7a268f8442b2e808df7b094afe8998c38",
"version-string": "4.3.1",
Expand Down