Skip to content

Commit 3958ea8

Browse files
authored
Support different node flags for different versions of node. (emscripten-core#18070)
This is mostly about what flags to pass to node during testing, but also applies to `CMAKE_CROSSCOMPILING_EMULATOR` and to the #! used in autoconf tests.
1 parent 9a824c9 commit 3958ea8

10 files changed

Lines changed: 75 additions & 22 deletions

File tree

.circleci/config.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ executors:
77
linux-node:
88
docker:
99
- image: circleci/node:stretch
10+
linux-python:
11+
docker:
12+
- image: cimg/python:3.10.7
1013
bionic:
1114
docker:
1215
- image: emscripten/emscripten-ci
@@ -44,7 +47,7 @@ commands:
4447
- run:
4548
name: emsdk_env.sh
4649
command: |
47-
echo "EMSDK_QUIET=1 source ~/emsdk/emsdk_env.sh" >> $BASH_ENV
50+
EMSDK_BASH=1 ~/emsdk/emsdk construct_env >> $BASH_ENV
4851
# In order make our external version of emscripten use the emsdk
4952
# config we need to explictly set EM_CONFIG here.
5053
echo "export EM_CONFIG=~/emsdk/.emscripten" >> $BASH_ENV
@@ -469,6 +472,28 @@ jobs:
469472
test_targets: "wasm64"
470473
- run-tests:
471474
test_targets: "wasm64l"
475+
test-latest-node:
476+
executor: linux-python
477+
steps:
478+
- checkout
479+
- run:
480+
name: submodule update
481+
command: git submodule update --init
482+
- pip-install
483+
- build
484+
- run:
485+
name: get node
486+
command: |
487+
cd $HOME
488+
wget https://nodejs.org/dist/v19.0.0/node-v19.0.0-linux-x64.tar.xz
489+
tar xf node-v19.0.0-linux-x64.tar.xz
490+
echo "export EM_JS_ENGINES=$HOME/node-v19.0.0-linux-x64/bin/node" >> $BASH_ENV
491+
echo "export EM_NODE_JS=$HOME/node-v19.0.0-linux-x64/bin/node" >> $BASH_ENV
492+
echo "export PATH=\"$HOME/node-v19.0.0-linux-x64/bin:\$PATH\"" >> $BASH_ENV
493+
- run-tests:
494+
# Run tests that on older versions of node would require flags, but
495+
# those flags should not be injected on newer versions.
496+
test_targets: "-v core2.test_pthread_create core2.test_i64_invoke_bigint"
472497
test-other:
473498
executor: bionic
474499
steps:
@@ -628,5 +653,6 @@ workflows:
628653
- test-sockets-chrome:
629654
requires:
630655
- build-linux
656+
- test-latest-node
631657
- test-windows
632658
- test-mac

emcc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ def make_js_executable(script):
631631
src = read_file(script)
632632
cmd = config.JS_ENGINES[0]
633633
if settings.WASM_BIGINT:
634-
cmd.append('--experimental-wasm-bigint')
634+
cmd += shared.node_bigint_flags()
635635
cmd = shared.shlex_join(cmd)
636636
if not os.path.isabs(cmd[0]):
637637
# TODO: use whereis etc. And how about non-*NIX?

emcmake.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ def has_substr(args, substr):
3535
args.append('-DCMAKE_TOOLCHAIN_FILE=' + utils.path_from_root('cmake/Modules/Platform/Emscripten.cmake'))
3636

3737
if not has_substr(args, '-DCMAKE_CROSSCOMPILING_EMULATOR'):
38-
node_js = config.NODE_JS[0]
39-
# In order to allow cmake to run code built with pthreads we need to pass some extra flags to node.
40-
# Note that we also need --experimental-wasm-bulk-memory which is true by default and hence not added here
38+
node_js = [config.NODE_JS[0]]
39+
# In order to allow cmake to run code built with pthreads we need to pass
40+
# some extra flags to node.
41+
node_js += shared.node_pthread_flags()
42+
node_js = ';'.join(node_js)
4143
# See https://github.com/emscripten-core/emscripten/issues/15522
42-
args.append(f'-DCMAKE_CROSSCOMPILING_EMULATOR={node_js};--experimental-wasm-threads')
44+
args.append(f'-DCMAKE_CROSSCOMPILING_EMULATOR={node_js}')
4345

4446
# On Windows specify MinGW Makefiles or ninja if we have them and no other
4547
# toolchain was specified, to keep CMake from pulling in a native Visual

src/runtime_init_memory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ if (ENVIRONMENT_IS_PTHREAD) {
4343
if (!(wasmMemory.buffer instanceof SharedArrayBuffer)) {
4444
err('requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag');
4545
if (ENVIRONMENT_IS_NODE) {
46-
err('(on node you may need: --experimental-wasm-threads --experimental-wasm-bulk-memory and also use a recent version)');
46+
err('(on node you may need: --experimental-wasm-threads --experimental-wasm-bulk-memory and/or recent version)');
4747
}
4848
throw Error('bad memory');
4949
}

test/common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def metafunc(self, with_bigint):
260260
self.skipTest('redundant in bigint test config')
261261
self.set_setting('WASM_BIGINT')
262262
self.require_node()
263-
self.node_args.append('--experimental-wasm-bigint')
263+
self.node_args += shared.node_bigint_flags()
264264
f(self)
265265
else:
266266
f(self)
@@ -457,7 +457,7 @@ def setup_node_pthreads(self):
457457
if self.get_setting('MINIMAL_RUNTIME'):
458458
self.skipTest('node pthreads not yet supported with MINIMAL_RUNTIME')
459459
self.js_engines = [config.NODE_JS]
460-
self.node_args += ['--experimental-wasm-threads', '--experimental-wasm-bulk-memory']
460+
self.node_args += shared.node_pthread_flags()
461461

462462
def uses_memory_init_file(self):
463463
if self.get_setting('SIDE_MODULE') or (self.is_wasm() and not self.get_setting('WASM2JS')):
@@ -1799,7 +1799,7 @@ def btest(self, filename, expected=None, reference=None,
17991799
expected = [expected]
18001800
if EMTEST_BROWSER == 'node':
18011801
self.js_engines = [config.NODE_JS]
1802-
self.node_args += ['--experimental-wasm-threads', '--experimental-wasm-bulk-memory']
1802+
self.node_args += shared.node_pthread_flags()
18031803
output = self.run_js('test.js')
18041804
self.assertContained('RESULT: ' + expected[0], output)
18051805
else:

test/test_core.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def metafunc(self, standalone):
240240
if impure:
241241
self.wasm_engines = []
242242
self.js_engines = [config.NODE_JS]
243-
self.node_args.append('--experimental-wasm-bigint')
243+
self.node_args += shared.node_bigint_flags()
244244
func(self)
245245
if wasm2c:
246246
print('wasm2c')
@@ -576,7 +576,7 @@ def test_i64_varargs(self):
576576
def test_i64_invoke_bigint(self):
577577
self.set_setting('WASM_BIGINT')
578578
self.emcc_args += ['-fexceptions']
579-
self.node_args += ['--experimental-wasm-bigint']
579+
self.node_args += shared.node_bigint_flags()
580580
self.do_core_test('test_i64_invoke_bigint.cpp')
581581

582582
def test_vararg_copy(self):
@@ -2277,7 +2277,7 @@ def test_em_js_i64(self):
22772277
self.assertContained('emcc: error: using 64-bit arguments in EM_JS function without WASM_BIGINT is not yet fully supported: `foo`', err)
22782278

22792279
self.set_setting('WASM_BIGINT')
2280-
self.node_args += ['--experimental-wasm-bigint']
2280+
self.node_args += shared.node_bigint_flags()
22812281
self.do_core_test('test_em_js_i64.c')
22822282

22832283
def test_runtime_stacksave(self):
@@ -7006,7 +7006,7 @@ def test_wasm2c_sandboxing(self, mode):
70067006
# mode. this happens to work without wasmfs, but with wasmfs we get the
70077007
# time when we create/update a file, which uses clock_time_get that has an
70087008
# i64 param. For such an import to work we need wasm-bigint support.
7009-
self.node_args.append('--experimental-wasm-bigint')
7009+
self.node_args += shared.node_bigint_flags()
70107010
if not can_do_standalone(self):
70117011
return self.skipTest('standalone mode not supported')
70127012
self.set_setting('STANDALONE_WASM')
@@ -7580,14 +7580,14 @@ def test_embind_dynamic_initialization(self):
75807580
def test_embind_i64_val(self):
75817581
self.set_setting('WASM_BIGINT')
75827582
self.emcc_args += ['-lembind']
7583-
self.node_args += ['--experimental-wasm-bigint']
7583+
self.node_args += shared.node_bigint_flags()
75847584
self.do_run_in_out_file_test('embind/test_i64_val.cpp', assert_identical=True)
75857585

75867586
@no_wasm2js('wasm_bigint')
75877587
def test_embind_i64_binding(self):
75887588
self.set_setting('WASM_BIGINT')
75897589
self.emcc_args += ['-lembind']
7590-
self.node_args += ['--experimental-wasm-bigint']
7590+
self.node_args += shared.node_bigint_flags()
75917591
self.do_run_in_out_file_test('embind/test_i64_binding.cpp', assert_identical=True)
75927592

75937593
def test_embind_no_rtti(self):
@@ -9637,7 +9637,7 @@ def setUp(self):
96379637
# MEMORY64=2, or "lowered"
96389638
wasm64l = make_run('wasm64l', emcc_args=['-Wno-experimental', '--profiling-funcs'],
96399639
settings={'MEMORY64': 2},
9640-
node_args=['--experimental-wasm-bigint'])
9640+
node_args=shared.node_bigint_flags())
96419641

96429642
lto0 = make_run('lto0', emcc_args=['-flto', '-O0'])
96439643
lto1 = make_run('lto1', emcc_args=['-flto', '-O1'])
@@ -9674,7 +9674,7 @@ def setUp(self):
96749674
core2ss = make_run('core2ss', emcc_args=['-O2'], settings={'STACK_OVERFLOW_CHECK': 2})
96759675

96769676
bigint = make_run('bigint', emcc_args=['--profiling-funcs'], settings={'WASM_BIGINT': 1},
9677-
node_args=['--experimental-wasm-bigint'])
9677+
node_args=shared.node_bigint_flags())
96789678

96799679
# Add DEFAULT_TO_CXX=0
96809680
strict = make_run('strict', emcc_args=[], settings={'STRICT': 1})

test/test_other.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6844,7 +6844,7 @@ def test_i64_return_value(self, args, bind_js):
68446844
''')
68456845

68466846
# Run the test and confirm the output is as expected.
6847-
out = self.run_js('testrun.js', engine=config.NODE_JS + ['--experimental-wasm-bigint'])
6847+
out = self.run_js('testrun.js', engine=config.NODE_JS + shared.node_bigint_flags())
68486848
self.assertContained('''\
68496849
input = 0xaabbccdd11223344
68506850
low = 5678
@@ -12106,7 +12106,7 @@ def test_wasmfs_readfile(self):
1210612106
@wasmfs_all_backends
1210712107
def test_wasmfs_readfile_bigint(self):
1210812108
self.set_setting('WASM_BIGINT')
12109-
self.node_args += ['--experimental-wasm-bigint']
12109+
self.node_args += shared.node_bigint_flags()
1211012110
self.do_run_in_out_file_test(test_file('wasmfs/wasmfs_readfile.c'))
1211112111

1211212112
def test_wasmfs_jsfile(self):
@@ -12319,7 +12319,7 @@ def test_error_in_js_libraries(self):
1231912319
@also_with_minimal_runtime
1232012320
def test_shared_memory(self):
1232112321
self.do_runf(test_file('wasm_worker/shared_memory.c'), '0', emcc_args=[])
12322-
self.node_args += ['--experimental-wasm-threads', '--experimental-wasm-bulk-memory']
12322+
self.node_args += shared.node_pthread_flags()
1232312323
self.do_runf(test_file('wasm_worker/shared_memory.c'), '1', emcc_args=['-sSHARED_MEMORY'])
1232412324
self.do_runf(test_file('wasm_worker/shared_memory.c'), '1', emcc_args=['-sWASM_WORKERS'])
1232512325
self.do_runf(test_file('wasm_worker/shared_memory.c'), '1', emcc_args=['-pthread'])

tools/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ def parse_config_file():
135135
if env_value is not None:
136136
if env_value in ('', '0'):
137137
env_value = None
138+
# Unlike the other keys these two should always be lists.
139+
if key in ('JS_ENGINES', 'WASM_ENGINES'):
140+
env_value = env_value.split(',')
138141
globals()[key] = env_value
139142
elif key in config:
140143
globals()[key] = config[key]

tools/gen_struct_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def inspect_headers(headers, cflags):
301301
show('Calling generated program... ' + js_file[1])
302302
args = []
303303
if settings.MEMORY64:
304-
args += ['--experimental-wasm-bigint']
304+
args += shared.node_bigint_flags()
305305
info = shared.run_js_tool(js_file[1], node_args=args, stdout=shared.PIPE).splitlines()
306306

307307
if not DEBUG:

tools/shared.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ def env_with_node_in_path():
328328
return env
329329

330330

331+
@memoize
331332
def check_node_version():
332333
try:
333334
actual = run_process(config.NODE_JS + ['--version'], stdout=PIPE).stdout.strip()
@@ -336,11 +337,32 @@ def check_node_version():
336337
version = tuple(int(v) for v in version)
337338
except Exception as e:
338339
diagnostics.warning('version-check', 'cannot check node version: %s', e)
340+
return
339341

340342
if version < MINIMUM_NODE_VERSION:
341343
expected = '.'.join(str(v) for v in MINIMUM_NODE_VERSION)
342344
diagnostics.warning('version-check', f'node version appears too old (seeing "{actual}", expected "v{expected}")')
343345

346+
return version
347+
348+
349+
def node_bigint_flags():
350+
node_version = check_node_version()
351+
# wasm bigint was enabled by default in node v16.
352+
if node_version and node_version < (16, 0, 0):
353+
return ['--experimental-wasm-bigint']
354+
else:
355+
return []
356+
357+
358+
def node_pthread_flags():
359+
node_version = check_node_version()
360+
# bulk memory and wasm threads were enabled by default in node v16.
361+
if node_version and node_version < (16, 0, 0):
362+
return ['--experimental-wasm-bulk-memory', '--experimental-wasm-threads']
363+
else:
364+
return []
365+
344366

345367
@memoize
346368
@ToolchainProfiler.profile()

0 commit comments

Comments
 (0)