-
Notifications
You must be signed in to change notification settings - Fork 30k
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
doc: add guide for updating N-API API surface #21877
Conversation
This adds a new guide that outlines the principles and guidelines for contributing a new API to the N-API surface. These guidelines were formulated based on discussions in the API working group. Refs: nodejs/abi-stable-node#301
cc @nodejs/n-api For more context, this document was written up to help provide node collaborators a framework to reason about contributions to the N-API surface. However, this is not a locked down document- rather, this PR is intended to solicit additional feedback from the broader community Also, after chatting with @mhdawson, it seemed like doc/guides was the best place for such a document to live but if there's a better place to move this to, happy to update the PR. |
doc/guides/adding-new-napi-api.md
Outdated
@@ -0,0 +1,31 @@ | |||
# Contributing a new API to N-API | |||
|
|||
N-API is Node's next generation ABI-stable API for native modules. While improving the API surface is encouraged and welcomed, the following are a set of principles and guidelines to keep in mind while adding a new N-API API. |
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.
Please line break at <=80 chars... makes it significantly easier to review :-)
doc/guides/adding-new-napi-api.md
Outdated
|
||
N-API is Node's next generation ABI-stable API for native modules. While improving the API surface is encouraged and welcomed, the following are a set of principles and guidelines to keep in mind while adding a new N-API API. | ||
|
||
- A new API **must** adhere to N-API API shape and spirit |
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.
nit: for consistency, please use * instead of - for bullet lists.
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.
Couple of nits, but LGTM!
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.
Some nits)
doc/guides/adding-new-napi-api.md
Outdated
@@ -0,0 +1,31 @@ | |||
# Contributing a new API to N-API | |||
|
|||
N-API is Node's next generation ABI-stable API for native modules. While improving the API surface is encouraged and welcomed, the following are a set of principles and guidelines to keep in mind while adding a new N-API API. |
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.
Node's
-> Node.js's
?
doc/guides/adding-new-napi-api.md
Outdated
- A new API **must** adhere to N-API API shape and spirit | ||
- **Must** be a C API | ||
- **Must** not throw exceptions | ||
- **Must** return napi_status |
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.
`napi_status`
doc/guides/adding-new-napi-api.md
Outdated
- **Must** be a C API | ||
- **Must** not throw exceptions | ||
- **Must** return napi_status | ||
- **Should** consume napi_env |
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.
`napi_env`
doc/guides/adding-new-napi-api.md
Outdated
- **Should** consume napi_env | ||
- **Must** operate only on primitive data types, pointers to primitive datatypes or opaque handles | ||
- **Must** be a necessary API and not a nice to have. Convenience APIs belong in node-addon-api. | ||
- **Must** not change the signature of an existing N-API API or break ABI compatibility with other versions of Node. |
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.
Some points have a period in the end, some have not. Should we unify them?
doc/guides/adding-new-napi-api.md
Outdated
- **Must** be a necessary API and not a nice to have. Convenience APIs belong in node-addon-api. | ||
- **Must** not change the signature of an existing N-API API or break ABI compatibility with other versions of Node. | ||
- New API **should** be agnostic towards the underlying JavaScript VM | ||
- New API request PRs **must** have a corresponding documentation update |
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.
Is request PR
tautological (here and below)?
doc/guides/adding-new-napi-api.md
Outdated
- **Should** consume napi_env | ||
- **Must** operate only on primitive data types, pointers to primitive datatypes or opaque handles | ||
- **Must** be a necessary API and not a nice to have. Convenience APIs belong in node-addon-api. | ||
- **Must** not change the signature of an existing N-API API or break ABI compatibility with other versions of Node. |
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.
Node
-> Node.js
doc/guides/adding-new-napi-api.md
Outdated
- A new API **should** be discussed at the N-API working group meeting | ||
- A new API addition **must** be signed off by at least two members of the N-API WG | ||
- A new API addition **should** be simultaneously implemented in at least one other VM implementation of Node. | ||
- A new API **must** be considered experimental for at least one minor version release of Node before it can be considered for promotion out of experimental |
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.
Node
-> Node.js
doc/guides/adding-new-napi-api.md
Outdated
- A new API addition **should** be simultaneously implemented in at least one other VM implementation of Node. | ||
- A new API **must** be considered experimental for at least one minor version release of Node before it can be considered for promotion out of experimental | ||
- Experimental APIs **must** be documented as such | ||
- Experimental APIs **must** require an explicit compile-time flag (#define) to be set to opt-in |
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.
`#define`
?
doc/guides/adding-new-napi-api.md
Outdated
- Experimental APIs **must** require an explicit compile-time flag (#define) to be set to opt-in | ||
- Experimental APIs **must** be considered for backport | ||
- Experimental status exit criteria **must** involve at least the following: | ||
- A new PR **must** be opened in nodejs/node to remove experimental status. This PR **must** be tagged as **n-api** and **semver-minor**. |
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.
`nodejs/node`
doc/guides/adding-new-napi-api.md
Outdated
- Exiting an API from experimental **must** be signed off by the working group. | ||
- If a backport is merited, an API **must** have a down level implementation. | ||
- The API **should** be used by a published real-world module. Use of the API by a real-world published module will contribute favorably to the decision to take an API out of experimental status | ||
- The API **must** be implemented in a node implementation with an alternate VM |
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.
node
-> Node.js
Doc linting also have some |
cc @nodejs/documentation, @Trott |
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.
LGTM once existing comments are addressed.
Also obviously all the linter errors need to be fixed up. |
@nodejs/tsc please review as there are some key points that affect PRs to node core. For example:
|
Thanks @jasnell @vsemozhetbyt @mhdawson for your feedback- incorporated it all into a new commit |
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.
The text generally LGTM. The package-lock changes should be backed out?
doc/guides/adding-new-napi-api.md
Outdated
datatypes or opaque handles. | ||
* **Must** be a necessary API and not a nice to have. Convenience APIs | ||
belong in node-addon-api. | ||
* **Must** not change the signature of an existing N-API API or break |
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.
Extra space before "or"
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.
Fixed- thanks! And yes, whoops- the package-lock changes were accidental 😞
doc/guides/adding-new-napi-api.md
Outdated
belong in node-addon-api. | ||
* **Must** not change the signature of an existing N-API API or break | ||
ABI compatibility with other versions of Node.js. | ||
* New API **should** be agnostic towards the underlying JavaScript VM. |
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.
Is this a "should" or a "must"?
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.
You really need to perform the exercise of stretching the bed sheet onto two different mattresses to see if it really is a one-size-fits-all 🙂
I guess, basically, if this is a "must", then so is implementation on top of multiple engines below.
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.
Yeah, also the thinking here was that there might be legitimate reasons why we might want to expose an API that was VM specific (that other VMs would just return an error/silently fail on), and so the thinking was to leave that up to the reviewers of the relevant PR
doc/guides/adding-new-napi-api.md
Outdated
* There **must** be at least one test case showing how to use the API. | ||
* There **should** be at least one test case per interesting use of the API. | ||
* There **should** be a sample provided that operates in a realistic way | ||
(operating how a real addon would be written). |
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.
A nit: wrapped lines in this level are not aligned with the first line properly (other levels seem OK).
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.
Fixed- thanks!
Landed in e83126a |
This adds a new guide that outlines the principles and guidelines for contributing a new API to the N-API surface. These guidelines were formulated based on discussions in the API working group. PR-URL: #21877 Refs: nodejs/abi-stable-node#301 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
This adds a new guide that outlines the principles and guidelines for contributing a new API to the N-API surface. These guidelines were formulated based on discussions in the API working group. PR-URL: #21877 Refs: nodejs/abi-stable-node#301 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Quite a bit late on this one, so I apologize, but: It is not clear if this document is supposed to be policy. It describes itself as a list of "principles and guidelines to keep in mind". I don't recall if I started reviewing this or not, but had I, I would have stopped right there and let other folks review it because what do I have to say about n-api principles and guidelines? Happy to let n-api-savvy folks do that. But then it gets to using must and should, which sure sounds like it's intended to be binding. Given i's self-description as "guidelines" etc. along with its lack of discoverability (no link from COLLABORATOR_GUIDE or any other location in the repo, so the only way to find it is if you already know it's there), I'm not inclined to interpret this as policy but more guidance. (It probably doesn't help that I believe we have far too much policy for anyone to actually know and follow.) If it is intended to be a policy, I think that needs to be clarified and it probably should get considerably more TSC scrutiny. |
It was intended to be policy, it does need more discover-ability by inclusion as a reference in the onboarding guide at least for a start. I had included a @nodejs/tsc ping specifically because I wanted to get people to chime in -> see #21877 (comment) |
Suggestions on other places to link to for discover-ability also greatly appreciated. |
I'd go with COLLABORATOR_GUIDE rather than onboarding. Onboarding is something most Collaborators should ideally only have to look at once. Anything they'll need repeatedly should be in COLLABORATOR_GUIDE. (Yes, there's still stuff in onboarding that needs to be moved to COLLABORATOR_GUIDE. But for most things a Collaborator is likely to need again, onboarding links to COLLABORATOR_GUIDE or the material is duplicated there. I'm not a fan of the duplication either, though.) |
@Trott I'll create a PR adding a link in the COLLABORATOR_GUIDE. |
PR to add to collaborator guide #22593 |
This adds a new guide that outlines the principles and guidelines for contributing a new API to the N-API surface. These guidelines were formulated based on discussions in the API working group.
Refs: nodejs/abi-stable-node#301
Checklist