Skip to content

Warn of usage of legacy library symbols #21357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2024
Merged
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
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 symbol '${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