Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions test/jslib/test_jslib_custom_settings.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
addToLibrary({
js_function: function() {
#if CUSTOM_JS_OPTION
return 1;
#else
return 0;
#endif
}
});
js_function: function() {
return {{{ CUSTOM_JS_OPTION }}};
}
});
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add new line at EOF

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just do js_function: () => {{{ CUSTOM_JS_OPTION }}} now.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe leave the #if in there to confirm that it can be used in pre-processor.

#if CUSTOM_JS_OPTION
js_function: () => {{{ CUSTOM_JS_OPTION }}},
#endif

11 changes: 8 additions & 3 deletions test/test_jslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,15 @@ def test_jslib_legacy(self):
# the -jsDfoo=val syntax:
# See https://github.com/emscripten-core/emscripten/issues/10580.
def test_jslib_custom_settings(self):
self.cflags += ['--js-library', test_file('jslib/test_jslib_custom_settings.js'), '-jsDCUSTOM_JS_OPTION=1']
self.do_run_in_out_file_test('jslib/test_jslib_custom_settings.c')
test_file_path = test_file('jslib/test_jslib_custom_settings.c')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need test_file there since do_runf knows to look for test files.

But not a big deal. lgtm

js_lib = test_file('jslib/test_jslib_custom_settings.js')

self.assert_fail([EMCC, '-jsDWASM=0'], 'cannot change built-in settings values with a -jsD directive')
self.do_runf(test_file_path, '1\n', cflags=['--js-library', js_lib, '-jsDCUSTOM_JS_OPTION=1'])

# verify that the settings can be specified more than once, and that the last one wins.
self.do_runf(test_file_path, '2\n', cflags=['--js-library', js_lib, '-jsDCUSTOM_JS_OPTION=1', '-jsDCUSTOM_JS_OPTION=2'])

self.assert_fail([EMCC, '-jsDWASM=1'], 'cannot change built-in settings values with a -jsD directive')

def test_jslib_native_deps(self):
# Verify that memset (which lives in compiled code), can be specified as a JS library
Expand Down
7 changes: 4 additions & 3 deletions tools/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def parse_args(newargs): # noqa: C901, PLR0912, PLR0915
"""
should_exit = False
skip = False
builtin_settings = set(settings.keys())
LEGACY_ARGS = {'--js-opts', '--llvm-opts', '--llvm-lto', '--memory-init-file'}
LEGACY_FLAGS = {'--separate-asm', '--jcache', '--proxy-to-worker', '--default-obj-ext',
'--embind-emit-tsd', '--remove-duplicates', '--no-heap-copy'}
Expand Down Expand Up @@ -572,12 +573,12 @@ def consume_arg_file():
elif arg.startswith('-jsD'):
key = arg.removeprefix('-jsD')
if '=' in key:
key, value = key.split('=')
key, value = key.split('=', 1)
else:
value = '1'
if key in settings.keys():
if key in builtin_settings:
exit_with_error(f'{arg}: cannot change built-in settings values with a -jsD directive. Pass -s{key}={value} instead!')
# Apply user -jsD settings
# Allow overrides/duplicates for user-defined -jsD flags
settings[key] = value
newargs[i] = ''
elif check_flag('-shared'):
Expand Down
Loading