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

doc: add guide for updating N-API API surface #21877

Closed
wants to merge 3 commits into from

Conversation

digitalinfinity
Copy link
Contributor

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

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
@digitalinfinity
Copy link
Contributor Author

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.

@@ -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.
Copy link
Member

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 :-)


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
Copy link
Member

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.

Copy link
Member

@jasnell jasnell left a 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!

@vsemozhetbyt vsemozhetbyt added doc Issues and PRs related to the documentations. node-api Issues and PRs related to the Node-API. labels Jul 19, 2018
Copy link
Contributor

@vsemozhetbyt vsemozhetbyt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits)

@@ -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.
Copy link
Contributor

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?

- 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`napi_status`

- **Must** be a C API
- **Must** not throw exceptions
- **Must** return napi_status
- **Should** consume napi_env
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`napi_env`

- **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.
Copy link
Contributor

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?

- **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
Copy link
Contributor

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)?

- **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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node -> Node.js

- 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node -> Node.js

- 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`#define`?

- 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**.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`nodejs/node`

- 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node -> Node.js

@vsemozhetbyt
Copy link
Contributor

Doc linting also have some Use spaces instead of hard-tabs errors.

@vsemozhetbyt
Copy link
Contributor

cc @nodejs/documentation, @Trott

Copy link
Member

@mhdawson mhdawson left a 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.

@mhdawson
Copy link
Member

Also obviously all the linter errors need to be fixed up.

@mhdawson
Copy link
Member

@nodejs/tsc please review as there are some key points that affect PRs to node core.

For example:

A new API addition **must** be signed off by at least two members of the N-API WG

@digitalinfinity
Copy link
Contributor Author

Thanks @jasnell @vsemozhetbyt @mhdawson for your feedback- incorporated it all into a new commit

Copy link
Contributor

@cjihrig cjihrig left a 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?

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space before "or"

Copy link
Contributor Author

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 😞

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.
Copy link
Contributor

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"?

Copy link
Contributor

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.

Copy link
Contributor Author

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

* 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).
Copy link
Contributor

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed- thanks!

@vsemozhetbyt
Copy link
Contributor

@vsemozhetbyt
Copy link
Contributor

Landed in e83126a
Thank you!

vsemozhetbyt pushed a commit that referenced this pull request Jul 25, 2018
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>
targos pushed a commit that referenced this pull request Jul 26, 2018
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>
@targos targos mentioned this pull request Jul 31, 2018
@Trott
Copy link
Member

Trott commented Aug 7, 2018

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.

@mhdawson
Copy link
Member

mhdawson commented Aug 8, 2018

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)

@mhdawson
Copy link
Member

mhdawson commented Aug 8, 2018

Suggestions on other places to link to for discover-ability also greatly appreciated.

@Trott
Copy link
Member

Trott commented Aug 9, 2018

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.)

@mhdawson
Copy link
Member

mhdawson commented Aug 9, 2018

@Trott I'll create a PR adding a link in the COLLABORATOR_GUIDE.

@mhdawson
Copy link
Member

PR to add to collaborator guide #22593

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. node-api Issues and PRs related to the Node-API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants