-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
libnode: Added C FFI compatible function to act as an entrypoint for embedded consumers #57846
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
Conversation
Review requested:
|
@alshdavid , this PR looks like to be related to this PR #54660. Currently this new experimental C API is implemented in this libnode NuGet package (based on Node.js 20.x): https://www.nuget.org/packages/Microsoft.JavaScript.LibNode |
This looks great and I welcome an expanded libnode API. In my case, all I need to get off the ground is a Anything beyond that is a nice to have for my use case; e.g.
|
@alshdavid , I believe that the upcoming embedding API should address the most of your requirements:
The API has the
We cannot do it. I guess this is a V8 limitation. It allows to initialize and then dispose the V8 platform only once. Thus, the Node.js must do the same. Instead of starting and stopping the whole Node.js, you should rather change your usage to create/delete the
I need more info to understand this scenario. The shared
See the |
@vmoroz thanks for the details! I have started working on a Rust crate that adds bindings for the new C api you have in your PR. I am working off of local builds of Will hopefully be able to fetch the prebuilt library files from official urls at some point. It currently includes all of the C n-api bindings and a few of the embedder APIs (like https://github.com/alshdavid/libnode_sys I'll close my PR given #54660 does what I need and more.
Sorry, poor choice of words. The internal node.js instance inherits stdin/out/err from the host process - meaning a |
@alshdavid , regarding the stdin/stdout/stderr, I believe it is all normal app behavior. Any library can use them without any additional work. I.e. the JS code that works with |
Motivation
Hi all,
I have been working on embedding Nodejs in my Rust application to act as a plugin runtime however, while
libnode
exposes a C++ API, it does not work with consumers that only have access to C FFI calls (like Rust).Changes
node_start()
function innode.cc
to proxynode::Start()
Examples
I created a repo that patches nodejs to add this function, generate static binaries (under GitHub releases) and offers a Rust crate that provides bindings. So far, all I need is this one function added to
node.cc
.Usage:
CC: #52289