Skip to content

Commit 1f2cd4f

Browse files
authored
Make Emscripten CMake build more configurable (#6638)
This makes several changes to make the Emscripten build more configurable and convenient for testing: 1) Remove ERROR_ON_WASM_CHANGES_AFTER_LINK from ENABLE_BIGINT: this makes the setting composable with optimized builds 2) Add EMSCRIPTEN_ENABLE_MEMORY64 to build with the memory64 option 3) Add EMSCRIPTEN_ENABLE_SINGLE_FILE to allow disabling the single-file build (to make it easier to analyze binary output)
1 parent f8086ad commit 1f2cd4f

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

CMakeLists.txt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,15 @@ option(BUILD_FOR_BROWSER "Build binaryen toolchain utilities for the browser" OF
5252
# Turn this on to use the Wasm EH feature instead of emscripten EH in the wasm/BinaryenJS builds
5353
option(EMSCRIPTEN_ENABLE_WASM_EH "Enable Wasm EH feature in emscripten build" OFF)
5454

55+
option(EMSCRIPTEN_ENABLE_WASM64 "Enable memory64 in emscripten build" OFF)
56+
5557
# Turn this on to use pthreads feature in the wasm/BinaryenJS builds
5658
option(EMSCRIPTEN_ENABLE_PTHREADS "Enable pthreads in emscripten build" OFF)
5759

60+
# Turn this off to generate a separate .wasm file instead of packaging it into the JS.
61+
# This is useful for debugging, performance analysis, and other testing.
62+
option(EMSCRIPTEN_ENABLE_SINGLE_FILE "Enable SINGLE_FILE mode in emscripten build" ON)
63+
5864
# For git users, attempt to generate a more useful version string
5965
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
6066
find_package(Git QUIET REQUIRED)
@@ -329,7 +335,6 @@ if(EMSCRIPTEN)
329335
# does when run on wasm files.
330336
option(ENABLE_BIGINT "Enable wasm BigInt support" OFF)
331337
if(ENABLE_BIGINT)
332-
add_link_flag("-sERROR_ON_WASM_CHANGES_AFTER_LINK")
333338
add_link_flag("-sWASM_BIGINT")
334339
endif()
335340

@@ -377,6 +382,10 @@ if(EMSCRIPTEN)
377382
endif()
378383
# in opt builds, LTO helps so much (>20%) it's worth slow compile times
379384
add_nondebug_compile_flag("-flto")
385+
if(EMSCRIPTEN_ENABLE_WASM64)
386+
add_compile_flag("-sMEMORY64 -Wno-experimental")
387+
add_link_flag("-sMEMORY64")
388+
endif()
380389
endif()
381390

382391
# clang doesn't print colored diagnostics when invoked from Ninja
@@ -477,7 +486,9 @@ if(EMSCRIPTEN)
477486
target_link_libraries(binaryen_wasm "-Wno-unused-command-line-argument")
478487
# Emit a single file for convenience of people using binaryen.js as a library,
479488
# so they only need to distribute a single file.
480-
target_link_libraries(binaryen_wasm "-sSINGLE_FILE")
489+
if(EMSCRIPTEN_ENABLE_SINGLE_FILE)
490+
target_link_libraries(binaryen_wasm "-sSINGLE_FILE")
491+
endif()
481492
target_link_libraries(binaryen_wasm "-sEXPORT_ES6")
482493
target_link_libraries(binaryen_wasm "-sEXPORTED_RUNTIME_METHODS=stringToUTF8OnStack,stringToAscii")
483494
target_link_libraries(binaryen_wasm "-sEXPORTED_FUNCTIONS=_malloc,_free")
@@ -512,7 +523,9 @@ if(EMSCRIPTEN)
512523
target_link_libraries(binaryen_js "-sNODERAWFS=0")
513524
# Do not error on the repeated NODERAWFS argument
514525
target_link_libraries(binaryen_js "-Wno-unused-command-line-argument")
515-
target_link_libraries(binaryen_js "-sSINGLE_FILE")
526+
if(EMSCRIPTEN_ENABLE_SINGLE_FILE)
527+
target_link_libraries(binaryen_js "-sSINGLE_FILE")
528+
endif()
516529
target_link_libraries(binaryen_js "-sEXPORT_NAME=Binaryen")
517530
# Currently, js_of_ocaml can only process ES5 code
518531
if(JS_OF_OCAML)

0 commit comments

Comments
 (0)