-
Notifications
You must be signed in to change notification settings - Fork 263
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
N-API Support #345
N-API Support #345
Conversation
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.
Not a maintainer, just some drive-by comments.
lib/build.js
Outdated
@@ -16,7 +17,13 @@ function do_build(gyp,argv,callback) { | |||
concat(['--']). | |||
concat(result.unparsed); | |||
} | |||
if (!err && result.opts.napi_build_version) { | |||
napi.swap_build_dir_in(result.opts.napi_build_version); | |||
} |
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're using tabs but, looking at the surrounding code, it should be spaces. Happen in a few other places too.
lib/util/napi.js
Outdated
|
||
module.exports.validate_package_json = function(package_json) { // return err | ||
var binary = package_json.binary; | ||
var module_path_ok = binary.module_path && binary.module_path.includes('{napi_build_version}'); |
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.
I'm not sure what node versions node-pre-gyp supports but String.p.includes() doesn't exist in node.js <= v0.12. Use String.p.indexOf() if that's an issue.
lib/util/napi.js
Outdated
|
||
if (napi_build_versions) { | ||
napi_build_versions.forEach(function(napi_build_version){ | ||
if (!((parseInt(napi_build_version) === napi_build_version) && (napi_build_version > 0))) { |
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.
I'd be explicit about the base and write parseInt(napi_build_version, 10)
. Likewise on line 119.
Aside: your clauses have some superfluous parentheses.
"sources": [ "<(module_name).cc" ], | ||
'product_dir': '<(module_path)', | ||
"xcode_settings": { | ||
"MACOSX_DEPLOYMENT_TARGET":"10.9", |
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.
Just curious, is there any particular reason to set this?
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.
I created app7
by copying one of the existing test apps as a starting point. The declaration came along for the ride.
I appreciate your taking the time to review my code and for your constructive suggestions. Thank you.
I am working to determine why the builds for Node versions < 8 are failing. |
At this point, all of the Travis CI build tests are completing successfully. For the AppVeyor builds, two tests for each of the builds for Node 8+ are failing. The tests are related to downloading the pre-built binaries. The reason for the failures is the fact that the current In the test logs we can see that the test is attempting to download the following URL:
Notice the URL contains the substitution text Manually substituting the supported N-API versions
If you'd like, I can add code to Otherwise, I feel this PR is ready to merge. However, I'm open to any suggestions to improve it. |
@inspiredware looks like you addressed the CI issues and it will be green once the PR changes. Looking forward to seeing it land. |
The N-API Working Group is meeting tomorrow. Would it be possible for the maintainers to post an update here, even if it's just an indication of when you think you'll be able to look at this PR? Many thanks! |
@inspiredware excellent work on this. I've reviewed (finally, sorry for the wait), and will merge now. This will land in v0.8.0. |
hmm, holding on v0.8.0 release. @inspiredware I'm seeing https://travis-ci.org/mapbox/node-pre-gyp/jobs/351625424#L990 on travis:
For node v8 and v9 - any idea what might be wrong? Perhaps the |
@inspiredware found the problem with the tests: b22612c |
[email protected] is now released with N-API support. Thanks @inspiredware and team: https://www.npmjs.com/package/node-pre-gyp |
Many thanks @springmeyer |
thanx a lot @springmeyer ! |
Thank you @springmeyer. I'm available to diagnose and correct any issues that may arise. |
@inspiredware Can I ask for clarification on how this feature is meant to be used? If I understand correctly the N-API version replaces the Node module version and instead of publishing one binary for each platform + Node module version, we now have to publish a binary for each platform + N-API version? I am attempting to build a module with
Would love to hear your thoughts on these issues. I'm eager to get this all working and publish a stable N-API enabled module but not really succeeding so far. If you wish to take a look, the current code can be found in https://github.com/rolftimmermans/zeromq-ng/tree/various-nodes. |
@rolftimmermans thank you for your questions. They help us improve our documentation for all users. One of the primary benefits of N-API is that the API is "ABI stable." What this means practically is that an N-API add-on you publish today will work indefinitely for all future versions of Node. Today the N-API version is 2. So, if you build today with You mention that you're creating a polyfill for features recently added to N-API. I assume those features would have been added in version 2. So in this case you need to build against versions 1 and 2. As you mention, this will fire off two builds, with This build will continue to work for all future versions of N-API beyond version 2. The question of building with earlier versions of Node is confusing because builds can occur in two different settings: 1. You build as a publisher. This is the whole purpose of When you build as a publisher, you need to be building with a version of Node that supports the highest N-API version against which you are building. If you declare that your module supports N-API version 3, you need to be building with a version of Node that supports N-API version 3. A version of Node that supports a certain N-API version can also be used to build an add-on for all previous N-API versions. I agree that the current implementation is naive and will add a version check. If your users are not able to download one of your pre-built binaries, they will need to build it themselves. In that case 'node-pre-gyp` checks to see the N-API version supported by the Node they have installed. It chooses the highest version of your add-on supported by the user's Node and build against just that one version. If the user's Node version is not high enough, the user receives an error message and the build fails. The I hope I've answered your questions. If not, please let me know. |
@inspiredware Thanks for your excellent detailed response. This clears up a lot of confusion for me. I have one remaining question: what is the story for running tests and CI? Say I want to test the module with a certain, slightly older Node version that supports N-API but does not have the latest N-API version yet (example: some Node 8.x with N-API v1). How do I build it for just this N-API version? This is something I haven't been able to figure out. Previously I would just do a |
@rolftimmermans as we've discussed, I'll work on making the following improvements to the N-API support for
Please let know if there is anything else that comes to mind. Thanks again for your help improving this code. |
@ghost here, formerly @inspiredware. Just a note that I've not forgotten these proposed changes and expect to get to them in the next couple of weeks. |
This work is continued at #402. |
N-API Support
This pull request implements changes necessary to support the new N-API ABI-stable API for building Node native add-ons. The N-API Working Group discussion motivating these changes can be found here:
nodejs/abi-stable-node#263
I've thoroughly tested this code on Mac, Windows, and ARM. In addition, I've included a new
app7
project for automated testing.All
build.test.js
automated tests pass on Mac, Windows, and ARM with the sole exception of test 4 forapp1
on Windows only.I'm fairly confident this failure is not related to the changes I've made to support N-API builds.
I'm anxious to receive your comments and suggestions as landing this PR is necessary for N-API to leave experimental status.