Skip to content

Commit b5e5ff8

Browse files
authored
Extend support for -### flag to optimized linking (#22877)
This will cause the ### flag to print most Binaryen and acorn-optimizer subcommands in addtion to clang and ld. However accuracy isn't perfect because some steps (E.g. metadce) depend on the output of previous steps.
1 parent 4b3bace commit b5e5ff8

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

test/test_other.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,11 @@ def test_log_subcommands(self):
321321

322322
def test_skip_subcommands(self):
323323
# The -### flag is like `-v` but it doesn't actaully execute the sub-commands
324-
proc = self.run_process([EMCC, '-###', test_file('hello_world.c')], stdout=PIPE, stderr=PIPE)
324+
proc = self.run_process([EMCC, '-###', '-O3', test_file('hello_world.c')], stdout=PIPE, stderr=PIPE)
325325
self.assertContained(CLANG_CC, proc.stderr)
326326
self.assertContained(WASM_LD, proc.stderr)
327+
self.assertContained('wasm-opt', proc.stderr)
328+
self.assertContained('acorn-optimizer.mjs', proc.stderr)
327329
self.assertNotExists('a.out.js')
328330

329331
def test_emcc_check(self):

tools/building.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def js_optimizer(filename, passes):
348348
def acorn_optimizer(filename, passes, extra_info=None, return_output=False, worker_js=False):
349349
optimizer = path_from_root('tools/acorn-optimizer.mjs')
350350
original_filename = filename
351-
if extra_info is not None:
351+
if extra_info is not None and not shared.SKIP_SUBPROCS:
352352
temp_files = shared.get_temp_files()
353353
temp = temp_files.get('.js', prefix='emcc_acorn_info_').name
354354
shutil.copyfile(filename, temp)
@@ -366,6 +366,9 @@ def acorn_optimizer(filename, passes, extra_info=None, return_output=False, work
366366
if settings.VERBOSE:
367367
cmd += ['--verbose']
368368
if return_output:
369+
shared.print_compiler_stage(cmd)
370+
if shared.SKIP_SUBPROCS:
371+
return ''
369372
return check_call(cmd, stdout=PIPE).stdout
370373

371374
acorn_optimizer.counter += 1
@@ -375,6 +378,9 @@ def acorn_optimizer(filename, passes, extra_info=None, return_output=False, work
375378
output_file = basename + '.jso%d.js' % acorn_optimizer.counter
376379
shared.get_temp_files().note(output_file)
377380
cmd += ['-o', output_file]
381+
shared.print_compiler_stage(cmd)
382+
if shared.SKIP_SUBPROCS:
383+
return output_file
378384
check_call(cmd)
379385
save_intermediate(output_file, '%s.js' % passes[0])
380386
return output_file
@@ -780,6 +786,9 @@ def metadce(js_file, wasm_file, debug_info, last):
780786
extra_info = '{ "exports": [' + ','.join(f'["{asmjs_mangle(x)}", "{x}"]' for x in exports) + ']}'
781787

782788
txt = acorn_optimizer(js_file, ['emitDCEGraph', '--no-print'], return_output=True, extra_info=extra_info)
789+
if shared.SKIP_SUBPROCS:
790+
# The next steps depend on the output from this step, so we can't do them if we aren't actually running.
791+
return js_file
783792
graph = json.loads(txt)
784793
# ensure that functions expected to be exported to the outside are roots
785794
required_symbols = user_requested_exports.union(set(settings.SIDE_MODULE_IMPORTS))
@@ -1209,6 +1218,9 @@ def run_binaryen_command(tool, infile, outfile=None, args=None, debug=False, std
12091218
if settings.GENERATE_SOURCE_MAP and outfile and tool in ['wasm-opt', 'wasm-emscripten-finalize']:
12101219
cmd += [f'--input-source-map={infile}.map']
12111220
cmd += [f'--output-source-map={outfile}.map']
1221+
shared.print_compiler_stage(cmd)
1222+
if shared.SKIP_SUBPROCS:
1223+
return ''
12121224
ret = check_call(cmd, stdout=stdout).stdout
12131225
if outfile:
12141226
save_intermediate(outfile, '%s.wasm' % tool)

0 commit comments

Comments
 (0)