This issue is to track what's left to be able to legitimately claim we support using neon projects in Electron apps.
OK, I got my first "hello world" working manually. Here's the steps I took to do it, so we can at least reproduce it. This is obviously not what we want the final workflow to be, but I need to study electron-builder and see if that will have a nice compatibility story. (Otherwise we may have to either build a new electron tool, which I'd rather not do, or work on integrating with electron-rebuild. But my current hunch is that electron-builder may work out better.)
I got this working with Node v7.5.0. I don't think the version of node on the system has to be a perfect match for the version of node bundled with Electron, but I'm not sure how close it has to be.
"hello neon") but don't build it.document.write(nativeModule.hello())).# Electron's version.
export npm_config_target=1.6.2
# The architecture of Electron, can be ia32 or x64.
export npm_config_arch=x64
export npm_config_target_arch=x64
# Download headers for Electron.
export npm_config_disturl=https://atom.io/download/electron
# Tell node-pre-gyp that we are building for Electron.
export npm_config_runtime=electron
# Tell node-pre-gyp to build module from source code.
export npm_config_build_from_source=true
# Ensure ~/.electron-gyp exists
mkdir -p ~/.electron-gyp
# Install all dependencies, and store cache to ~/.electron-gyp.
npm config set cache ~/.electron-gyp
npm install.I don't think the version of node on the system has to be a perfect match for the version of node bundled with Electron, but I'm not sure how close it has to be.
Which version of Electron were you using? Because the ABI versions of the Node.js installation used to compile the module and Electron have to match - so when you build it with Node v7.5.0 (ABI 51) it won't work with Electron 1.6.3 (ABI 53). You will get an error:
The module [...] was compiled against a different Node.js version using NODE_MODULE_VERSION 51. This version of Node.js requires NODE_MODULE_VERSION 53. Please try re-compiling or re-installing the module.
@ffflorian I was using v7.5.0. I _believe_ the reason it does work is that setting the npm environment variables and configuration settings (step 3 above) tells node-gyp to download the C++ headers from electron's web server, and selects the ones that match the electron version. So when node builds the native module with npm install, that triggers a cargo build; cargo builds neon-runtime, which runs node-gyp, which in turn consults the environment variables to know where to download the C++ headers from.
Integrating with electron-rebuild is a better choice, it's integrated with the rest of the Electron ecosystem far better, electron-builder is kind of the legacy solution to a lot of these problems
@paulcbetts Thanks, that's helpful to know. I've almost got a first step working that makes building possible at all but doesn't integrate with either. I'll focus more on electron-rebuild, though. I have had a first conversation with @MarshallOfSound, who's happy to work with us to integrate into electron-rebuild.
Just so I don't lose it, I did some research on what we need to fix inside electron-rebuild:
node-gyp rebuild instead of npm rebuildbinding.gyp when it prob shouldn'tbuild/Release when neon puts it in nativeLatest Electron releases are ^4 and ^5, which use a custom NODE_MODULE_VERSION=69, see here. However node LTS has version 67 right now.
When requiring the generated index.node, I get
Uncaught Exception:
Error: Cannot open /{path}/native/index.node: Error: The module '/{path}/native/index.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 67. This version of Node.js requires
NODE_MODULE_VERSION 69. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
Edit: Following the guide https://neon-bindings.com/docs/electron-apps, it actually works with Electron@4 馃帀.
I have an initial implementation that propose an easy setup flow. Simply ensure that the electron is in the $PATH and activate the cargo feature electron in native to set it up:
[dependencies]
neon = { version = "0.2.1", features = [ "electron" ] }
I want to submit a pull request if we agree on this.
Note:
Tested using [email protected] and [email protected] after applying a patch.
Any news about this?
It's working with electron 3 but not with version 4 or 5
Actually, I'm getting errors about missing symbols on versions 3,4,5 and latest. E.g.:
undefined symbol: _ZN2v88Function3NewENS_5LocalINS_7ContextEEEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEENS1_IS5_EEiNS_19ConstructorBehaviorENS_14SideEffectTypeE
Most helpful comment
Any news about this?
It's working with electron 3 but not with version 4 or 5