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

Node.js Feature Request: Embedded Host API & NativeWrapperGen Solution with Decorator and Tool Support & Infrastructure Change #51824

Closed
congzhangzh opened this issue Feb 21, 2024 · 3 comments
Labels
feature request Issues that request new features to be added to Node.js. stale

Comments

@congzhangzh
Copy link
Contributor

congzhangzh commented Feb 21, 2024

What is the problem this feature will solve?

Using JavaScript as a library and plugin extension for existing C/C++ programs requires a substantial amount of work, where writing glue code is particularly complex and error-prone.

What is the feature you are proposing to solve the problem?

Key Features:

  1. Define a basic type table(reference ffi)and decorate functions (export2c in nativegen.js)
  2. Auto-generate .h, .cc, and Makefile files from a library file (library.js/plugin.js) where functions are already decorated using export2c from nativegen.js
  3. Nativegen.js implement the tools main function

Technical Challenges:

1.	Is it necessary to run the libuv event loop on a separate thread? Merely pump out the event queue is insufficient as code with persistent logic (such as a server) will not function.
2.	For sync api, communication with the event loop by async handle/async send? Implement send call with c++ promise from caller, activate c++ promise on finish call, and return values on the C/C++ side.
3.	For async api(promise handling): set callback on V8 promise to activate c++ promise for valueb back to caller.
4.	Exception propagation: from JavaScript to C++, including catch, wrapper, and rethrow mechanisms.

Infrastructure change Requirements:

Include with node-embedded.tar(like python)

•	node.h, v8.h (and all related child.h), uv.h
•	libnode.lib (win), libuv.lib (win)
•	libnode.so/libnode.dll, libuv.dll(win)

References:

  1. https://nodejs.org/api/embedding.html
  2. https://github.com/nodejs/node/blob/HEAD/test/embedding/embedtest.cc
  3. https://v8.dev/docs/embed
  4. https://github.com/v8/v8/blob/main/samples/process.cc
  5. https://github.com/node-ffi/node-ffi/wiki/Node-FFI-Tutorial
  6. https://github.com/TooTallNate/ref/blob/6951bf7fdcef0dfa7e0b65d93f68d36aabdedef7/lib/ref.js#L831
  7. https://learn.microsoft.com/en-us/dotnet/core/tutorials/netcore-hosting#hosting-apis
  8. https://github.com/AaronRobinsonMSFT/DNNE
  9. https://cffi.readthedocs.io/en/latest/embedding.html
  10. https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html
  11. https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html#interacting-with-code-call-javascript-from-native
  12. https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html#implement-c-in-javascript
  13. https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#embind-val-guide
  14. https://emscripten.org/docs/porting/asyncify.html
  15. https://github.com/danbev/learning-v8/tree/master
  16. https://docs.python.org/3.6/using/windows.html#embedded-distribution
  17. httpsq://www.python.org/ftp/python/3.11.8/python-3.11.8-embed-amd64.zip

What alternatives have you considered?

Do all the work by hand is possible, but very verbose and error prone.

@congzhangzh congzhangzh added the feature request Issues that request new features to be added to Node.js. label Feb 21, 2024
Copy link
Contributor

github-actions bot commented Sep 6, 2024

There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the never-stale Mark issue so that it is never considered stale label or close this issue if it should be closed. If not, the issue will be automatically closed 6 months after the last non-automated comment.
For more information on how the project manages feature requests, please consult the feature request management document.

@github-actions github-actions bot added the stale label Sep 6, 2024
Copy link
Contributor

github-actions bot commented Oct 6, 2024

There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.

For more information on how the project manages feature requests, please consult the feature request management document.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. stale
Projects
None yet
Development

No branches or pull requests

1 participant