summaryrefslogtreecommitdiff
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
parentcccc7a6a66b00ab79626afe02f259aa5290d479c (diff)
downloadbinaryen-c5db74cae9bc0c46065ad1ec9f3ec48772d09784.tar.gz
binaryen-c5db74cae9bc0c46065ad1ec9f3ec48772d09784.tar.bz2
binaryen-c5db74cae9bc0c46065ad1ec9f3ec48772d09784.zip
Add browser target for binaryen toolchain utilities (#6131)
-rw-r--r--CMakeLists.txt26
-rw-r--r--README.md11
2 files changed, 29 insertions, 8 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")
diff --git a/README.md b/README.md
index 341ad278c..a59e15ec2 100644
--- a/README.md
+++ b/README.md
@@ -352,9 +352,14 @@ To avoid the gtest dependency, you can pass `-DBUILD_TESTS=OFF` to cmake.
Binaryen.js can be built using Emscripten, which can be installed via [the SDK](http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html).
-```bash
-emcmake cmake . && emmake make binaryen_js
-```
+- Building for Node.js:
+ ```bash
+ emcmake cmake . && emmake make binaryen_js
+ ```
+- Building for the browser:
+ ```bash
+ emcmake cmake -DBUILD_FOR_BROWSER=ON . && emmake make
+ ```
### Visual C++