anaisbetts / grunt-build-atom-shell

Grunt task to build Electron and rebuild node modules
MIT License
122 stars 11 forks source link

Executable built with script can't load addons #26

Closed toly-k closed 9 years ago

toly-k commented 9 years ago

build-atom-shell script generates an executable that can't load C++ addons.

To reproduce the issue, I have built a hello world addon following these steps: https://nodejs.org/api/addons.html#addons_hello_world rebuilt it for atom-shell node-gyp rebuild --target=0.21.2 --arch=ia32 --dist-url=https://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist

Downloaded atom-shell 0.21.2 loads the addon as expected:

E:\Projects\native-app>"E:\atom\atom.exe" hello.js

E:\Projects\native-app>[6948:0331/170749:INFO:CONSOLE(0)] world

atom-shell built with the following grunt task:

'build-atom-shell': {
      tag: 'v0.21.2',
      nodeVersion: '0.21.0',
      buildDir: 'C:/build',
      projectName: 'test',
      productName: 'TestBuild'
    }

throws an error:

E:\Projects\native-app>"E:\Release\Release\test.exe" hello.js

E:\Projects\native-app>[3964:0331/170825:INFO:CONSOLE(0)] App throwed an error w
hen running [Error: The specified module could not be found.
E:\Projects\native-app\build\Release\addon.node]

capture

test.exe is built on Windows 7, node v0.10.36

Is it a known issue? Is there a version that will work or a workaround?

maxkorp commented 9 years ago

I might not be the best source for solutions, but the only thing that I see is that when building the module, you're not setting HOME to the appropriate value. From what I can glean from trying to disect the plugin, that should be something like HOME="~/.test/.node-gyp/0.21.0" node-gyp rebuild --target=0.21.2 ...

where the version in the home is the same as the nodeVersion in the grunt config. I may be wrong, but that's where I'd start.

anaisbetts commented 9 years ago

@Akudrevatykh You shouldn't be calling node-gyp rebuild at all if you're using this Task, it's done for you automatically.

toly-k commented 9 years ago

@maxkorp hey, thanks for the pointer in the right direction! :) I'm not sure what "HOME" would be on Windows, but replacing C:\Users\user.node-gyp\0.21.2\Release\node.lib with node.lib built by this task totally worked.

@paulcbetts I am calling node-gyp rebuild to build my native addon.

anaisbetts commented 9 years ago

@Akudrevatykh That's what I'm saying, you should not do that, at all. grunt-build-atom-shell already rebuilds all of your native modules installed via npm install.

maxkorp commented 9 years ago

@paulcbetts thats impying that all of your node modules youre using in whichever app you're building are currently contained in the current projects node_modules, which is not necessarily a guarantee.

anaisbetts commented 9 years ago

@maxkorp It's recursive, you don't have to do that. Or are you saying you have separate, top-level node_modules folders?

toly-k commented 9 years ago

@paulcbetts Thanks for your response, but I am still struggling to understand at what point is this grunt task supposed to rebuild my native addon.

I have a private native addon(not installed via npm), that I want to use in my app. What I did: 1) Build test.exe with grunt-build-atom-shell 2) Copy app to resources or call test.exe + path to the app 3) At this point the native module fails to load (unless I replace C:\Users\user.node-gyp\0.21.2\Release\node.lib with a .lib built by the script and rebuild the addon).

Basically I only use the script to build atom-shell with a different name. At no point it is aware of my native app. How do I fix that? is targetDir supposed to point to my app folder or something?

maxkorp commented 9 years ago

@paulcbetts I had a module that existed in another folder somewhere else on the drive that isn't npm linked (or symlinked). I got around to basically copying the components needed to rebuild into my node modules folder, but that shouldn't have to be the case.