Skip to content

Commit 56e1a90

Browse files
authored
Look for binaryen.js/wasm.js in install directory as well as source dir (emscripten-core#6407)
1 parent b40183b commit 56e1a90

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

emcc.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ def exit_with_error(message):
106106

107107
class Intermediate(object):
108108
counter = 0
109-
# this method uses the global 'final' variable, which contains the current
109+
110+
# this function uses the global 'final' variable, which contains the current
110111
# final output file. if a method alters final, and calls this method, then it
111112
# must modify final globally (i.e. it can't receive final as a param and
112113
# return it)
@@ -119,6 +120,7 @@ def save_intermediate(name=None, suffix='js'):
119120
return
120121
shutil.copyfile(final, name)
121122
Intermediate.counter += 1
123+
122124
def save_intermediate_with_wasm(name, wasm_binary):
123125
save_intermediate(name) # save the js
124126
name = os.path.join(shared.get_emscripten_temp_dir(), 'emcc-%d-%s.wasm' % (Intermediate.counter - 1, name))
@@ -2297,6 +2299,7 @@ def do_binaryen(target, asm_target, options, memfile, wasm_binary_target,
22972299
global final
22982300
logging.debug('using binaryen, with method: ' + shared.Settings.BINARYEN_METHOD)
22992301
binaryen_bin = shared.Building.get_binaryen_bin()
2302+
binaryen_lib = shared.Building.get_binaryen_lib()
23002303
# Emit wasm.js at the top of the js. This is *not* optimized with the rest of the code, since
23012304
# (1) it contains asm.js, whose validation would be broken, and (2) it's very large so it would
23022305
# be slow in cleanup/JSDCE etc.
@@ -2305,7 +2308,7 @@ def do_binaryen(target, asm_target, options, memfile, wasm_binary_target,
23052308
# BINARYEN_METHOD with something that doesn't use the polyfill, then we don't need it.
23062309
if not shared.Settings.BINARYEN_METHOD or 'interpret' in shared.Settings.BINARYEN_METHOD:
23072310
logging.debug('integrating wasm.js polyfill interpreter')
2308-
wasm_js = open(os.path.join(binaryen_bin, 'wasm.js')).read()
2311+
wasm_js = open(os.path.join(binaryen_lib, 'wasm.js')).read()
23092312
wasm_js = wasm_js.replace('EMSCRIPTEN_', 'emscripten_') # do not confuse the markers
23102313
js = open(final).read()
23112314
combined = open(final, 'w')

tools/shared.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2363,7 +2363,7 @@ def path_to_system_js_libraries(library_name):
23632363
else:
23642364
if Settings.ERROR_ON_MISSING_LIBRARIES:
23652365
logging.fatal('emcc: cannot find library "%s"', library_name)
2366-
exit(1)
2366+
sys.exit(1)
23672367
else:
23682368
logging.warning('emcc: cannot find library "%s"', library_name)
23692369

@@ -2396,6 +2396,19 @@ def get_binaryen_bin():
23962396
Building.get_binaryen()
23972397
return os.path.join(Settings.BINARYEN_ROOT, 'bin')
23982398

2399+
@staticmethod
2400+
def get_binaryen_lib():
2401+
Building.get_binaryen()
2402+
# The wasm.js and binaryen.js libraries live in 'bin' in the binaryen
2403+
# source tree, but are installed to share/binaryen.
2404+
paths = (os.path.join(Settings.BINARYEN_ROOT, 'bin'),
2405+
os.path.join(Settings.BINARYEN_ROOT, 'share', 'binaryen'))
2406+
for dirname in paths:
2407+
if os.path.exists(os.path.join(dirname, 'binaryen.js')):
2408+
return dirname
2409+
logging.fatal('emcc: cannot find binaryen js libraries (tried: %s)' % str(paths))
2410+
sys.exit(1)
2411+
23992412
# compatibility with existing emcc, etc. scripts
24002413
Cache = cache.Cache(debug=DEBUG_CACHE)
24012414
chunkify = cache.chunkify

0 commit comments

Comments
 (0)