[QUESTION] "Link" Emscripten JS Runtime via WASM standard API

37 views
Skip to first unread message

Tianqi Chen

unread,
Apr 23, 2020, 12:29:23 AM4/23/20
to emscripten-discuss
Dear Developers:

https://v8.dev/blog/emscripten-standalone-wasm provides an excellent description about how to compile a stand-alone WASM via emcc.
However, in the case of the syscalls still needs emscripten defined files, we will still need an emscripten generated file, and that means
we will need to interact with the WASM via the emscripten Javascript wrapper, e.g. Module.wrap, and call

Recently we start to look into directly build our js interface on top of the WASM js API.
I am wondering if it is possible to directly interact with the wasm module generated by emscripten via the standard WASM js interface,
but still make these additional emscripten syscalls available.

In particular, I am looking for something like


emcc -O3 mylib.c -o mylib.js -s STANDALONE_WASM


Then

const binary = require('fs').readFileSync('mylib.wasm');

// this line ontains the emscripten defined syscalls as a imports 
// that can be passed to the WebAssembly interface.
imports_with_emscripten_sycalls = getEnv("mylib.js");

WebAssembly.instantiate(binary, imports_with_emscripten_sycalls);


Thank you!

TQ

Sam Clegg

unread,
Apr 23, 2020, 10:21:15 PM4/23/20
to emscripte...@googlegroups.com
No, this is currently not possible.  I think it would be cool feature though.   I'm not sure how much work it would be to modify the generated JS to work in this way.  I'm guessing a fair amount..

 
Thank you!

TQ

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/4dda2146-9bb7-4d5e-abc9-adeb505ef029%40googlegroups.com.

Tianqi Chen

unread,
Apr 26, 2020, 1:51:25 AM4/26/20
to emscripte...@googlegroups.com
I see. I wonder if it is possible to get some middle ground.

// mod is emscripten module 
mod =Module;

wasmInstance = mod.wasmInstance;
wasmMemory = wasmInstance.exports.memory

// Directly interact with wasmInstance
// using the WebAssembly API
// syscall callbacks can trap into emscripten module 

TQ 
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/Dqdcjzs6fj0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAL_va29AAMY5-CQ5S7gYQ6MD1Bp3Y5hpBYrMNFc14w3zh3V8hw%40mail.gmail.com.

Sam Clegg

unread,
Apr 26, 2020, 1:49:35 PM4/26/20
to emscripte...@googlegroups.com
On Sat, Apr 25, 2020 at 10:51 PM Tianqi Chen <tqc...@cs.washington.edu> wrote:
I see. I wonder if it is possible to get some middle ground.

// mod is emscripten module 
mod =Module;

wasmInstance = mod.wasmInstance;
wasmMemory = wasmInstance.exports.memory

// Directly interact with wasmInstance
// using the WebAssembly API
// syscall callbacks can trap into emscripten module 

I think that should work yes.  I don't see anything stopping you doing that today.  


Reply all
Reply to author
Forward
0 new messages