-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add target_modules_version
variable into generated config.gypi file
#855
Conversation
|
||
for (var i = 0; i < sources.length; ++i) { | ||
try { | ||
var source = fs.readFileSync(sources[i], { encoding: 'utf8'}) |
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 try/catch should only be around this statement. Style nit: space before }
.
Can you add a couple of regression tests? You'll probably need to adjust the logic a little so you can test it without trying to read from disk (or make it use fixtures somehow.) |
Reworked getModulesVersion() to read a particular file, depending on the target Node.js version. No tests were added yet, because I don't know how to make appropriate fixtures for them. |
Ideally this should be provided by node itself in it's config.gypi file. |
It may be handy to have multiple native addon binaries for several Node.js versions (i.e. 0.12, 4.X, 5.X). Node.js has a value for the native modules version as `process.versions.modules`. A particular C++ addon can be loaded in JavaScript depending on Node.js version like this: // loads 'addon_win32_x64_m47.node' for Node.js 5.0 on Windows x64 // loads 'addon_linux_x64_m46.node' for Node.js 4.X on Linux x64 var native = require(addon' + process.platform + '_' + process.arch + '_m' + process.versions.modules + '.node'); The target binary file name should be set with `product_name` directive in binding.gyp file in a such way: { 'targets': [ { 'product_name': 'addon_<(target_platform)_<(target_arch)_m<(target_modules_version)' ... # rest of GYP directives } ] } where `target_platform` is a configuration variable with value from Node.js `process.platform` property. But the `process.versions.modules` value can't be used for `target_modules_version` since node-gyp can build targets for different Node.js versions specified with a `--target` command-line option. To resolve this issue, a function getModulesVersion() was added on `configure` step to get a value of `NODE_MODULE_VERSION` defined in `node_version.h` file in a supplied directory with Node.js development files.
Use value of release.semver to determinate file name and location with NODE_MODULE_VERSION define, and to read this file depending on target Node.js version. Tested with Node.js versions: 0.8.4, 0.10.25, 0.11.4, 0.11.5, 0.12.0, iojs-1.0.0, iojs-2.0.0, iojs-3.0.0, 4.X, 5.X Added verbose log messages for the target_arch, target_platform, and target_modules_version variables.
Rename getModulesVersion to nodeModulesVersion function and move it out of configure() function for testing purpose. Expose nodeModulesVersion() function in `configure.test` to call it tests. Run tests for the current Node release and for all installed targets.
44f04b2
to
1844911
Compare
Renamed function to |
@bnoordhuis could you review recent changes please? |
|
||
// set the target modules version | ||
variables.target_modules_version = nodeModulesVersion(nodeDir) | ||
log.verbose('build/' + configFilename, 'modules version: ' + variables.target_modules_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.
Can you wrap lines at 80 columns? I realize there are long lines elsewhere but I'd like to avoid introducing new ones.
This needs more tests, there are quite a few cases that aren't covered yet. For example, the use case of If you make the |
@bnoordhuis thank you very much! I will think on more tests. |
'target arch: ' + variables.target_arch) | ||
|
||
// set the target_platform variable | ||
variables.target_platform = process.platform |
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.
Maybe we should allow manual override here as well? What about cross-platform builds?
Something that just came to mind: building for electron / nw.js / node-webkit. Also, it's perhaps worth pointing out that node.js v6.3.0 introduced the |
@bnoordhuis do you think that |
Maybe to v4 but not to v0.10 and v0.12. Those are near their end of life anyway, though. |
@bnoordhuis should we open an issue on @nodejs/lts? |
@thealphanerd Sure, go ahead. |
Having this in some final releases of 0.10 and 0.12 would be ultra cool. Actually this patch could become a separate npm module which kicks in as a fallback if module version is not available via the gypi files. |
The Caveat emptor though, v0.10 and v0.12 are in maintenance mode. Normally only security fixes and critical fixes are accepted but since |
Enable targetting of a different node version than the currently running one when building binary modules. Based on nodejs/node@410296c37 PR-URL: nodejs#7808 Ref: nodejs/node-gyp#855
Enable targetting of a different node version than the currently running one when building binary modules. Based on nodejs/node@410296c37 PR-URL: nodejs#8027 Ref: nodejs#7808 Ref: nodejs/node-gyp#855
Enable targetting of a different node version than the currently running one when building binary modules. Based on nodejs/node@410296c37 PR-URL: nodejs#8171 Ref: nodejs#8027 Ref: nodejs#7808 Ref: nodejs/node-gyp#855
Enable targetting of a different node version than the currently running one when building binary modules. Based on 410296c37 PR-URL: #8171 Ref: #8027 Ref: #7808 Ref: nodejs/node-gyp#855 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Enable targetting of a different node version than the currently running one when building binary modules. Based on 410296c37 PR-URL: #8171 Ref: #8027 Ref: #7808 Ref: nodejs/node-gyp#855 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
@pmed Do you think this PR is still necessary? |
As I understand, the variable I think there is no more need to do the same thing in node-gyp, so let's close this PR. |
Okay thanks, I'll close. |
Enable targetting of a different node version than the currently running one when building binary modules. Based on 410296c37 PR-URL: #8171 Ref: #8027 Ref: #7808 Ref: nodejs/node-gyp#855 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Enable targetting of a different node version than the currently running one when building binary modules. Based on 410296c37 PR-URL: #8171 Ref: #8027 Ref: #7808 Ref: nodejs/node-gyp#855 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Enable targetting of a different node version than the currently running one when building binary modules. Based on nodejs/node@410296c37 PR-URL: nodejs#8027 Ref: nodejs#7808 Ref: nodejs/node-gyp#855
Enable targetting of a different node version than the currently running one when building binary modules. Based on nodejs/node@410296c37 PR-URL: nodejs#8027 Ref: nodejs#7808 Ref: nodejs/node-gyp#855
It may be handy to have multiple native addon binaries for several Node.js versions (i.e. 0.12, 4.X, 5.X). Node.js has a value for the native modules version as
process.versions.modules
.A particular C++ addon can be loaded in JavaScript depending on Node.js version like this:
The target binary file name should be set with
product_name
directive in binding.gyp file in a such way:where
target_platform
is a configuration variable with value from Node.jsprocess.platform
property.But the
process.versions.modules
value can't be used fortarget_modules_version
since node-gyp can build targets for different Node.js versions specified with a--target
command-line option.To resolve this issue, a function getModulesVersion() was added on
configure
step to get a value ofNODE_MODULE_VERSION
defined innode_version.h
file in a supplied directory with Node.js development files.