@@ -49,14 +49,21 @@ endif()
4949
5050option (BUILD_STATIC_LIB "Build as a static library" OFF )
5151if (MSVC )
52- # We don't have dllexport declarations set up for windows yet.
52+ # We don't have dllexport declarations set up for Windows yet.
5353 set (BUILD_STATIC_LIB ON )
5454endif ()
5555
56- # Turn this off to install only tools and not static/dynamic libs
56+ # Advised to turn on when statically linking against musl libc (e.g., in the
57+ # Alpine Linux build we use for producing official Linux binaries), because
58+ # musl libc's allocator has very bad performance on heavily multi-threaded
59+ # workloads / high core count machines.
60+ # See https://github.com/WebAssembly/binaryen/issues/5561.
61+ option (MIMALLOC_STATIC "Build with statically linked mimalloc allocator" OFF )
62+
63+ # Turn this off to install only tools and not static/dynamic libs.
5764option (INSTALL_LIBS "Install libraries" ON )
5865
59- # Turn this on to build only the subset of tools needed for emscripten
66+ # Turn this on to build only the subset of tools needed for Emscripten.
6067option (BUILD_EMSCRIPTEN_TOOLS_ONLY "Build only tools needed by emscripten" OFF )
6168
6269# Turn this on to build binaryen.js as ES5, with additional compatibility configuration for js_of_ocaml.
@@ -345,11 +352,11 @@ if(EMSCRIPTEN)
345352 # in opt builds, LTO helps so much (>20%) it's worth slow compile times
346353 add_nondebug_compile_flag("-flto" )
347354 endif ()
348- if (EMSCRIPTEN_ENABLE_WASM64)
349- add_compile_flag("-sMEMORY64 -Wno-experimental" )
350- add_link_flag("-sMEMORY64" )
351- endif ()
355+ if (EMSCRIPTEN_ENABLE_WASM64)
356+ add_compile_flag("-sMEMORY64 -Wno-experimental" )
357+ add_link_flag("-sMEMORY64" )
352358 endif ()
359+ endif ()
353360
354361# clang doesn't print colored diagnostics when invoked from Ninja
355362if (UNIX AND CMAKE_GENERATOR STREQUAL "Ninja" )
@@ -455,6 +462,14 @@ if(BUILD_LLVM_DWARF)
455462 target_link_libraries (binaryen llvm_dwarf)
456463endif ()
457464
465+ if (MIMALLOC_STATIC)
466+ if (NOT (LINUX AND BUILD_STATIC_LIB) OR EMSCRIPTEN)
467+ message (FATAL_ERROR "Statically linking mimalloc is only supported when building as a native, statically linked library on Linux." )
468+ endif ()
469+ message (STATUS "Building with statically linked mimalloc allocator." )
470+ target_link_libraries (binaryen mimalloc-static )
471+ endif ()
472+
458473add_subdirectory (src/ir)
459474add_subdirectory (src/asmjs)
460475add_subdirectory (src/cfg)
0 commit comments