Change WASM location in JS glue code

354 views
Skip to first unread message

ilia.g...@gmail.com

unread,
Sep 9, 2017, 11:34:34 AM9/9/17
to emscripten-discuss
Hi,
I am compiling my project to WASM code with JS glue and put them on server side.
Then I have to load them from server and use.
Is it possible to control  path to wasm file from JS glue during compilation? Perhaps there are some flags or something else.
I did not find this option in documentation. I use web workers and lots of API calls, so I am not sure that I it would be easy to load WASM files manually instead of using JS glue code.

Floh

unread,
Sep 10, 2017, 10:07:57 PM9/10/17
to emscripten-discuss
Best way is to use your own HTML shell file and put your own paths in there, for example like this:


This doesn't change the location of the wasm file, but its file extensions (to .wasm.txt because .wasm files are not compressed by the github pages web servers, but .txt files are, some with the .mem file).

The file is actually a python template file, the ${name} part would be replaced with the actual app name.

Use the --shell-file linker argument to link with such a custom html shell file (see here and search for "--shell-file": https://kripken.github.io/emscripten-site/docs/tools_reference/emcc.html)

Check the browser dev tools with this live demo to see how it works in the end: http://floooh.github.io/oryol/wasm/Clear.html

Cheers,
-Floh.

Floh

unread,
Sep 10, 2017, 10:25:59 PM9/10/17
to emscripten-discuss
...just for clarification: the python templating I mentioned is not performed by emscripten's build process, instead I'm doing this in my own -"post-build-script" (I'm compiling the emscripten code as usual, and then throw the original shell file away, and use my own stuff instead).

ilia.g...@gmail.com

unread,
Sep 11, 2017, 4:30:49 AM9/11/17
to emscripten-discuss
Thank you for explanations.
But with this approach I cannot get access to web worker wasm module.
Is there any ways to do this in main html file or somewhere else?
I would like to set the location of wasm worker file too.

суббота, 9 сентября 2017 г., 18:34:34 UTC+3 пользователь ilia.g...@gmail.com написал:

Floh

unread,
Sep 11, 2017, 6:51:26 AM9/11/17
to emscripten-discuss
Ah ok, I haven't dabbled with web workers in wasm yet. For asm.js you would simply hand the script URL to emscripten_create_worker() (https://kripken.github.io/emscripten-site/docs/api_reference/emscripten.h.html#id6), but I don't know how a WebAssembly module would be loaded this way (I guess it also starts with a JS script, which would then need to load and initialize the WebAssembly module).
Reply all
Reply to author
Forward
0 new messages