diff options
| author | ruki <[email protected]> | 2025-09-21 00:02:42 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-09-21 20:50:55 +0800 |
| commit | c22c658f7ec91bd2945f3dda1f600ccb6ab5ce4d (patch) | |
| tree | 46683aafb2f67e49afe2bd9281d8a9111a4d430d | |
| parent | 9d31ef9182159697179b781f0e2d42983277857a (diff) | |
add xmake.sh for mimalloc
| -rwxr-xr-x | core/src/mimalloc/xmake.sh | 53 | ||||
| -rw-r--r-- | core/src/xmake/engine.c | 4 | ||||
| -rwxr-xr-x | core/src/xmake/xmake.sh | 3 | ||||
| -rw-r--r-- | core/xmake.lua | 2 | ||||
| -rwxr-xr-x | core/xmake.sh | 7 |
5 files changed, 67 insertions, 2 deletions
diff --git a/core/src/mimalloc/xmake.sh b/core/src/mimalloc/xmake.sh new file mode 100755 index 000000000..d85373851 --- /dev/null +++ b/core/src/mimalloc/xmake.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +target "mimalloc" + set_kind "static" + set_default false + set_warnings "all" + add_includedirs "mimalloc/include" "{public}" + add_defines "XM_CONFIG_API_HAVE_MIMALLOC" "{public}" + + add_files "mimalloc/src/alloc.c" + add_files "mimalloc/src/alloc-aligned.c" + add_files "mimalloc/src/alloc-posix.c" + add_files "mimalloc/src/arena.c" + add_files "mimalloc/src/bitmap.c" + add_files "mimalloc/src/heap.c" + add_files "mimalloc/src/init.c" + add_files "mimalloc/src/libc.c" + add_files "mimalloc/src/options.c" + add_files "mimalloc/src/os.c" + add_files "mimalloc/src/page.c" + add_files "mimalloc/src/random.c" + add_files "mimalloc/src/segment.c" + add_files "mimalloc/src/segment-map.c" + add_files "mimalloc/src/stats.c" + add_files "mimalloc/src/prim/prim.c" + + # override malloc + if is_plat "macosx"; then + add_files "mimalloc/src/prim/osx/alloc-override-zone.c" + add_defines "MI_OSX_ZONE=1" "MI_OSX_INTERPOSE=1" + fi + add_cflags "-fno-builtin-malloc" + + # fast atomics + if is_plat "macosx" "iphoneos" && is_arch "arm64"; then + add_cflags "-Xarch_arm64;-march=armv8.1-a" + elif is_plat "windows"; then + add_cflags "/arch:armv8.1" + elif is_arch "arm64"; then + add_cflags "-march=armv8.1-a" + fi + + add_defines "MI_SKIP_COLLECT_ON_EXIT=1" + if is_plat "windows" && is_kind "static"; then + add_defines "MI_WIN_USE_FIXED_TLS=1" + fi + if is_plat "mingw"; then + add_defines "_WIN32_WINNT=0x600" + fi + + if is_plat "windows" "mingw"; then + add_syslinks "psapi" "shell32" "user32" "advapi32" "bcrypt" "{public}" + fi diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index 007a94639..918272f59 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -1295,7 +1295,9 @@ static tb_pointer_t xm_engine_lua_realloc(tb_pointer_t udata, tb_pointer_t data, #ifdef XM_CONFIG_API_HAVE_MIMALLOC tb_pointer_t ptr = tb_null; if (nsize == 0 && data) mi_free(data); - else ptr = mi_realloc(data, nsize); + else if (!data) ptr = mi_malloc(nsize); + else if (nsize != osize) ptr = mi_realloc(data, nsize); + else ptr = data; return ptr; #else tb_pointer_t ptr = tb_null; diff --git a/core/src/xmake/xmake.sh b/core/src/xmake/xmake.sh index 731d1d783..6ca1261af 100755 --- a/core/src/xmake/xmake.sh +++ b/core/src/xmake/xmake.sh @@ -31,6 +31,9 @@ target "xmake" else add_deps "lua" fi + if has_config "mimalloc"; then + add_deps "mimalloc" + fi fi # add options diff --git a/core/xmake.lua b/core/xmake.lua index dded49371..e84a1506d 100644 --- a/core/xmake.lua +++ b/core/xmake.lua @@ -75,7 +75,7 @@ option_end() -- the mimalloc option option("mimalloc") - set_default(true) + set_default(false) set_description("Use mimalloc as memory allocator") option_end() diff --git a/core/xmake.sh b/core/xmake.sh index 69592ad0d..0c143f03c 100755 --- a/core/xmake.sh +++ b/core/xmake.sh @@ -35,6 +35,9 @@ option "runtime" "Use luajit or lua runtime" "lua" # always use external dependencies option "external" "Always use external dependencies" false +# use mimalloc +option "mimalloc" "Use mimalloc as memory allocator" false + # the readline option option "readline" add_links "readline" @@ -226,6 +229,10 @@ if ! has_config "external"; then includes "src/lz4" includes "src/sv" includes "src/tbox" + if has_config "mimalloc"; then + includes "src/mimalloc" + fi fi includes "src/xmake" includes "src/cli" + |
