@@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.10.2)
7
7
# to reduce this for compatability with emsdk.
8
8
set (CMAKE_OSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "Minimum OS X deployment version" )
9
9
10
- project (binaryen LANGUAGES C CXX VERSION 116 )
10
+ project (binaryen LANGUAGES C CXX VERSION 117 )
11
11
include (GNUInstallDirs)
12
12
13
13
# The C++ standard whose features are required to build Binaryen.
@@ -46,9 +46,15 @@ option(BUILD_EMSCRIPTEN_TOOLS_ONLY "Build only tools needed by emscripten" OFF)
46
46
# Turn this on to build binaryen.js as ES5, with additional compatibility configuration for js_of_ocaml.
47
47
option (JS_OF_OCAML "Build binaryen.js for js_of_ocaml" OFF )
48
48
49
+ # Turn this on to compile binaryen toolchain utilities for the browser.
50
+ option (BUILD_FOR_BROWSER "Build binaryen toolchain utilities for the browser" OFF )
51
+
49
52
# Turn this on to use the Wasm EH feature instead of emscripten EH in the wasm/BinaryenJS builds
50
53
option (EMSCRIPTEN_ENABLE_WASM_EH "Enable Wasm EH feature in emscripten build" OFF )
51
54
55
+ # Turn this on to use pthreads feature in the wasm/BinaryenJS builds
56
+ option (EMSCRIPTEN_ENABLE_PTHREADS "Enable pthreads in emscripten build" OFF )
57
+
52
58
# For git users, attempt to generate a more useful version string
53
59
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR} /.git)
54
60
find_package (Git QUIET REQUIRED)
@@ -280,6 +286,11 @@ else()
280
286
add_compile_flag("-Wimplicit-fallthrough" )
281
287
add_compile_flag("-Wnon-virtual-dtor" )
282
288
289
+ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
290
+ # Google style requires this, so make sure we compile cleanly with it.
291
+ add_compile_flag("-Wctad-maybe-unsupported" )
292
+ endif ()
293
+
283
294
if (WIN32 )
284
295
add_compile_flag("-D_GNU_SOURCE" )
285
296
add_compile_flag("-D__STDC_FORMAT_MACROS" )
@@ -319,7 +330,6 @@ if(EMSCRIPTEN)
319
330
endif ()
320
331
321
332
if ("${CMAKE_BUILD_TYPE} " MATCHES "Release" )
322
- add_link_flag("-sSINGLE_FILE" )
323
333
# Extra check that cmake has set -O3 in its release flags.
324
334
# This is really as an assertion that cmake is behaving as we expect.
325
335
if (NOT CMAKE_CXX_FLAGS_RELEASE_INIT MATCHES "-O3" )
@@ -328,17 +338,42 @@ if(EMSCRIPTEN)
328
338
endif ()
329
339
330
340
add_link_flag("-sALLOW_MEMORY_GROWTH" )
341
+ add_link_flag("-sSTACK_SIZE=5MB" )
331
342
if (EMSCRIPTEN_ENABLE_WASM_EH)
332
343
add_compile_flag("-fwasm-exceptions" )
333
344
else ()
334
345
add_compile_flag("-sDISABLE_EXCEPTION_CATCHING=0" )
335
346
add_link_flag("-sDISABLE_EXCEPTION_CATCHING=0" )
336
347
endif ()
337
- # make the tools immediately usable on Node.js
338
- add_link_flag("-sNODERAWFS" )
339
- # in opt builds, LTO helps so much (>20%) it's worth slow compile times
340
- add_nondebug_compile_flag("-flto" )
341
- endif ()
348
+ if (EMSCRIPTEN_ENABLE_PTHREADS)
349
+ add_compile_flag("-pthread" )
350
+ add_link_flag("-pthread" )
351
+ # Use mimalloc to avoid a 5x slowdown:
352
+ # https://github.com/emscripten-core/emscripten/issues/15727#issuecomment-1960295018
353
+ add_link_flag("-sMALLOC=mimalloc" )
354
+ # Disable the warning on pthreads+memory growth (we are not much affected by
355
+ # it as there is little wasm-JS transfer of data, almost all work is inside
356
+ # the wasm).
357
+ add_link_flag("-Wno-pthreads-mem-growth" )
358
+ endif ()
359
+ # In the browser, there is no natural place to provide commandline arguments
360
+ # for a commandline tool, so let the user run the main entry point themselves
361
+ # and pass in the arguments there.
362
+ if (BUILD_FOR_BROWSER)
363
+ add_link_flag("-sENVIRONMENT=web,worker" )
364
+ add_link_flag("-sINVOKE_RUN=0" )
365
+ add_link_flag("-sEXPORTED_RUNTIME_METHODS=run,callMain,FS" )
366
+ add_link_flag("-sMODULARIZE" )
367
+ add_link_flag("-sEXPORT_ES6" )
368
+ add_link_flag("-sFILESYSTEM" )
369
+ add_link_flag("-sFORCE_FILESYSTEM" )
370
+ else ()
371
+ # On Node.js, make the tools immediately usable.
372
+ add_link_flag("-sNODERAWFS" )
373
+ endif ()
374
+ # in opt builds, LTO helps so much (>20%) it's worth slow compile times
375
+ add_nondebug_compile_flag("-flto" )
376
+ endif ()
342
377
343
378
# clang doesn't print colored diagnostics when invoked from Ninja
344
379
if (UNIX AND CMAKE_GENERATOR STREQUAL "Ninja" )
@@ -439,14 +474,16 @@ if(EMSCRIPTEN)
439
474
target_link_libraries (binaryen_wasm "-sFILESYSTEM" )
440
475
target_link_libraries (binaryen_wasm "-sEXPORT_NAME=Binaryen" )
441
476
target_link_libraries (binaryen_wasm "-sNODERAWFS=0" )
477
+ # Emit a single file for convenience of people using binaryen.js as a library,
478
+ # so they only need to distribute a single file.
479
+ target_link_libraries (binaryen_wasm "-sSINGLE_FILE" )
442
480
target_link_libraries (binaryen_wasm "-sEXPORT_ES6" )
443
- target_link_libraries (binaryen_wasm "-sEXPORTED_RUNTIME_METHODS=allocateUTF8OnStack ,stringToAscii" )
481
+ target_link_libraries (binaryen_wasm "-sEXPORTED_RUNTIME_METHODS=stringToUTF8OnStack ,stringToAscii" )
444
482
target_link_libraries (binaryen_wasm "-sEXPORTED_FUNCTIONS=_malloc,_free" )
445
483
target_link_libraries (binaryen_wasm "--post-js=${CMAKE_CURRENT_SOURCE_DIR} /src/js/binaryen.js-post.js" )
446
484
target_link_libraries (binaryen_wasm "-msign-ext" )
447
485
target_link_libraries (binaryen_wasm "-mbulk-memory" )
448
486
target_link_libraries (binaryen_wasm optimized "--closure=1" )
449
- target_link_libraries (binaryen_wasm optimized "--closure-args=\" --language_in=ECMASCRIPT6 --language_out=ECMASCRIPT6\" " )
450
487
# TODO: Fix closure warnings! (#5062)
451
488
target_link_libraries (binaryen_wasm optimized "-Wno-error=closure" )
452
489
target_link_libraries (binaryen_wasm optimized "-flto" )
@@ -472,14 +509,15 @@ if(EMSCRIPTEN)
472
509
target_link_libraries (binaryen_js "-sFILESYSTEM=1" )
473
510
endif ()
474
511
target_link_libraries (binaryen_js "-sNODERAWFS=0" )
512
+ target_link_libraries (binaryen_js "-sSINGLE_FILE" )
475
513
target_link_libraries (binaryen_js "-sEXPORT_NAME=Binaryen" )
476
514
# Currently, js_of_ocaml can only process ES5 code
477
515
if (JS_OF_OCAML)
478
516
target_link_libraries (binaryen_js "-sEXPORT_ES6=0" )
479
517
else ()
480
518
target_link_libraries (binaryen_js "-sEXPORT_ES6=1" )
481
519
endif ()
482
- target_link_libraries (binaryen_js "-sEXPORTED_RUNTIME_METHODS=allocateUTF8OnStack ,stringToAscii" )
520
+ target_link_libraries (binaryen_js "-sEXPORTED_RUNTIME_METHODS=stringToUTF8OnStack ,stringToAscii" )
483
521
target_link_libraries (binaryen_js "-sEXPORTED_FUNCTIONS=_malloc,_free" )
484
522
target_link_libraries (binaryen_js "--post-js=${CMAKE_CURRENT_SOURCE_DIR} /src/js/binaryen.js-post.js" )
485
523
# js_of_ocaml needs a specified variable with special comment to provide the library to consumers
@@ -489,9 +527,7 @@ if(EMSCRIPTEN)
489
527
target_link_libraries (binaryen_js optimized "--closure=1" )
490
528
# Currently, js_of_ocaml can only process ES5 code
491
529
if (JS_OF_OCAML)
492
- target_link_libraries (binaryen_js optimized "--closure-args=\" --language_in=ECMASCRIPT6 --language_out=ECMASCRIPT5\" " )
493
- else ()
494
- target_link_libraries (binaryen_js optimized "--closure-args=\" --language_in=ECMASCRIPT6 --language_out=ECMASCRIPT6\" " )
530
+ target_link_libraries (binaryen_js optimized "--closure-args=\" --language_out=ECMASCRIPT5\" " )
495
531
endif ()
496
532
# TODO: Fix closure warnings! (#5062)
497
533
target_link_libraries (binaryen_js optimized "-Wno-error=closure" )
0 commit comments