Skip to content

Commit 998f631

Browse files
committed
Add #! line to top of JS file
Previously we could only add this when we detect that we running under autoconf. With this change we now default to outputting a JS file that is executable unless as long as we are possibly targetting node (ENVIRONMENT_MAY_BE_NODE) and we are not optimizing for size (`-Oz` or `-Os`). Also, conditionally add `--experimental-wasm-threads` to the node command (similar to what we did in #15590) used in the #! line.
1 parent 8a4747c commit 998f631

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

ChangeLog.md

+4
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ See docs/process.md for more on how version tagging works.
159159
processed as the last item after all system provided JS libraries have been
160160
added to the build. This fix enables overriding WebGL 2 symbols from user JS
161161
libraries.
162+
- The JavaScript file output by emscripten is now marked as executable and
163+
given a `#!` line to run under node, as long as node is a possible
164+
`ENVIRONMENT` and `-Oz` or `-Os` is not used (since this adds a few bytes
165+
to the resulting JavaScript file).
162166

163167
3.0.0 - 11/22/2021
164168
------------------

emcc.py

+8
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,8 @@ def check_human_readable_list(items):
605605
def make_js_executable(script):
606606
src = read_file(script)
607607
cmd = shared.shlex_join(config.JS_ENGINE)
608+
if settings.USE_PTHREADS:
609+
cmd += ' --experimental-wasm-threads'
608610
if not os.path.isabs(config.JS_ENGINE[0]):
609611
# TODO: use whereis etc. And how about non-*NIX?
610612
cmd = '/usr/bin/env -S ' + cmd
@@ -1567,6 +1569,12 @@ def phase_linker_setup(options, state, newargs, user_settings):
15671569
# Add `#!` line to output JS and make it executable.
15681570
options.executable = True
15691571

1572+
if settings.ENVIRONMENT_MAY_BE_NODE and not settings.SHRINK_LEVEL:
1573+
# Older browsers don't support ignoring the #! line
1574+
# https://github.com/tc39/proposal-hashbang
1575+
if settings.MIN_CHROME_VERSION < 74 or settings.MIN_FIREFOX_VERSION < 67 or settings.MIN_IE_VERSION != 0x7fffffff:
1576+
options.executable = True
1577+
15701578
ldflags = emsdk_ldflags(newargs)
15711579
for f in ldflags:
15721580
add_link_flag(state, sys.maxsize, f)

tests/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ def verify_es5(self, filename):
589589
# ES-Check: there were no ES version matching errors!
590590
# pipe stdout and stderr so that we can choose if/when to print this
591591
# output and avoid spamming stdout when tests are successful.
592-
shared.run_process(es_check + ['es5', os.path.abspath(filename)], stdout=PIPE, stderr=STDOUT, env=es_check_env)
592+
shared.run_process(es_check + ['es5', os.path.abspath(filename), '--allow-hash-bang'], stdout=PIPE, stderr=STDOUT, env=es_check_env)
593593
except subprocess.CalledProcessError as e:
594594
print(e.stdout)
595595
self.fail('es-check failed to verify ES5 output compliance')

0 commit comments

Comments
 (0)