Skip to content

Commit

Permalink
Simplify gen_struct_info. NFC (emscripten-core#22327)
Browse files Browse the repository at this point in the history
In the past we had this script setup to run from emcc directly. Now that
it only runs as a standalone tool a lot of the complexity can be
removed.
  • Loading branch information
sbc100 authored Aug 7, 2024
1 parent 03fca01 commit 9150488
Showing 1 changed file with 8 additions and 28 deletions.
36 changes: 8 additions & 28 deletions tools/maint/gen_struct_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
from tools import shared
from tools import system_libs
from tools import utils
from tools.settings import settings

QUIET = (__name__ != '__main__')
DEBUG = False
Expand Down Expand Up @@ -239,7 +238,7 @@ def generate_c_code(headers):
return code


def generate_cmd(js_file_path, src_file_path, cflags, compiler_rt):
def generate_cmd(js_file_path, src_file_path, cflags):
# Compile the program.
show('Compiling generated code...')

Expand All @@ -255,8 +254,7 @@ def generate_cmd(js_file_path, src_file_path, cflags, compiler_rt):
'-O0',
'-Werror',
'-Wno-format',
'-nostdlib',
compiler_rt,
'-nolibc',
'-sBOOTSTRAPPING_STRUCT_INFO',
'-sINCOMING_MODULE_JS_API=',
'-sSTRICT',
Expand All @@ -270,14 +268,6 @@ def generate_cmd(js_file_path, src_file_path, cflags, compiler_rt):
# TODO(sbc): Remove this one we remove the test_em_config_env_var test
cmd += ['-Wno-deprecated']

if settings.LTO:
cmd += ['-flto=' + settings.LTO]

if settings.MEMORY64:
# Always use =2 here so that we don't generate binar that actually requires
# memeory64 to run. All we care about is that the output is correct.
cmd += ['-sMEMORY64=2', '-Wno-experimental']

show(shared.shlex_join(cmd))
return cmd

Expand All @@ -290,21 +280,11 @@ def inspect_headers(headers, cflags):
os.write(src_file_fd, '\n'.join(code).encode())
os.close(src_file_fd)

# Check sanity early on before populating the cache with libcompiler_rt
# If we don't do this the parallel build of compiler_rt will run while holding the cache
# lock and with EM_EXCLUSIVE_CACHE_ACCESS set causing N processes to race to run sanity checks.
# While this is not in itself serious problem it is wasteful and noise on stdout.
# For the same reason we run this early in embuilder.py and emcc.py.
# TODO(sbc): If we can remove EM_EXCLUSIVE_CACHE_ACCESS then this would not longer be needed.
shared.check_sanity()

compiler_rt = system_libs.Library.get_usable_variations()['libcompiler_rt'].build()

js_file_fd, js_file_path = tempfile.mkstemp('.js')
# Close the unneeded FD.
os.close(js_file_fd)

cmd = generate_cmd(js_file_path, src_file_path, cflags, compiler_rt)
cmd = generate_cmd(js_file_path, src_file_path, cflags)

try:
subprocess.check_call(cmd, env=system_libs.clean_env())
Expand All @@ -314,10 +294,8 @@ def inspect_headers(headers, cflags):

# Run the compiled program.
show('Calling generated program... ' + js_file_path)
args = []
if settings.MEMORY64:
args += shared.node_bigint_flags(config.NODE_JS)
info = shared.run_js_tool(js_file_path, node_args=args, stdout=shared.PIPE).splitlines()
node_args = shared.node_bigint_flags(config.NODE_JS)
info = shared.run_js_tool(js_file_path, node_args=node_args, stdout=shared.PIPE).splitlines()

if not DEBUG:
# Remove all temporary files.
Expand Down Expand Up @@ -423,7 +401,9 @@ def main(args):
extra_cflags = []

if args.wasm64:
settings.MEMORY64 = 2
# Always use =2 here so that we don't generate a binary that actually requires
# memory64 to run. All we care about is that the output is correct.
extra_cflags += ['-sMEMORY64=2', '-Wno-experimental']

# Add the user options to the list as well.
for path in args.includes:
Expand Down

0 comments on commit 9150488

Please sign in to comment.