Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web audio typescript generation failure #21835

Open
MatthieuMv opened this issue Apr 26, 2024 · 1 comment
Open

Web audio typescript generation failure #21835

MatthieuMv opened this issue Apr 26, 2024 · 1 comment
Assignees

Comments

@MatthieuMv
Copy link

MatthieuMv commented Apr 26, 2024

When compiling a simple WebAudio program, typescript type generation fails to register runtime exports.
In fact, it fails as soon as I use -sAUDIO_WORKLET. I used a simple main function that only returns 0 to ensure that I was making any mistake.

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.58 (a41843e0860e52c948c1fce20307933c6631c800)
clang version 19.0.0git (https:/github.com/llvm/llvm-project 0a8cd1ed1f4f35905df318015b0dbcb69d81d7c2)
Target: wasm32-unknown-emscripten
Thread model: posix

Failing command line in full:
em++ -O3 -DNDEBUG -pthread -sAUDIO_WORKLET -sWASM_WORKERS --emit-tsd ClientTypes.d.ts {ALL OBJECT FILES...} -o Release/Client.js -lembind

Error:

Traceback (most recent call last):
  File "/home/ptah/Tools/emsdk/upstream/emscripten/em++.py", line 15, in <module>
    sys.exit(emcc.main(sys.argv))
             ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/ptah/Tools/emsdk/upstream/emscripten/emcc.py", line 1583, in main
    ret = run(args)
          ^^^^^^^^^
  File "/home/ptah/Tools/emsdk/upstream/emscripten/emcc.py", line 648, in run
    return link.run(linker_inputs, options, state, newargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ptah/Tools/emsdk/upstream/emscripten/tools/link.py", line 3102, in run
    phase_post_link(options, state, wasm_target, wasm_target, target, js_syms)
  File "/usr/lib/python3.11/contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/ptah/Tools/emsdk/upstream/emscripten/tools/link.py", line 1877, in phase_post_link
    phase_emit_tsd(options, wasm_target, state.js_target, js_syms, metadata)
  File "/usr/lib/python3.11/contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/ptah/Tools/emsdk/upstream/emscripten/tools/link.py", line 1966, in phase_emit_tsd
    all_tsd = emscripten.create_tsd(metadata, embind_tsd)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ptah/Tools/emsdk/upstream/emscripten/tools/emscripten.py", line 638, in create_tsd
    out += create_tsd_exported_runtime_methods(metadata)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ptah/Tools/emsdk/upstream/emscripten/tools/emscripten.py", line 620, in create_tsd_exported_runtime_methods
    js_doc += f'{definition["docs"]}\nRuntimeExports[\'{name}\'] = \n{definition["snippet"]};\n'

Failing code: emscripten.py

def create_tsd_exported_runtime_methods(metadata):
  # Use the TypeScript compiler to generate defintions for all of the runtime
  # exports. The JS from the library any JS docs are included in the file used
  # for generation.
  js_doc = 'var RuntimeExports = {};'
  for name in settings.EXPORTED_RUNTIME_METHODS:
    if name in metadata.library_definitions:
      definition = metadata.library_definitions[name]
      print(definition) # I added this print to check what happens
      js_doc += f'{definition["docs"]}\nRuntimeExports[\'{name}\'] = \n{definition["snippet"]};\n'
    else:
      js_doc += f'/** @type {{any}} */RuntimeExports[\'{name}\'];\n'
  js_doc_file = in_temp('jsdoc.js')
  tsc_output_file = in_temp('jsdoc.d.ts')
  utils.write_file(js_doc_file, js_doc)
  if shutil.which('tsc'):
    tsc = ['tsc']
  else:
    tsc = shared.get_npm_cmd('tsc')
  cmd = tsc + ['--outFile', tsc_output_file, '--declaration', '--emitDeclarationOnly', '--allowJs', js_doc_file]
  shared.check_call(cmd, cwd=path_from_root())
  return utils.read_file(tsc_output_file)

The added print(definition) shows few definitions before the error is thrown:

{'docs': '', 'snippet': '() => _emscripten_stack_get_current()'}
{'docs': '', 'snippet': '(sz) => __emscripten_stack_alloc(sz)'}
{'docs': '', 'snippet': '(val) => __emscripten_stack_restore(val)'}
{'docs': ''}

Any help would be greatly appreciated, thank you !

@kichikuou
Copy link

I think this is #21788 as -sAUDIO_WORKLET makes wasmTable exported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants