Skip to content

Conversation

@NickNaso
Copy link
Member

@NickNasoNickNaso commented May 23, 2019

Expose napi_build_version to allow node-gyp to make it
available for addons.
Fixes: nodejs/node-gyp#1745
Refs: nodejs/abi-stable-node#371

  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Copy link
Member

@lpincalpinca left a comment

Choose a reason for hiding this comment

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

SGTM

@lpinca
Copy link
Member

lpinca commented May 23, 2019

@NickNaso can you please remove "build:" and capitalize "ensure" in commit message body?

Expose `napi_build_version` to allow `node-gyp` to make it available for addons. 

Expose `napi_build_version` to allow `node-gyp` to make it available for addons. Fixes: nodejs/node-gyp#1745 Refs: nodejs/abi-stable-node#371
@mhdawson
Copy link
Member

@NickNaso is there any way to have this be generated from where the value is defined? Just worried about keeping the 2 in sync. I wonder if something the in the makefiles/build steps could update it? MIght be a bad idea if we don't modify the build files already but thought I'd ask to see if anybody else has any suggestions/comments as well.

@NickNaso
Copy link
MemberAuthor

@mhdawson I will investigate later or tomorrow what you suggested because it's a more robust solution. If anyone want help all feedback are welcome.

@bnoordhuis
Copy link
Member

configure.py could write it to config.gypi, that's also picked up by node-gyp. Another benefit: it'll show up in process.config as process.config.variables.napi_build_version; useful for post-install scripts.

There's precedence, see tools/getmoduleversion.py and its corresponding import and usage in configure.py. That's what generates process.config.variables.node_module_version.

@mhdawson
Copy link
Member

@bnoordhuis thanks for the great pointers.

@addaleax
Copy link
Member

A test with assert.strictEqual(process.config.variables.napi_build_version, process.versions.napi); should work if @bnoordhuis’ suggestion is implemented, as far as keeping the versions up to date is concerned, right?

@addaleaxaddaleax added addons Issues and PRs related to native addons. build Issues and PRs related to build files or the CI. node-api Issues and PRs related to the Node-API. labels Jun 2, 2019
@NickNaso
Copy link
MemberAuthor

Thanks all for suggestions I will update the PR very soon.

Copy link
Member

@legendecaslegendecas left a comment

Choose a reason for hiding this comment

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

There is a definition of NAPI_VERSION in node_version.h. Should it be derived from the one in js_native_api.h too?

@NickNaso
Copy link
MemberAuthor

@legendecas
I didn't know that node_verssion.h contains the definition of NAPI_VERSION and I think that it's more appropriate use this file to retrieve the version of N-API. I will provide to update the PR.

@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@legendecaslegendecas left a comment

Choose a reason for hiding this comment

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

Wondering the difference of NAPI_VERSION between node_version.h and js_native_api.h. Should they both be updated on version bumping?

@NickNaso
Copy link
MemberAuthor

@legendecas I think that we need to update both version in node_version.h and in js_native_api.h, but your concern is about the fact the we need to change the version in two places. Now I'm thinking that if we use js_native_api.h to retrive the N-API version could be more appropriate because I added a test so if the test fail this means there is a bad N-API version set in js_native_api.h or node_version.h. What do you think?

@NickNaso
Copy link
MemberAuthor

NickNaso commented Jun 7, 2019

Hi everyone,
like I explained in the previous comment now we have two places (node_version.h and js_native_api.h) where we need to update the N-API version and this could not be ideal. In these days I tried to find a solution that now I want propose:

  • Create a new file called js_native_api_version.h and define NAPI_BASE_VERSION
  • Import js_native_api_version.h in node_version.h and js_native_api.h and then use the NAPI_BASE_VERSION

I executed the tests and it seems to work, but I don't know if it could be the right solution.
Someone have an opinion or feedback about that?

@nodejs/n-api

@mhdawson
Copy link
Member

The two definitions of N-API version are actually a bit different.

The one in node_version.h is the version which the Node binary being built supports.

The one in js_native_api_version.h controls which version will be used by default when compiling a native addon. For example, if all LTS versions support N-API 4, but the latest support N-API 5 we still may want to have the default be N-API 4 be the default so that the addon can compile across all of the LTS versions. If the addon developer specifically wants to use functions in N-API 5 they can do that by setting NAPI_VERSION to 5 knowing that they have specifically depended on that version.

Might have been better if we had named them differently as I can't remember if there was any reason they needed to be the same.

My thought is that having them be separate is useful but that we should have more comments to explain what I've just said in the code.

@jschlight
Copy link
Contributor

jschlight commented Jun 10, 2019

If I understand correctly, the NAPI_VERSION value is meant to be optionally overridden using build tools.

