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

--embind-emit-tsd / --emit-tsd do not work with dynamic linkage #21859

Open
slade87 opened this issue Apr 30, 2024 · 2 comments
Open

--embind-emit-tsd / --emit-tsd do not work with dynamic linkage #21859

slade87 opened this issue Apr 30, 2024 · 2 comments
Assignees

Comments

@slade87
Copy link

slade87 commented Apr 30, 2024

In case a WASM binary is linked dynamically the option to emit typescript interface does not work.
The main cause seems to be that the generated wasm and js file are copied to a temp directory during running emitting the typescript interfaces while all of the possible dependencies are not.

As a workaround I changed link.py #

outfile_wasm = in_temp('tsgen_a.out.wasm')
to the following content:

outfile_wasm = in_temp('tsgen_a.out.wasm')
import pathlib, glob, shutil
root_dir =  str(pathlib.Path(wasm_target).parent.resolve())
out_temp = str(pathlib.Path(outfile_js).parent.resolve())
for file in glob.glob(root_dir + r'/*.so*'):
    logger.info('Copying: ' + file)
    shutil.copy(src=file, dst=out_temp)"

The example workaround above simply copies all .so files existent in the same location as the wasm/js file to the same location in the temp directory. With the workaround the dynamic lib is properly loaded and the typescript interfaces are emitted. There is most likely a much more sophisticated solution to that problem.

Version of emscripten/emsdk:
3.1.56

Failing command line in full:
The issue occurs during linking when option --emit-tsd or --embind-emit-tsd is performed

Full link command and output with -v appended:
As soon as the generated WASM binary contains the following dynamic link section:
dylink.0 .so NAMEOFLIB.so the linking step fails within: function run_embind_gen (https://github.com/emscripten-core/emscripten/blob/63c648fa17be49fa9640d4a40c8ba2f7a9b2d444/tools/link.py#L1924C5-L1924C19) due to node execution failure while trying to load any dynamically linked dependencies in:
out = shared.run_js_tool(outfile_js, [], node_args, stdout=PIPE)

Possible solution
During linkage all dependencies are already propagated to emscripten for the actual linking step, ensure these dependencies are not only put into the dynlink.0 section but also properly copied/symlinked from their origin to the temporary folder used for generating tsd utilizing node when using --embind-emit-tsd / --emit-tsd.

@sbc100
Copy link
Collaborator

sbc100 commented Apr 30, 2024

I'm not sure just bundling the .so files that happen to live next the output binary is the most correct thing to do here.

Are all of your .so files listed on the command line when builting your main module? If so we can maybe just copy them based on the command line.

@slade87
Copy link
Author

slade87 commented Apr 30, 2024

Yes they are passed to link step, so it should be possible to copy them from the command line arguments

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