Skip to content

Instantly share code, notes, and snippets.

@kripken
Created February 22, 2024 20:49
Show Gist options
  • Save kripken/10ae73f44e939f8a5d7169e33777ebfb to your computer and use it in GitHub Desktop.
Save kripken/10ae73f44e939f8a5d7169e33777ebfb to your computer and use it in GitHub Desktop.
Binaryen wasm-opt.js pthreads build
diff --git a/CMakeLists.txt b/CMakeLists.txt
index def330b27..01ac747b9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -336,12 +336,12 @@ if(EMSCRIPTEN)
add_link_flag("-sALLOW_MEMORY_GROWTH")
add_link_flag("-sSTACK_SIZE=5MB")
- if(EMSCRIPTEN_ENABLE_WASM_EH)
- add_compile_flag("-fwasm-exceptions")
- else()
- add_compile_flag("-sDISABLE_EXCEPTION_CATCHING=0")
- add_link_flag("-sDISABLE_EXCEPTION_CATCHING=0")
- endif()
+ add_compile_flag("-fwasm-exceptions")
+ add_compile_flag("-pthread")
+ add_link_flag("-pthread")
+ add_link_flag("-PTHREAD_POOL_SIZE=navigator.hardwareConcurrency")
+ add_link_flag("-Wno-pthreads-mem-growth")
+ add_link_flag("-sMALLOC=mimalloc")
# In the browser, there is no natural place to provide commandline arguments
# for a commandline tool, so let the user run the main entry point themselves
# and pass in the arguments there.
@@ -359,7 +359,7 @@ if(EMSCRIPTEN)
add_link_flag("-sSINGLE_FILE")
endif()
# in opt builds, LTO helps so much (>20%) it's worth slow compile times
- add_nondebug_compile_flag("-flto")
+ # add_nondebug_compile_flag("-flto")
endif()
# clang doesn't print colored diagnostics when invoked from Ninja
diff --git a/src/support/threads.cpp b/src/support/threads.cpp
index e61769a84..3247ea388 100644
--- a/src/support/threads.cpp
+++ b/src/support/threads.cpp
@@ -139,15 +139,11 @@ void ThreadPool::initialize(size_t num) {
}
size_t ThreadPool::getNumCores() {
-#ifdef __EMSCRIPTEN__
- return 1;
-#else
size_t num = std::max(1U, std::thread::hardware_concurrency());
if (getenv("BINARYEN_CORES")) {
num = std::stoi(getenv("BINARYEN_CORES"));
}
return num;
-#endif
}
ThreadPool* ThreadPool::get() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment