diff --git a/emcc.py b/emcc.py index 48b55899c8f24..027b2a7066caf 100644 --- a/emcc.py +++ b/emcc.py @@ -664,6 +664,9 @@ def phase_parse_arguments(state): # warnings are properly printed during arg parse. newargs = diagnostics.capture_warnings(newargs) + if not diagnostics.is_enabled('deprecated'): + settings.WARN_DEPRECATED = 0 + for i in range(len(newargs)): if newargs[i] in ('-l', '-L', '-I', '-z'): # Scan for flags that can be written as either one or two arguments diff --git a/src/library_legacy.js b/src/library_legacy.js index bf0c0ef2cbb62..3b7a622ba6f7d 100644 --- a/src/library_legacy.js +++ b/src/library_legacy.js @@ -4,7 +4,7 @@ * SPDX-License-Identifier: MIT */ -addToLibrary({ +legacyFuncs = { $ALLOC_NORMAL: 0, // Tries to use _malloc() $ALLOC_STACK: 1, // Lives for the duration of the current function call @@ -120,4 +120,18 @@ addToLibrary({ }); }, #endif -}); +}; + +if (WARN_DEPRECATED && !INCLUDE_FULL_LIBRARY) { + for (const name of Object.keys(legacyFuncs)) { + if (!isDecorator(name)) { + depsKey = `${name}__deps`; + legacyFuncs[depsKey] = legacyFuncs[depsKey] || []; + legacyFuncs[depsKey].push(() => { + warn(`JS library symbols '${name}' is deprecated. Please open a bug if you have a continuing need for this symbol [-Wdeprecated]`); + }); + } + } +} + +addToLibrary(legacyFuncs); diff --git a/src/settings_internal.js b/src/settings_internal.js index 36a1887540a84..96fad541fad1a 100644 --- a/src/settings_internal.js +++ b/src/settings_internal.js @@ -273,3 +273,5 @@ var BULK_MEMORY = false; var MINIFY_WHITESPACE = true; var ASYNCIFY_IMPORTS_EXCEPT_JS_LIBS = []; + +var WARN_DEPRECATED = true; diff --git a/test/test_core.py b/test/test_core.py index 31e873d4462ce..1dd31b8966199 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -7113,6 +7113,7 @@ def test(expected, args=None, assert_returncode=0): # Adding the symbol to DEFAULT_LIBRARY_FUNCS_TO_INCLUDE should allow direct usage, but # Module usage should continue to fail. + self.emcc_args += ['-Wno-deprecated'] self.set_setting('DEFAULT_LIBRARY_FUNCS_TO_INCLUDE', ['$ALLOC_STACK']) test(not_exported, assert_returncode=NON_ZERO) test('1', args=['-DDIRECT']) diff --git a/test/test_other.py b/test/test_other.py index 5f5d0d4022c0c..2f0a41193c7c4 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -3670,11 +3670,11 @@ def test_exported_runtime_methods(self): def test_exported_runtime_methods_from_js_library(self): create_file('pre.js', ''' Module.onRuntimeInitialized = () => { - Module.setErrNo(88); + out(Module.ptrToString(88)); out('done'); }; ''') - self.do_runf('hello_world.c', 'done', emcc_args=['--pre-js=pre.js', '-sEXPORTED_RUNTIME_METHODS=setErrNo']) + self.do_runf('hello_world.c', 'done', emcc_args=['--pre-js=pre.js', '-sEXPORTED_RUNTIME_METHODS=ptrToString']) @crossplatform def test_fs_stream_proto(self): @@ -13376,6 +13376,7 @@ def test_legacy_runtime(self): # By default `LEGACY_RUNTIME` is disabled and `allocate` is not available. self.set_setting('EXPORTED_RUNTIME_METHODS', ['ALLOC_NORMAL']) + self.emcc_args += ['-Wno-deprecated'] self.do_runf('other/test_legacy_runtime.c', '`allocate` is a library symbol and not included by default; add it to your library.js __deps or to DEFAULT_LIBRARY_FUNCS_TO_INCLUDE on the command line', assert_returncode=NON_ZERO)