Skip to content

Commit

Permalink
Warn of usage of legacy library symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed Feb 15, 2024
1 parent ed336f5 commit 4697be4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
3 changes: 3 additions & 0 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions src/library_legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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);
2 changes: 2 additions & 0 deletions src/settings_internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,5 @@ var BULK_MEMORY = false;
var MINIFY_WHITESPACE = true;

var ASYNCIFY_IMPORTS_EXCEPT_JS_LIBS = [];

var WARN_DEPRECATED = true;
1 change: 1 addition & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
5 changes: 3 additions & 2 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4697be4

Please sign in to comment.