Skip to content
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

Electron support #194

Closed
2 of 4 tasks
dherman opened this issue Mar 11, 2017 · 10 comments · Fixed by #435
Closed
2 of 4 tasks

Electron support #194

dherman opened this issue Mar 11, 2017 · 10 comments · Fixed by #435

Comments

@dherman
Copy link
Collaborator

dherman commented Mar 11, 2017

This issue is to track what's left to be able to legitimately claim we support using neon projects in Electron apps.

@dherman
Copy link
Collaborator Author

dherman commented Mar 11, 2017

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.

  1. Create a simple neon module (I made one that just has a function that returns "hello neon") but don't build it.
  2. Create a simple electron app, add the neon module as a dependency, and have the app require and use the neon module (I just did document.write(nativeModule.hello())).
  3. Follow almost the directions from "Using Native Node Modules":
# 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
  1. Go into the native module's directory and run npm install.
  2. Run the electron app to test whether it loads the native module without an error.

@ffflorian
Copy link
Contributor

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.

@dherman
Copy link
Collaborator Author

dherman commented Mar 13, 2017

@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.

@anaisbetts
Copy link

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

@dherman
Copy link
Collaborator Author

dherman commented Mar 22, 2017

@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.

@anaisbetts
Copy link

Just so I don't lose it, I did some research on what we need to fix inside electron-rebuild:

  1. electron-rebuild uses node-gyp rebuild instead of npm rebuild
  2. electron-rebuild explicitly looks for binding.gyp when it prob shouldn't
  3. electron-rebuild looks for the build result in build/Release when neon puts it in native

@amaury1093
Copy link

amaury1093 commented Apr 6, 2019

Latest 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 🎉.

@Abdillah
Copy link

Abdillah commented Jun 2, 2019

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 electron@5.0.2 and node@12.0.0 after applying a patch.

@John0x
Copy link

John0x commented Jul 4, 2019

Any news about this?
It's working with electron 3 but not with version 4 or 5

@nukeop
Copy link

nukeop commented Aug 23, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants