-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
node-api: minimal C node embedding API function #58207
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
base: main
Are you sure you want to change the base?
Conversation
Review requested:
|
src/node_embedding_api.h
Outdated
|
||
#include "node.h" | ||
|
||
#ifdef _WIN32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This header file must follow the design patterns used by Node-API code:
- It must not depend on the
node.h
. Thenode.h
is a non-ABI stable C++ API. It should rather depend on thenode-api.h
orjs_native_api.h
. - For the
__cdecl
there is a macroNAPI_CDECL
. It must help to avoid the code duplication. - We must use the
EXTERN_C_START
andEXTERN_C_END
macros around the declaration of functions to enable that header to be used from C++.
@alshdavid , we had discussed this PR in our last Node-API meeting on 5/9/2025.
Overall, it is a great step towards the ABI-stable embedding API and thank you for doing it! |
🥳
I agree with your intuition here.
I will update the PR to reflect these requirements and happy to write the documentation.
If I'm honest, outside of compsci 101 many years ago, I am very new to real-world C/C++ and would definitely require assistance with writing tests as I'm already treading water just trying to navigate the build system, templating and macros 😅. As for using
Likewise! Thank you for working with the team to get the ball rolling, obtaining consensus on the approach and helping out with the implementation specifics in comments to this PR. P.S. I wouldn't be offended if you added commits to this PR or rewrote it/raised a new PR that is idiomatic as I might need some time to get it right. |
@alshdavid , sure, I can do that to streamline the process. |
@alshdavid , I do not have permissions to update your PR branch directly. |
f76b323
to
8b4dfe3
Compare
Co-authored-by: vmoroz <[email protected]>
8b4dfe3
to
732c46c
Compare
@vmoroz, thanks for the commit. I have applied those changes and amended the commit message to fit the Nodejs rules I have also added you as a co-author and given you write access to my fork if you'd like to make changes |
@alshdavid , it looks great! Let me also update the PR title. @nodejs/node-api and @nodejs/embedders , could you have a look at this PR? |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #58207 +/- ##
========================================
Coverage 90.18% 90.18%
========================================
Files 630 632 +2
Lines 186473 186692 +219
Branches 36612 36669 +57
========================================
+ Hits 168169 168373 +204
Misses 11116 11116
- Partials 7188 7203 +15
🚀 New features to boost your workflow:
|
Currently, this PR is raised to aid in the discussion of #54660, which implements the complete API.
This PR only adds a single "unstable" C compatible function for embedders.
node_embedding_start
which forwards tonode::Start
.While this function does not offer a complete embedder API like the aforementioned PR, when combined with some glue code on the JavaScript side and existing n-api functionality, it is sufficient to enable a large portion of use cases for embedders.
Example use cases; Calling into JavaScript plugins that feature Node.js compatibility from a language that can consume a C library (Rust, Go, Zig, C#, etc)
While a rich C API would be amazing, my hope is that in the interim, a smaller change is more likely to be included into Nodejs and unblocks consumers that want to embed it.
Reference consumer embedder implementations: