From 7506c70c0766cc78a376dc5def70fd6906583fda Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 3 Jan 2024 16:27:29 -0800 Subject: [PATCH] Add list of JS-only settings --- ChangeLog.md | 2 ++ test/test_other.py | 4 ++++ tools/link.py | 7 ++++++- tools/settings.py | 21 +++++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 4d5b1e9eedfe2..e24fe2b2c8aa2 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -20,6 +20,8 @@ See docs/process.md for more on how version tagging works. 3.1.52 (in development) ----------------------- +- Certain settings that only apply when generating JavaScript output will now + trigger a warning if used when generating only Wasm. - Fix bug where `main` was mistakenly included in debug builds but not in release builds. (#20971) - Remove JAVA from the list of `.emscripten` config file settings. In the diff --git a/test/test_other.py b/test/test_other.py index 3b8a0a99937c8..ea1aa4b265068 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -14414,3 +14414,7 @@ def test_no_extra_output(self): def test_browser_too_old(self): err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sMIN_CHROME_VERSION=10']) self.assertContained('emcc: error: MIN_CHROME_VERSION older than 32 is not supported', err) + + def test_js_only_settings(self): + err = self.run_process([EMCC, test_file('hello_world.c'), '-o', 'foo.wasm', '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=emscripten_get_heap_max'], stderr=PIPE).stderr + self.assertContained('emcc: warning: DEFAULT_LIBRARY_FUNCS_TO_INCLUDE is only valid when generated JavaScript output', err) diff --git a/tools/link.py b/tools/link.py index 6f438b695418f..864f270980664 100644 --- a/tools/link.py +++ b/tools/link.py @@ -38,7 +38,7 @@ from .shared import in_temp, safe_copy, do_replace, run_process, OFormat from .shared import DEBUG, WINDOWS, DYNAMICLIB_ENDINGS, STATICLIB_ENDINGS from .shared import unsuffixed, unsuffixed_basename, get_file_suffix -from .settings import settings, default_setting, user_settings +from .settings import settings, default_setting, user_settings, JS_ONLY_SETTINGS from .minimal_runtime_shell import generate_minimal_runtime_html import tools.line_endings @@ -753,6 +753,11 @@ def phase_linker_setup(options, state, newargs): else: options.oformat = OFormat.JS + if options.oformat in (OFormat.WASM, OFormat.OBJECT): + for s in JS_ONLY_SETTINGS: + if s in user_settings: + diagnostics.warning('unused-command-line-argument', f'{s} is only valid when generated JavaScript output') + if options.oformat == OFormat.MJS: settings.EXPORT_ES6 = 1 settings.MODULARIZE = 1 diff --git a/tools/settings.py b/tools/settings.py index 8c13ada6d77c6..67d01f2b98859 100644 --- a/tools/settings.py +++ b/tools/settings.py @@ -54,6 +54,27 @@ 'USE_SQLITE3', } +# Subset of settings that apply only when generating JS +JS_ONLY_SETTINGS = { + 'DEFAULT_LIBRARY_FUNCS_TO_INCLUDE', + 'INCLUDE_FULL_LIBRARY', + 'PROXY_TO_WORKER', + 'PROXY_TO_WORKER_FILENAME', + 'BUILD_AS_WORKER', + 'STRICT_JS', + 'SMALL_XHR_CHUNKS', + 'HEADLESS', + 'MODULARIZE', + 'EXPORT_ES6', + 'USE_ES6_IMPORT_META', + 'EXPORT_NAME', + 'DYNAMIC_EXECUTION', + 'PTHREAD_POOL_SIZE', + 'PTHREAD_POOL_SIZE_STRICT', + 'PTHREAD_POOL_DELAY_LOAD', + 'DEFAULT_PTHREAD_STACK_SIZE', +} + # Subset of settings that apply at compile time. # (Keep in sync with [compile] comments in settings.js) COMPILE_TIME_SETTINGS = {