For example, node-pre-gyp (N-API Doc) and prebuild (N-API Doc) are designed to fire off multiple builds, one for each N-API version supported by the native module. The NAPI_VERSION value is used to communicate to the C/C++code which N-API version the code is being built against.

I'm not clear what effect, if any, NAPI_VERSION should have on napi_build_version if the value of NAPI_VERSION set externally by a build tool.

Edit: Reviewing the documentation linked above, it looks like for node-pre-gyp and prebuild the NAPI_VERSION is derived directly from napi_build_version. So with these two tools we're good.

@gabrielschulhof
Copy link
Contributor

@mhdawsonNAPI_VERSION as defined in js_native_api.h is defined softly. Thus, if you wish to build against whichever version your copy of Node.js supports, you can

#include"node_version.h"#include"js_native_api.h"

@gabrielschulhof
Copy link
Contributor

@mhdawson that's probably why they have the same name.

Copy link
Member

@mhdawsonmhdawson left a comment

Choose a reason for hiding this comment

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

LGTM

@nodejs-github-bot
Copy link
Collaborator

@mhdawson
Copy link
Member

@mhdawson
Copy link
Member

Copy link
Member

@bnoordhuisbnoordhuis left a comment

Choose a reason for hiding this comment

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

LGTM % style nit. Thanks for doing this!

edit: the CI failures are all infrastructural, by the way.

@NickNaso
Copy link
MemberAuthor

Hi everybody is there a chance to merge this PR?

@nodejs-github-bot
Copy link
Collaborator

@gabrielschulhof
Copy link
Contributor

Landed in 9868126.

pullbot pushed a commit to SimenB/node that referenced this pull request Jul 2, 2019
Expose `napi_build_version` to allow `node-gyp` to make it available for building native addons. Fixes: nodejs/node-gyp#1745 Refs: nodejs/abi-stable-node#371 PR-URL: nodejs#27835 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
targos pushed a commit that referenced this pull request Jul 2, 2019
Expose `napi_build_version` to allow `node-gyp` to make it available for building native addons. Fixes: nodejs/node-gyp#1745 Refs: nodejs/abi-stable-node#371 PR-URL: #27835 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
targos pushed a commit that referenced this pull request Jul 2, 2019
Expose `napi_build_version` to allow `node-gyp` to make it available for building native addons. Fixes: nodejs/node-gyp#1745 Refs: nodejs/abi-stable-node#371 PR-URL: #27835 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
@targostargos mentioned this pull request Jul 2, 2019
gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this pull request Sep 19, 2020
Expose `napi_build_version` to allow `node-gyp` to make it available for building native addons. Fixes: nodejs/node-gyp#1745 Refs: nodejs/abi-stable-node#371 PR-URL: nodejs#27835 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
richardlau pushed a commit that referenced this pull request Oct 7, 2020
Expose `napi_build_version` to allow `node-gyp` to make it available for building native addons. Fixes: nodejs/node-gyp#1745 Refs: nodejs/abi-stable-node#371 PR-URL: #27835 Backport-PR-URL: #35266 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
@richardlaurichardlau mentioned this pull request Oct 7, 2020
3 tasks
richardlau added a commit that referenced this pull request Oct 7, 2020
Notable changes: - deps: - upgrade npm to 6.14.8 (Ruy Adorno) #34834 - n-api: - create N-API version 7 (Gabriel Schulhof) #35199 - expose napi_build_version variable (NickNaso) #27835 - tools: - add debug entitlements for macOS 10.15+ (Gabriele Greco) #34378 PR-URL: #35544
richardlau added a commit that referenced this pull request Oct 9, 2020
Notable changes: - deps: - upgrade npm to 6.14.8 (Ruy Adorno) #34834 - n-api: - create N-API version 7 (Gabriel Schulhof) #35199 - expose napi_build_version variable (NickNaso) #27835 - tools: - add debug entitlements for macOS 10.15+ (Gabriele Greco) #34378 PR-URL: #35544
richardlau added a commit that referenced this pull request Oct 27, 2020
Notable changes: - deps: - upgrade npm to 6.14.8 (Ruy Adorno) #34834 - n-api: - create N-API version 7 (Gabriel Schulhof) #35199 - expose napi_build_version variable (NickNaso) #27835 - tools: - add debug entitlements for macOS 10.15+ (Gabriele Greco) #34378 PR-URL: #35544
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

addonsIssues and PRs related to native addons.buildIssues and PRs related to build files or the CI.node-apiIssues and PRs related to the Node-API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose napi version as a node-gyp variable

10 participants

@NickNaso@lpinca@mhdawson@bnoordhuis@addaleax@nodejs-github-bot@jschlight@gabrielschulhof@richardlau@legendecas