Skip to content

Commit 4697be4

Browse files
committed
Warn of usage of legacy library symbols
1 parent ed336f5 commit 4697be4

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

emcc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,9 @@ def phase_parse_arguments(state):
664664
# warnings are properly printed during arg parse.
665665
newargs = diagnostics.capture_warnings(newargs)
666666

667+
if not diagnostics.is_enabled('deprecated'):
668+
settings.WARN_DEPRECATED = 0
669+
667670
for i in range(len(newargs)):
668671
if newargs[i] in ('-l', '-L', '-I', '-z'):
669672
# Scan for flags that can be written as either one or two arguments

src/library_legacy.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: MIT
55
*/
66

7-
addToLibrary({
7+
legacyFuncs = {
88
$ALLOC_NORMAL: 0, // Tries to use _malloc()
99
$ALLOC_STACK: 1, // Lives for the duration of the current function call
1010

@@ -120,4 +120,18 @@ addToLibrary({
120120
});
121121
},
122122
#endif
123-
});
123+
};
124+
125+
if (WARN_DEPRECATED && !INCLUDE_FULL_LIBRARY) {
126+
for (const name of Object.keys(legacyFuncs)) {
127+
if (!isDecorator(name)) {
128+
depsKey = `${name}__deps`;
129+
legacyFuncs[depsKey] = legacyFuncs[depsKey] || [];
130+
legacyFuncs[depsKey].push(() => {
131+
warn(`JS library symbols '${name}' is deprecated. Please open a bug if you have a continuing need for this symbol [-Wdeprecated]`);
132+
});
133+
}
134+
}
135+
}
136+
137+
addToLibrary(legacyFuncs);

src/settings_internal.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,5 @@ var BULK_MEMORY = false;
273273
var MINIFY_WHITESPACE = true;
274274

275275
var ASYNCIFY_IMPORTS_EXCEPT_JS_LIBS = [];
276+
277+
var WARN_DEPRECATED = true;

test/test_core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7113,6 +7113,7 @@ def test(expected, args=None, assert_returncode=0):
71137113

71147114
# Adding the symbol to DEFAULT_LIBRARY_FUNCS_TO_INCLUDE should allow direct usage, but
71157115
# Module usage should continue to fail.
7116+
self.emcc_args += ['-Wno-deprecated']
71167117
self.set_setting('DEFAULT_LIBRARY_FUNCS_TO_INCLUDE', ['$ALLOC_STACK'])
71177118
test(not_exported, assert_returncode=NON_ZERO)
71187119
test('1', args=['-DDIRECT'])

test/test_other.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3670,11 +3670,11 @@ def test_exported_runtime_methods(self):
36703670
def test_exported_runtime_methods_from_js_library(self):
36713671
create_file('pre.js', '''
36723672
Module.onRuntimeInitialized = () => {
3673-
Module.setErrNo(88);
3673+
out(Module.ptrToString(88));
36743674
out('done');
36753675
};
36763676
''')
3677-
self.do_runf('hello_world.c', 'done', emcc_args=['--pre-js=pre.js', '-sEXPORTED_RUNTIME_METHODS=setErrNo'])
3677+
self.do_runf('hello_world.c', 'done', emcc_args=['--pre-js=pre.js', '-sEXPORTED_RUNTIME_METHODS=ptrToString'])
36783678

36793679
@crossplatform
36803680
def test_fs_stream_proto(self):
@@ -13376,6 +13376,7 @@ def test_legacy_runtime(self):
1337613376

1337713377
# By default `LEGACY_RUNTIME` is disabled and `allocate` is not available.
1337813378
self.set_setting('EXPORTED_RUNTIME_METHODS', ['ALLOC_NORMAL'])
13379+
self.emcc_args += ['-Wno-deprecated']
1337913380
self.do_runf('other/test_legacy_runtime.c',
1338013381
'`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',
1338113382
assert_returncode=NON_ZERO)

0 commit comments

Comments
 (0)