Skip to content

Commit 4c2cab0

Browse files
committed
[emscripten] Drop -sWASM=0 variant build
There is now just one emscripten target called `binaryen_js`. The settings for these two targets were almost identical except for. 1. Some JS_OF_OCAML specific stuff which is kept for the new unified target. 2. `-sASSERTIONS` was being forced (See #2507). I dropped this in favor of doing a debug build in testing where this is enabled by default.
1 parent 3286b6e commit 4c2cab0

File tree

7 files changed

+37
-88
lines changed

7 files changed

+37
-88
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ CMakeFiles
2929
/dist/
3030
/config.h
3131
/emcc-build
32+
/emcc-build-dbg
3233
compile_commands.json
3334
test/lit/lit.site.cfg.py
3435
CMakeUserPresets.json

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ full changeset diff at the end of each section.
1515
Current Trunk
1616
-------------
1717

18+
- The emscripten build of binaryen no longer targets pure JS (via wasm2js) by
19+
default. In the long run this will allow us to enable WASM_BIGINT and other
20+
features that wasm2js does not support. There is now just a single
21+
binaryen_js target. It should still be possible to inject `-sWASM=0` as a
22+
linker flag but this is not officially supported. (#7995)
1823
- The --mod-asyncify-never-unwind and --mod-asyncify-always-and-only-unwind
1924
passed were deleted. They only existed to support the lazy code loading
2025
support in emscripten that was removed. (#7893)

CMakeLists.txt

Lines changed: 14 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -529,92 +529,44 @@ endif()
529529
# binaryen.js
530530
#
531531
# Note that we can't emit binaryen.js directly, as there is libbinaryen already
532-
# declared earlier, so we create binaryen_wasm/js.js, which must then be copied.
532+
# declared earlier, so we create binaryen_js.js, which must then be copied.
533533
if(EMSCRIPTEN)
534-
# binaryen.js WebAssembly variant
535-
add_executable(binaryen_wasm ${binaryen_HEADERS})
534+
add_executable(binaryen_js ${binaryen_HEADERS})
536535
# For the emscripten build we link against libbinaryen wih `--whole-archive`.
537536
# Without this, the EMSCRIPTEN_KEEPALIVE symbols within the library would
538537
# be ignored.
539-
target_link_libraries(binaryen_wasm PRIVATE "$<LINK_LIBRARY:WHOLE_ARCHIVE,binaryen>")
540-
target_link_libraries(binaryen_wasm PRIVATE "-sFILESYSTEM")
541-
target_link_libraries(binaryen_wasm PRIVATE "-sEXPORT_NAME=Binaryen")
542-
target_link_libraries(binaryen_wasm PRIVATE "-sNODERAWFS=0")
543-
# Do not error on the repeated NODERAWFS argument
544-
target_link_libraries(binaryen_wasm PRIVATE "-Wno-unused-command-line-argument")
545-
# Emit a single file for convenience of people using binaryen.js as a library,
546-
# so they only need to distribute a single file.
547-
if(EMSCRIPTEN_ENABLE_SINGLE_FILE)
548-
target_link_libraries(binaryen_wasm PRIVATE "-sSINGLE_FILE")
549-
endif()
550-
target_link_libraries(binaryen_wasm PRIVATE "-sEXPORT_ES6")
551-
target_link_libraries(binaryen_wasm PRIVATE "-sEXPORTED_RUNTIME_METHODS=stringToUTF8OnStack,stringToAscii")
552-
target_link_libraries(binaryen_wasm PRIVATE "-sEXPORTED_FUNCTIONS=_malloc,_free")
553-
target_link_libraries(binaryen_wasm PRIVATE "--post-js=${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.js-post.js")
554-
target_link_libraries(binaryen_wasm PRIVATE "-msign-ext")
555-
target_link_libraries(binaryen_wasm PRIVATE "-mbulk-memory")
556-
target_link_libraries(binaryen_wasm PRIVATE optimized "--closure=1")
557-
# TODO: Fix closure warnings! (#5062)
558-
target_link_libraries(binaryen_wasm PRIVATE optimized "-Wno-error=closure")
559-
if (BYN_ENABLE_LTO)
560-
target_link_libraries(binaryen_wasm PRIVATE optimized "-flto")
561-
endif()
562-
target_link_libraries(binaryen_wasm PRIVATE debug "--profiling")
563-
# Avoid catching exit as that can confuse error reporting in Node,
564-
# see https://github.com/emscripten-core/emscripten/issues/17228
565-
target_link_libraries(binaryen_wasm PRIVATE "-sNODEJS_CATCH_EXIT=0")
566-
install(TARGETS binaryen_wasm DESTINATION ${CMAKE_INSTALL_BINDIR})
567-
568-
# binaryen.js JavaScript variant
569-
add_executable(binaryen_js ${binaryen_HEADERS})
570538
target_link_libraries(binaryen_js PRIVATE "$<LINK_LIBRARY:WHOLE_ARCHIVE,binaryen>")
571-
target_link_libraries(binaryen_js PRIVATE "-sWASM=0")
572-
target_link_libraries(binaryen_js PRIVATE "-sWASM_ASYNC_COMPILATION=0")
573-
574-
if(${CMAKE_CXX_COMPILER_VERSION} STREQUAL "6.0.1")
575-
# only valid with fastcomp and WASM=0
576-
target_link_libraries(binaryen_js PRIVATE "-sELIMINATE_DUPLICATE_FUNCTIONS")
577-
endif()
578-
# Disabling filesystem and setting web environment for js_of_ocaml
579-
# so it doesn't try to detect the "node" environment
580-
if(JS_OF_OCAML)
581-
target_link_libraries(binaryen_js PRIVATE "-sFILESYSTEM=0")
582-
target_link_libraries(binaryen_js PRIVATE "-sENVIRONMENT=web,worker")
583-
else()
584-
target_link_libraries(binaryen_js PRIVATE "-sFILESYSTEM=1")
585-
endif()
539+
target_link_libraries(binaryen_js PRIVATE "-sFILESYSTEM")
540+
target_link_libraries(binaryen_js PRIVATE "-sEXPORT_NAME=Binaryen")
586541
target_link_libraries(binaryen_js PRIVATE "-sNODERAWFS=0")
587542
# Do not error on the repeated NODERAWFS argument
588543
target_link_libraries(binaryen_js PRIVATE "-Wno-unused-command-line-argument")
544+
# Emit a single file for convenience of people using binaryen.js as a library,
545+
# so they only need to distribute a single file.
589546
if(EMSCRIPTEN_ENABLE_SINGLE_FILE)
590547
target_link_libraries(binaryen_js PRIVATE "-sSINGLE_FILE")
591548
endif()
592-
target_link_libraries(binaryen_js PRIVATE "-sEXPORT_NAME=Binaryen")
593-
# Currently, js_of_ocaml can only process ES5 code
594549
if(JS_OF_OCAML)
595-
target_link_libraries(binaryen_js PRIVATE "-sEXPORT_ES6=0")
550+
# js_of_ocaml needs a specified variable with special comment to provide the library to consumer
551+
target_link_libraries(binaryen_js PRIVATE "--extern-pre-js=${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.jsoo-extern-pre.js")
552+
# Currently, js_of_ocaml can only process ES5 code
553+
target_link_libraries(binaryen_js PRIVATE optimized "--closure-args=\"--language_out=ECMASCRIPT5\"")
596554
else()
597-
target_link_libraries(binaryen_js PRIVATE "-sEXPORT_ES6=1")
555+
# Currently, js_of_ocaml can only process ES5 code
556+
target_link_libraries(binaryen_js PRIVATE "-sEXPORT_ES6")
598557
endif()
599558
target_link_libraries(binaryen_js PRIVATE "-sEXPORTED_RUNTIME_METHODS=stringToUTF8OnStack,stringToAscii")
600559
target_link_libraries(binaryen_js PRIVATE "-sEXPORTED_FUNCTIONS=_malloc,_free")
601560
target_link_libraries(binaryen_js PRIVATE "--post-js=${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.js-post.js")
602-
# js_of_ocaml needs a specified variable with special comment to provide the library to consumers
603-
if(JS_OF_OCAML)
604-
target_link_libraries(binaryen_js PRIVATE "--extern-pre-js=${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.jsoo-extern-pre.js")
605-
endif()
561+
target_link_libraries(binaryen_js PRIVATE "-msign-ext")
562+
target_link_libraries(binaryen_js PRIVATE "-mbulk-memory")
606563
target_link_libraries(binaryen_js PRIVATE optimized "--closure=1")
607-
# Currently, js_of_ocaml can only process ES5 code
608-
if(JS_OF_OCAML)
609-
target_link_libraries(binaryen_js PRIVATE optimized "--closure-args=\"--language_out=ECMASCRIPT5\"")
610-
endif()
611564
# TODO: Fix closure warnings! (#5062)
612565
target_link_libraries(binaryen_js PRIVATE optimized "-Wno-error=closure")
613566
if(BYN_ENABLE_LTO)
614567
target_link_libraries(binaryen_js PRIVATE optimized "-flto")
615568
endif()
616569
target_link_libraries(binaryen_js PRIVATE debug "--profiling")
617-
target_link_libraries(binaryen_js PRIVATE debug "-sASSERTIONS")
618570
# Avoid catching exit as that can confuse error reporting in Node,
619571
# see https://github.com/emscripten-core/emscripten/issues/17228
620572
target_link_libraries(binaryen_js PRIVATE "-sNODEJS_CATCH_EXIT=0")

check.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,6 @@ def run():
362362
('example', run_example_tests),
363363
('unit', run_unittest),
364364
('binaryenjs', binaryenjs.test_binaryen_js),
365-
('binaryenjs_wasm', binaryenjs.test_binaryen_wasm),
366365
('lit', run_lit),
367366
('gtest', run_gtest),
368367
])
@@ -371,7 +370,7 @@ def run():
371370
# Run all the tests
372371
def main():
373372
all_suites = TEST_SUITES.keys()
374-
skip_by_default = ['binaryenjs', 'binaryenjs_wasm']
373+
skip_by_default = ['binaryenjs']
375374

376375
if shared.options.list_suites:
377376
for suite in all_suites:

scripts/emcc-tests.sh

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ set -o pipefail
55

66
SRCDIR="$(dirname $(dirname ${BASH_SOURCE[0]}))"
77

8+
mkdir -p emcc-build-dbg
9+
echo "emcc-tests: build dbg"
10+
emcmake cmake -S $SRCDIR -B emcc-build-dbg -DCMAKE_BUILD_TYPE=Debug -G Ninja
11+
ninja -C emcc-build-dbg binaryen_js
12+
echo "emcc-tests: test dbg"
13+
$SRCDIR/check.py --binaryen-bin=emcc-build-dbg/bin binaryenjs
14+
815
mkdir -p emcc-build
9-
echo "emcc-tests: build:wasm"
16+
echo "emcc-tests: build"
1017
emcmake cmake -S $SRCDIR -B emcc-build -DCMAKE_BUILD_TYPE=Release -G Ninja
11-
ninja -C emcc-build binaryen_wasm
12-
echo "emcc-tests: test:wasm"
13-
$SRCDIR/check.py --binaryen-bin=emcc-build/bin binaryenjs_wasm
14-
echo "emcc-tests: done:wasm"
15-
16-
echo "emcc-tests: build:js"
17-
ninja -C emcc-build binaryen_js
18-
echo "emcc-tests: test:js"
18+
ninja -C emcc-build binaryen_js
19+
echo "emcc-tests: test"
1920
$SRCDIR/check.py --binaryen-bin=emcc-build/bin binaryenjs
20-
echo "emcc-tests: done:js"
21+
echo "emcc-tests: done"

scripts/test/binaryenjs.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@ def make_js_test(input_js_file, binaryen_js):
4545
return outname
4646

4747

48-
def do_test_binaryen_js_with(which):
48+
def test_binaryen_js():
4949
if not (shared.MOZJS or shared.NODEJS):
5050
shared.fail_with_error('no vm to run binaryen.js tests')
5151

5252
node_has_wasm = shared.NODEJS and support.node_has_webassembly(shared.NODEJS)
53-
if not os.path.exists(which):
54-
shared.fail_with_error('no ' + which + ' build to test')
53+
if not os.path.exists(shared.BINARYEN_JS):
54+
shared.fail_with_error('no ' + shared.BINARYEN_JS + ' build to test')
5555

56-
print('\n[ checking binaryen.js testcases (' + which + ')... ]\n')
56+
print('\n[ checking binaryen.js testcases (' + shared.BINARYEN_JS + ')... ]\n')
5757

5858
for s in shared.get_tests(shared.get_test_dir('binaryen.js'), ['.js']):
59-
outname = make_js_test(s, which)
59+
outname = make_js_test(s, shared.BINARYEN_JS)
6060

6161
def test(cmd):
6262
if 'fatal' not in s:
@@ -110,11 +110,3 @@ def update(cmd):
110110
update([shared.NODEJS, outname])
111111
else:
112112
print('Skipping ' + s + ' because WebAssembly might not be supported')
113-
114-
115-
def test_binaryen_js():
116-
do_test_binaryen_js_with(shared.BINARYEN_JS)
117-
118-
119-
def test_binaryen_wasm():
120-
do_test_binaryen_js_with(shared.BINARYEN_WASM)

scripts/test/shared.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ def is_exe(fpath):
212212
WASM_EMSCRIPTEN_FINALIZE = [os.path.join(options.binaryen_bin,
213213
'wasm-emscripten-finalize')]
214214
BINARYEN_JS = os.path.join(options.binaryen_bin, 'binaryen_js.js')
215-
BINARYEN_WASM = os.path.join(options.binaryen_bin, 'binaryen_wasm.js')
216215

217216

218217
def wrap_with_valgrind(cmd):

0 commit comments

Comments
 (0)