diff --git a/meson.build b/meson.build index 2c4817142..8d2821b1b 100644 --- a/meson.build +++ b/meson.build @@ -92,6 +92,8 @@ simdutf_dep = dependency('simdutf', ) miniaudio_dep = dependency('miniaudio') +mimalloc_dep = cc.find_library('mimalloc', required: get_option('enable_mimalloc')) + subdir('targets/util') subdir('targets/java') subdir('targets/nbt') diff --git a/meson.options b/meson.options index 4dc73f322..c2ed70bfc 100644 --- a/meson.options +++ b/meson.options @@ -40,3 +40,10 @@ option( value: 'frustum', description: 'Occlusion culling mode. Off disables ALL CULLING (debug only!), Frustum disables offscreen rendering (default), BFS is experimental connectivity culling, hardware uses GPU queries.', ) + +option( + 'enable_mimalloc', + type: 'feature', + value: 'auto', + description: 'Link mimalloc as the malloc implementation. Requires libmimalloc-dev.', +) diff --git a/targets/app/meson.build b/targets/app/meson.build index 6f90b86e7..e4be7a135 100644 --- a/targets/app/meson.build +++ b/targets/app/meson.build @@ -8,7 +8,18 @@ if host_machine.system() == 'linux' platform_sources += files(fs.read('linux_sources.txt').strip().split('\n')) endif -client_dependencies = [ +client_dependencies = [] + +# mimalloc must come first so the linker resolves malloc/free symbols to it +# before glibc. --no-as-needed prevents the linker from dropping it as +# "unreferenced" (the override happens via weak symbols, not direct calls). +client_link_args = [] +if mimalloc_dep.found() + client_dependencies += mimalloc_dep + client_link_args += ['-Wl,--no-as-needed'] +endif + +client_dependencies += [ java_dep, nbt_dep, render_dep, @@ -52,6 +63,7 @@ client = executable( '-D_UNICODE', ], c_args: global_cpp_defs + ['-DUNICODE', '-D_UNICODE'], + link_args: client_link_args, install: true, install_dir: '', )