summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorThomas Steiner <tomac@google.com>2023-11-21 20:10:41 +0100
committerGitHub <noreply@github.com>2023-11-21 11:10:41 -0800
commitc5db74cae9bc0c46065ad1ec9f3ec48772d09784 (patch)
tree3126bfbf036f00a82a8e91d5eaf5501921e3a987 /CMakeLists.txt
parentcccc7a6a66b00ab79626afe02f259aa5290d479c (diff)
downloadbinaryen-c5db74cae9bc0c46065ad1ec9f3ec48772d09784.tar.gz
binaryen-c5db74cae9bc0c46065ad1ec9f3ec48772d09784.tar.bz2
binaryen-c5db74cae9bc0c46065ad1ec9f3ec48772d09784.zip
Add browser target for binaryen toolchain utilities (#6131)
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt26
1 files changed, 21 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4727100de..f8c5ee8d2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,6 +46,9 @@ option(BUILD_EMSCRIPTEN_TOOLS_ONLY "Build only tools needed by emscripten" OFF)
# Turn this on to build binaryen.js as ES5, with additional compatibility configuration for js_of_ocaml.
option(JS_OF_OCAML "Build binaryen.js for js_of_ocaml" OFF)
+# Turn this on to compile binaryen toolchain utilities for the browser.
+option(BUILD_FOR_BROWSER "Build binaryen toolchain utilities for the browser" OFF)
+
# Turn this on to use the Wasm EH feature instead of emscripten EH in the wasm/BinaryenJS builds
option(EMSCRIPTEN_ENABLE_WASM_EH "Enable Wasm EH feature in emscripten build" OFF)
@@ -339,11 +342,24 @@ if(EMSCRIPTEN)
add_compile_flag("-sDISABLE_EXCEPTION_CATCHING=0")
add_link_flag("-sDISABLE_EXCEPTION_CATCHING=0")
endif()
- # make the tools immediately usable on Node.js
- add_link_flag("-sNODERAWFS")
- # in opt builds, LTO helps so much (>20%) it's worth slow compile times
- add_nondebug_compile_flag("-flto")
-endif()
+ # 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.
+ if(BUILD_FOR_BROWSER)
+ add_link_flag("-sENVIRONMENT=web,worker")
+ add_link_flag("-sINVOKE_RUN=0")
+ add_link_flag("-sEXPORTED_RUNTIME_METHODS=run,callMain,FS")
+ add_link_flag("-sMODULARIZE")
+ add_link_flag("-sEXPORT_ES6")
+ add_link_flag("-sFILESYSTEM")
+ add_link_flag("-sFORCE_FILESYSTEM")
+ # On Node.js, make the tools immediately usable.
+ else()
+ add_link_flag("-sNODERAWFS")
+ endif()
+ # in opt builds, LTO helps so much (>20%) it's worth slow compile times
+ add_nondebug_compile_flag("-flto")
+ endif()
# clang doesn't print colored diagnostics when invoked from Ninja
if(UNIX AND CMAKE_GENERATOR STREQUAL "Ninja")