From 2f0bf1a495f422b64483c9d785e7fcec140a2908 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Tue, 3 May 2022 15:30:24 -0700 Subject: [PATCH 1/3] Add JSOO cmake patch --- CMakeLists.txt | 30 ++++++++++++++++++++++++++---- src/js/binaryen.jsoo-extern-pre.js | 6 ++++++ 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 src/js/binaryen.jsoo-extern-pre.js diff --git a/CMakeLists.txt b/CMakeLists.txt index c0699ba24ae..c4f25b8d680 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -403,14 +403,36 @@ if(EMSCRIPTEN) # only valid with fastcomp and WASM=0 target_link_libraries(binaryen_js "-s ELIMINATE_DUPLICATE_FUNCTIONS=1") endif() - target_link_libraries(binaryen_js "-s NO_FILESYSTEM=0") + # Disabling filesystem and setting web environment for js_of_ocaml + # so it doesn't try to detect the "node" environment + if(JS_OF_OCAML) + target_link_libraries(binaryen_js "-s NO_FILESYSTEM=1") + target_link_libraries(binaryen_js "-s ENVIRONMENT=web,worker") + else() + target_link_libraries(binaryen_js "-s NO_FILESYSTEM=0") + endif() target_link_libraries(binaryen_js "-s NODERAWFS=0") target_link_libraries(binaryen_js "-s EXPORT_NAME=Binaryen") - target_link_libraries(binaryen_js "-s EXPORT_ES6=1") + # Currently, js_of_ocaml can only process ES5 code + if(JS_OF_OCAML) + target_link_libraries(binaryen_js "-s EXPORT_ES6=0") + else() + target_link_libraries(binaryen_js "-s EXPORT_ES6=1") + endif() target_link_libraries(binaryen_js "--post-js ${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.js-post.js") - target_link_libraries(binaryen_js "--extern-pre-js ${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.js-extern-pre.js") + # js_of_ocaml needs a specified variable with special comment to provide the library to consumers + if(JS_OF_OCAML) + target_link_libraries(binaryen_js "--extern-pre-js ${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.jsoo-extern-pre.js") + else() + target_link_libraries(binaryen_js "--extern-pre-js ${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.js-extern-pre.js") + endif() target_link_libraries(binaryen_js optimized "--closure 1") - target_link_libraries(binaryen_js optimized "--closure-args \"--language_in=ECMASCRIPT6 --language_out=ECMASCRIPT6\"") + # Currently, js_of_ocaml can only process ES5 code + if(JS_OF_OCAML) + target_link_libraries(binaryen_js optimized "--closure-args \"--language_in=ECMASCRIPT6 --language_out=ECMASCRIPT5\"") + else() + target_link_libraries(binaryen_js optimized "--closure-args \"--language_in=ECMASCRIPT6 --language_out=ECMASCRIPT6\"") + endif() target_link_libraries(binaryen_js optimized "-flto") target_link_libraries(binaryen_js debug "--profiling") target_link_libraries(binaryen_js debug "-s ASSERTIONS") diff --git a/src/js/binaryen.jsoo-extern-pre.js b/src/js/binaryen.jsoo-extern-pre.js new file mode 100644 index 00000000000..fdfee1c22f2 --- /dev/null +++ b/src/js/binaryen.jsoo-extern-pre.js @@ -0,0 +1,6 @@ +// js_of_ocaml needs a special syntax for exposing variables to the compiler +// and it is not built for nodejs so we don't need the __dirname hack + +//Provides: Binaryen +var Binaryen = {}; + From da408cb1594c6bba5f4f75a38cc6cd25c05c09e5 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Thu, 5 May 2022 16:51:30 -0700 Subject: [PATCH 2/3] Add option configuration --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c4f25b8d680..f1d15015d4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,9 @@ option(BYN_ENABLE_ASSERTIONS "Enable assertions" ON) # Turn this off to avoid the dependency on gtest. option(BUILD_TESTS "Build GTest-based tests" ON) +# Turn this on to build binaryen.js as ES5, with additional compatibility options for js_of_ocaml. +option(JS_OF_OCAML "Build binaryen.js for js_of_ocaml" OFF) + # For git users, attempt to generate a more useful version string if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git) find_package(Git QUIET REQUIRED) From 934eb3aeb16b650a8017490943ab4bc08211394f Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Thu, 5 May 2022 16:52:17 -0700 Subject: [PATCH 3/3] rephrase --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f1d15015d4b..820e78366f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,7 @@ option(BYN_ENABLE_ASSERTIONS "Enable assertions" ON) # Turn this off to avoid the dependency on gtest. option(BUILD_TESTS "Build GTest-based tests" ON) -# Turn this on to build binaryen.js as ES5, with additional compatibility options for js_of_ocaml. +# 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) # For git users, attempt to generate a more useful version string