Skip to content

Commit 95b8d55

Browse files
authored
Set MIN_x_VERSION as unsupported when not targeting ENVIRONMENT (#24376)
If `ENVIRONMENT` doesn't contain `node`, treat `MIN_NODE_VERSION` as unsupported, and vice versa - if `ENVIRONMENT` only contains `node`, treat all browser `MIN_*_VERSION` as unsupported. Will show a warning if user specified their own `MIN_*_VERSION` despite corresponding environment not being targeted. Fixes #20561.
1 parent 738a9a9 commit 95b8d55

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

test/test_other.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16099,3 +16099,23 @@ def test_em_js_bool_macro_expansion(self):
1609916099

1610016100
def test_getifaddrs(self):
1610116101
self.do_other_test('test_getifaddrs.c')
16102+
16103+
@parameterized({
16104+
'web': ('web',),
16105+
'node': ('node',),
16106+
})
16107+
def test_unsupported_min_version_when_unsupported_env(self, env):
16108+
create_file('pre.js', '''
16109+
#preprocess
16110+
var MIN_NODE_VERSION = {{{ MIN_NODE_VERSION }}};
16111+
var MIN_CHROME_VERSION = {{{ MIN_CHROME_VERSION }}};
16112+
var MIN_SAFARI_VERSION = {{{ MIN_SAFARI_VERSION }}};
16113+
var MIN_FIREFOX_VERSION = {{{ MIN_FIREFOX_VERSION }}};
16114+
''')
16115+
self.emcc(test_file('hello_world.c'), [f'-sENVIRONMENT={env}', '--pre-js=pre.js'])
16116+
src = read_file('a.out.js')
16117+
unsupported = 0x7FFFFFFF
16118+
self.assertContainedIf(f'var MIN_NODE_VERSION = {unsupported};', src, env == 'web')
16119+
self.assertContainedIf(f'var MIN_CHROME_VERSION = {unsupported};', src, env == 'node')
16120+
self.assertContainedIf(f'var MIN_SAFARI_VERSION = {unsupported};', src, env == 'node')
16121+
self.assertContainedIf(f'var MIN_FIREFOX_VERSION = {unsupported};', src, env == 'node')

tools/link.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,18 @@ def setup_environment_settings():
171171
settings.ENVIRONMENT_MAY_BE_NODE = not settings.ENVIRONMENT or 'node' in environments
172172
settings.ENVIRONMENT_MAY_BE_SHELL = not settings.ENVIRONMENT or 'shell' in environments
173173

174+
if not settings.ENVIRONMENT_MAY_BE_NODE:
175+
if 'MIN_NODE_VERSION' in user_settings:
176+
diagnostics.warning('unused-command-line-argument', 'ignoring MIN_NODE_VERSION because `node` environment is not enabled')
177+
settings.MIN_NODE_VERSION = feature_matrix.UNSUPPORTED
178+
179+
if not (settings.ENVIRONMENT_MAY_BE_WEB or settings.ENVIRONMENT_MAY_BE_WEBVIEW):
180+
for browser in ('FIREFOX', 'SAFARI', 'CHROME'):
181+
key = f'MIN_{browser}_VERSION'
182+
if key in user_settings:
183+
diagnostics.warning('unused-command-line-argument', 'ignoring %s because `web` and `webview` environments are not enabled', key)
184+
settings[key] = feature_matrix.UNSUPPORTED
185+
174186
# The worker case also includes Node.js workers when pthreads are
175187
# enabled and Node.js is one of the supported environments for the build to
176188
# run on. Node.js workers are detected as a combination of
@@ -2041,8 +2053,7 @@ def run_embind_gen(options, wasm_target, js_syms, extra_settings):
20412053
dirname, basename = os.path.split(lib)
20422054
if basename == 'libembind.js':
20432055
settings.JS_LIBRARIES[i] = os.path.join(dirname, 'libembind_gen.js')
2044-
if settings.MEMORY64:
2045-
settings.MIN_NODE_VERSION = 160000
2056+
settings.MIN_NODE_VERSION = 160000 if settings.MEMORY64 else 150000
20462057
# Source maps haven't been generated yet and aren't needed to run embind_gen.
20472058
settings.LOAD_SOURCE_MAP = 0
20482059
outfile_js = in_temp('tsgen.js')

0 commit comments

Comments
 (0)