mozilla / spidernode

Node.js on top of SpiderMonkey
https://ehsanakhgari.org/blog/2016-04-20/project-spidernode
Other
559 stars 43 forks source link

Native module support #388

Open Happy-Ferret opened 7 years ago

Happy-Ferret commented 7 years ago

Curious.

Is there currently a way to build and consume native node modules with spidernode? I tried building a "hello world" module using the node-gyp found inside deps/deps/npm/node_modules/node-gyp/bin/, unfortunately that didn't work.

Ditto for just using the regular node-gyp from my computer's /usr/local/bin/ (spidernode will just print a symbol lookup error in that case).

mykmelez commented 7 years ago

Unfortunately, there isn't currently a way to do this. We've talked about supporting the ABI-stable module API (a.k.a. N-API or NAPI) that was added to Node in https://github.com/nodejs/node/commit/56e881d0b0b2997b518753cb627eb3b50eeb6f62, for native modules that use that API; but we haven't yet done any work on that.

Happy-Ferret commented 7 years ago

That's good to know. I began doubting my ability to compile node modules for a second :) Thanks for the reading material.

I guess while the n-api specifics are still being worked out, I'll just refine my js-ctypes skills and work on a way to automate the js definition part so js-ctype modules can be built similarly to how you'd build native modules and required like regular native modules/commonJS modules, without having to manually write the JS glue code.

mykmelez commented 7 years ago

I guess while the n-api specifics are still being worked out, I'll just refine my js-ctypes skills and work on a way to automate the js definition part so js-ctype modules can be built similarly to how you'd build native modules and required like regular native modules/commonJS modules, without having to manually write the JS glue code.

I would've expected something like this to already exist for js-ctypes generally (albeit not for your specific use case), so I was surprised to do a few searches and not find one.

It isn't clear how well-maintained js-ctypes is. Various extensions have used it, and Firefox uses it in its OS.File implementation. But extension use will no longer be possible as of Firefox 57, and @Yoric has plans to re-implement OS.File without js-ctypes in bug 1231711.

Nevertheless, it does currently work, and there are no plans to change that, so it would be interesting at the very least to see how useful it is for your use case.

Speaking of which, I'd be curious to hear more about what you're doing with SpiderNode. Are you just experimenting with it, or do you have a particular use in mind?