-
Notifications
You must be signed in to change notification settings - Fork 284
Rely on node-pre-gyp, prebuild binaries #486
Conversation
Building for Electron$ ./node_modules/.bin/node-pre-gyp build --build-from-source --target=v0.35.2 --runtime=electron
node-pre-gyp info it worked if it ends with ok
node-pre-gyp info using node-pre-gyp@0.6.18
node-pre-gyp info using node@5.1.0 | darwin | x64
gyp info it worked if it ends with ok
gyp info using node-gyp@3.0.3
gyp info using node@5.1.0 | darwin | x64
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
CXX(target) Release/obj.target/zmq/binding.o
SOLINK_MODULE(target) Release/zmq.node
ld: warning: directory not found for option '-L/opt/local/lib'
COPY /Users/rgbkrk/code/src/github.com/JustinTulloss/zeromq.node/builds/zmq.node
TOUCH Release/obj.target/action_after_build.stamp
gyp info ok
node-pre-gyp info ok
$ ./node_modules/.bin/node-pre-gyp package --target=v0.35.2 --runtime=electron
node-pre-gyp info it worked if it ends with ok
node-pre-gyp info using node-pre-gyp@0.6.18
node-pre-gyp info using node@5.1.0 | darwin | x64
node-pre-gyp info package packing /Users/rgbkrk/code/src/github.com/JustinTulloss/zeromq.node/builds
node-pre-gyp info package packing /Users/rgbkrk/code/src/github.com/JustinTulloss/zeromq.node/builds/zmq.node
node-pre-gyp info package Binary staged at "build/stage/zmq-v2.14.0-electron-v0.35-darwin-x64.tar.gz"
node-pre-gyp info ok |
As for where these get shipped, I'd personally prefer to use GitHub releases. I'm in no liberty to do so. |
"devDependencies": { | ||
"should": "2.1.x", | ||
"aws-sdk": "^2.2.26", |
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.
why the aws-sdk?
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.
That's just for uploads (if the binaries end up in an S3 bucket). I can rip this out of course, as I'd prefer to rely on GitHub releases like I do for other packages.
people frequently run into problems when they build zmq with electron when installing the module from a different version of node that executes the module. IMO, most install difficulties center around the particular versions of node running |
That's certainly true. Normally people solve this by rebuilding with electron-rebuild. I'd like to have people be able to rely on If binaries are available for both nodejs and Electron, Electron packages that rely on
With this new setup, it's a matter of:
Perhaps it's even simpler than that and you see a better way. |
What do you think @ronkorving? |
// Replaces `var zmq = require('./bindings')`; | ||
var binary = require('node-pre-gyp'); | ||
var path = require('path'); | ||
var bindingPath = binary.find(path.resolve(path.join(__dirname, '../package.json'))); |
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.
It might be cleaner to join(__dirname, '..', 'package.json')
to avoid bias towards forward slashes.
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.
Good call, thank you.
I think this would be a great solution. Is there any way we could allow custom download URLs through an environment variable for example (which could point to a path on disk)? Is https://zmq-prebuilt.s3-us-west-1.amazonaws.com something that should actually exist, or would that be something we manage? I don't think it's our job to make zmq binaries tbh. If there's no official source for releases outside of GitHub, let's stick to GitHub. |
agreed. also doesn't electronic-prebuilt solve this particular use-case/problem? |
I'm not sure, haven't tried.
That definitely doesn't exist currently. That was a placeholder and yes we'd have to manage it.
Electron prebuilt provides prebuilt versions of Electron. Someone, somewhere, still has to build
Ok, let's change this PR up a bit and not post binaries. If the build at least goes through node-pre-gyp like this, I can create If you're game on for automatically posting builds for tags, I'm happy to introduce it here and help maintain it. |
@@ -71,6 +71,17 @@ | |||
], | |||
}], | |||
] | |||
}, | |||
{ | |||
"target_name": "action_after_build", |
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.
rather than adding a 2nd compile target and linking back the original compiled binary, I think it would be better to add an optional condition passed at the command line during an npm install.
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.
This is the compile target that node-pre-gyp
is relying on.
I still think we can improve this PR. rather than adding a 2nd compile target and linking back the original compiled binary, I think it would be better to add an optional condition passed at the command line during an npm install. this is how we can optionally change the original binary that we're linking to when we compile the final node gyp binary that gets called from v8. We have a similar option in node-nanomsg where the scenario is slightly different--just that it pulls from a system library rather than the library source code packaged with the node module during npm install. see https://github.com/nickdesaulniers/node-nanomsg/blob/master/deps/nanomsg.gyp and how we implemented that in the main gyp file, https://github.com/nickdesaulniers/node-nanomsg/blob/master/binding.gyp#L13-L15 and then also I'd recommend taking a look at the optional command line install flag: https://github.com/nickdesaulniers/node-nanomsg#install |
I've gone a different route here, which is to rely on prebuild and create a Longer term flow: zeromq has added gyp support to zproject and is in the process of creating bindings for the whole zeromq stack. |
Hey all, I've been wanting to make installation and usage of zmq across runtimes and versions super easy. Currently this goes well if the user has their development environment setup. For my own cases, I want to use
zmq
in Electron apps, Atom, and of course server side without needing a build environment.My ideal use case is that
zmq.node
gets fetched for them and they're able to rely on that directly, across all platforms, runtimes (Electron, node), and targets (versions of the runtimes). Hopefully this would help with #360, relying on a better experience instead of assuming people will read documentation.The major con to this PR is that if you want to link to your own zmq headers, we'd need to have two different options. However, node-pre-gyp can always do a full build if requested
node-pre-gyp build --build-from-source
.I'm more than happy to help setup the Appveyor and Travis setup so these can be shipped in automation on tagged builds.
Let me know what you think!