DEV Community

Embedding emscripten in a Node.js library

Bryan Hughes on March 15, 2019

I've been experimenting with Web Assembly lately, and right now I'm in the early stages of getting the messaging stack of my wireless LED control s...
Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Bryan, I just had a eureka moment and thought as thanks for keeping me going, I should share this.

If your still working in WASM, I have found the official way with no hacks, no env manually defined, just require the glue code and setup your c++ in the following way, I also have my lua repo which I could share as an example.

emscripten.org/docs/porting/connec...

Collapse
 
nebrius profile image
Bryan Hughes

Alas, I couldn't get embind (or ccall or cwrap) working in my case. I probably could have figured it out eventually, but I had deadlines 😉

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Thank you once again for saving the day .. sort of, this rewire is a hacky thing and feels very wrong considering the glue code does include some if node then do this type stuff.
But for the life of me I can't seem to make a library unless I take this approach. I would love to see a script to remove all the browser bits from the glue code.

Collapse
 
nebrius profile image
Bryan Hughes

"But for the life of me I can't seem to make a library unless I take this approach." I think I said exactly the same thing at one point in time 😂

Yeah, this approach is really hacky, and I'm not particularly happy that I had to do it this way.

Collapse
 
tranphuoctien profile image
Tran Tien • Edited
Error:  LinkError: WebAssembly.instantiate(): Import #0 module="env" function="abort" error: function import requires a callable
(anonymous) @ app.js:25
Promise.catch (async)
(anonymous) @ app.js:24

Im using github:AssemblyScript/assemblyscript
How to fix please? Im newbie

Thanks

Collapse
 
cancerberosgx profile image
Sebastián Gurin

I'm trying to run ImageMagick (wasm-imagemagick). We avoiding compiling two .wasm (probably we will end doing that). In this case the project provides a js API library to users ourselves are consuming it the application using its CLI.

Besides correctness I think is great that people start the discussion this way without shame. Build and distribution of emscripten binaries is still painful (distribution and installation of libraries particularly) and although a hack it could save lots of pain (so I'm trying it now).

In general we are engineers and if the right solution cost too much then it's not the right solution.
IMO, sometimes Elegant, and right are words that apply to other career while the engineer just need to make it work... Thanks.