Skip to content

Commit 519de4c

Browse files
authored
Cleanup use of EMCC_WASM_BACKEND env (#5327)
In some places were were checking EMCC_WASM_BACKEND directly. Rather than checking the environment or calculating it based on get_llvm_target() we should consistently using Settings.
1 parent a38d392 commit 519de4c

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

embuilder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def build_port(port_name, lib_name, params):
8787
tasks = sys.argv[2:]
8888
if 'ALL' in tasks:
8989
tasks = ['libc', 'libc-mt', 'dlmalloc', 'dlmalloc_threadsafe', 'pthreads', 'libcxx', 'libcxx_noexcept', 'libcxxabi', 'gl', 'binaryen', 'bullet', 'freetype', 'libpng', 'ogg', 'sdl2', 'sdl2-image', 'sdl2-ttf', 'sdl2-net', 'vorbis', 'zlib']
90-
if os.environ.get('EMCC_WASM_BACKEND') == '1':
90+
if shared.Settings.WASM_BACKEND:
9191
skip_tasks = {'libc-mt', 'dlmalloc_threadsafe', 'pthreads'}
9292
print('Skipping building of %s, because WebAssembly does not support pthreads.' % ', '.join(skip_tasks))
9393
tasks = [x for x in tasks if x not in skip_tasks]
@@ -160,7 +160,7 @@ def build_port(port_name, lib_name, params):
160160
int main() {}
161161
''', ['optimizer.2.exe'], ['-O2'])
162162
elif what == 'wasm_compiler_rt':
163-
if shared.get_llvm_target() == shared.WASM_TARGET:
163+
if shared.Settings.WASM_BACKEND:
164164
build('''
165165
int main() {}
166166
''', ['wasm_compiler_rt.a'], ['-s', 'WASM=1'])

emcc.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -887,9 +887,6 @@ def check(input_file):
887887
if shared.Settings.ASSERTIONS:
888888
shared.Settings.STACK_OVERFLOW_CHECK = 2
889889

890-
if shared.get_llvm_target() == shared.WASM_TARGET:
891-
shared.Settings.WASM_BACKEND = 1
892-
893890
if not shared.Settings.STRICT:
894891
# The preprocessor define EMSCRIPTEN is deprecated. Don't pass it to code in strict mode. Code should use the define __EMSCRIPTEN__ instead.
895892
shared.COMPILER_OPTS += ['-DEMSCRIPTEN']

tests/test_sanity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ def test_embuilder(self):
724724
([PYTHON, 'embuilder.py', 'build', 'cocos2d'], ['building and verifying cocos2d', 'success'], True, [os.path.join('ports-builds', 'Cocos2d', 'libCocos2d.bc')]),
725725
([PYTHON, 'embuilder.py', 'build', 'wasm-libc'], ['building and verifying wasm-libc', 'success'], True, ['wasm-libc.bc']),
726726
]
727-
if get_llvm_target() == WASM_TARGET:
727+
if Settings.WASM_BACKEND:
728728
tests.append(([PYTHON, 'embuilder.py', 'build', 'wasm_compiler_rt'], ['building and verifying wasm_compiler_rt', 'success'], True, ['wasm_compiler_rt.a']),)
729729

730730
for command, expected, success, result_libs in tests:

tools/cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def try_remove_ending(thestring, ending):
2828
self.filelock = filelock.FileLock(self.filelock_name)
2929

3030
if use_subdir:
31-
if os.environ.get('EMCC_WASM_BACKEND') and os.environ.get('EMCC_WASM_BACKEND') != '0':
31+
if shared.Settings.WASM_BACKEND:
3232
dirname = os.path.join(dirname, 'wasm')
3333
else:
3434
dirname = os.path.join(dirname, 'asmjs')

tools/shared.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def has_wasm_target(targets):
384384
def check_fastcomp():
385385
try:
386386
targets = get_llc_targets()
387-
if get_llvm_target() == ASM_JS_TARGET:
387+
if not Settings.WASM_BACKEND:
388388
if not has_asm_js_target(targets):
389389
logging.critical('fastcomp in use, but LLVM has not been built with the JavaScript backend as a target, llc reports:')
390390
print >> sys.stderr, '==========================================================================='
@@ -393,15 +393,14 @@ def check_fastcomp():
393393
logging.critical('you can fall back to the older (pre-fastcomp) compiler core, although that is not recommended, see http://kripken.github.io/emscripten-site/docs/building_from_source/LLVM-Backend.html')
394394
return False
395395
else:
396-
assert get_llvm_target() == WASM_TARGET
397396
if not has_wasm_target(targets):
398397
logging.critical('WebAssembly set as target, but LLVM has not been built with the WebAssembly backend, llc reports:')
399398
print >> sys.stderr, '==========================================================================='
400399
print >> sys.stderr, targets
401400
print >> sys.stderr, '==========================================================================='
402401
return False
403402

404-
if get_llvm_target() == ASM_JS_TARGET:
403+
if not Settings.WASM_BACKEND:
405404
# check repo versions
406405
d = get_fastcomp_src_dir()
407406
shown_repo_version_error = False
@@ -501,7 +500,7 @@ def get_emscripten_version(path):
501500
EMSCRIPTEN_VERSION = 'unknown'
502501

503502
def generate_sanity():
504-
return EMSCRIPTEN_VERSION + '|' + LLVM_ROOT + '|' + get_clang_version() + ('_wasm' if get_llvm_target() == WASM_TARGET else '')
503+
return EMSCRIPTEN_VERSION + '|' + LLVM_ROOT + '|' + get_clang_version() + ('_wasm' if Settings.WASM_BACKEND else '')
505504

506505
def check_sanity(force=False):
507506
ToolchainProfiler.enter_block('sanity')
@@ -514,7 +513,7 @@ def check_sanity(force=False):
514513
else:
515514
settings_mtime = os.stat(CONFIG_FILE).st_mtime
516515
sanity_file = CONFIG_FILE + '_sanity'
517-
if get_llvm_target() == WASM_TARGET:
516+
if Settings.WASM_BACKEND:
518517
sanity_file += '_wasm'
519518
if os.path.exists(sanity_file):
520519
try:
@@ -955,7 +954,6 @@ def get_vanilla_file():
955954
if is_vanilla:
956955
logging.debug('check tells us to use wasm backend')
957956
LLVM_TARGET = WASM_TARGET
958-
os.environ['EMCC_WASM_BACKEND'] = '1'
959957
else:
960958
logging.debug('check tells us to use asm.js backend')
961959
LLVM_TARGET = ASM_JS_TARGET
@@ -1171,6 +1169,9 @@ def load(self, args=[]):
11711169
declare = re.sub(r'([\w\d]+)\s*=\s*(.+)', r'self.attrs["\1"]=\2;', args[i+1])
11721170
exec declare
11731171

1172+
if get_llvm_target() == WASM_TARGET:
1173+
self.attrs['WASM_BACKEND'] = 1
1174+
11741175
# Transforms the Settings information into emcc-compatible args (-s X=Y, etc.). Basically
11751176
# the reverse of load_settings, except for -Ox which is relevant there but not here
11761177
@classmethod
@@ -1340,14 +1341,21 @@ def map(self, func, tasks):
13401341
Building.multiprocessing_pool = FakeMultiprocessor()
13411342
else:
13421343
child_env = [
1343-
# Multiprocessing pool children must have their current working directory set to a safe path that is guaranteed not to die in between of
1344-
# executing commands, or otherwise the pool children will have trouble spawning subprocesses of their own.
1344+
# Multiprocessing pool children must have their current working
1345+
# directory set to a safe path that is guaranteed not to die in
1346+
# between of executing commands, or otherwise the pool children will
1347+
# have trouble spawning subprocesses of their own.
13451348
'EMCC_POOL_CWD=' + path_from_root(),
1346-
# Multiprocessing pool children need to avoid all calling check_vanilla() again and again,
1347-
# otherwise the compiler can deadlock when building system libs, because the multiprocess parent can have the Emscripten cache directory locked for write
1348-
# access, and the EMCC_WASM_BACKEND check also requires locked access to the cache, which the multiprocess children would not get.
1349-
'EMCC_WASM_BACKEND=' + os.getenv('EMCC_WASM_BACKEND', '0'),
1350-
'EMCC_CORES=1' # Multiprocessing pool children can't spawn their own linear number of children, that could cause a quadratic amount of spawned processes.
1349+
# Multiprocessing pool children need to avoid all calling
1350+
# check_vanilla() again and again, otherwise the compiler can deadlock
1351+
# when building system libs, because the multiprocess parent can have
1352+
# the Emscripten cache directory locked for write access, and the
1353+
# EMCC_WASM_BACKEND check also requires locked access to the cache,
1354+
# which the multiprocess children would not get.
1355+
'EMCC_WASM_BACKEND=%s' % Settings.WASM_BACKEND,
1356+
# Multiprocessing pool children can't spawn their own linear number of
1357+
# children, that could cause a quadratic amount of spawned processes.
1358+
'EMCC_CORES=1'
13511359
]
13521360
Building.multiprocessing_pool = multiprocessing.Pool(processes=cores, initializer=g_multiprocessing_initializer, initargs=child_env)
13531361

0 commit comments

Comments
 (0)