-
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
Cross compilation #829
Comments
It's not explicitly supported at the moment and there are a few places in node-gyp where it assumes that the host arch/os == the target arch/os although you can probably work around that without too much effort. More importantly, add-ons need to be compatible with cross-compiling. Add-ons with simple binding.gyp files probably are but more complex ones need not be. |
@bnoordhuis, i have a similar question. I've been toying with electron-rebuild. as you may be aware, my node version !== electron's node version, so electron-rebuild has to recompile some modules against it's version. I see the rebuild module doing something like Do you have any tips on how I can best use npm to recompile against a target version? Assume that I have the target header files already downloaded. I need to use npm vs explicit node-gyp as there may be other lifecycle hooks that must be run for a module at install. I will gladly add to the README with pertinent docs if you can assist! |
@cdaringe You probably need to specify |
@bnoordhuis, thanks, I'll check it out. I did trace my original problem to the fact that some npm lifecycle scripts were conditionally rebuilding based on |
+1 |
Has any progress been made on this? Also is changing the OS inside node-gyp enough to make it cross compile? |
Well, I need to cross compile, so I'll be messing around with node-gyp or alternatively using raw gyp. I'll let you know how it goes. |
Any update on this @tyduptyler13 ? |
I have yet to prove this but I am pretty sure you can pull it off if you compile node itself from the platform you are compiling on as well. The reason being, it needs the same mangling scheme as your addon. I will get around to doing this soon. I am currently moving and starting a new job so I'm a bit busy lately. It would be nice if there is a way to create a translation layer between windows and linux compiled code so that you can still do the dynamic linking at runtime (how node calls your stuff) |
@tyduptyler13 So uh.. webassembly? |
That's would be cool :-P |
Web assembly is a target of mine, it usually has the same mangling scheme as clang as it sort of emulates the behavior of a compiled C/C++ application. Another point I can make is that if your addon only exposes C style anythings, you can totally get away with cross platform compiles because C doesn't get its names mangled. Hence the "extern C" stuff in lots of the old school addons. I was exploring to see if node-gyp could just do some of this mangling management, but I haven't gotten deep enough to say yet. Either its loader could handle these weird schemes internally when selecting the C++ name OR it could try cheating and use ASM flags to manually set the name. The ASM would probably be easier, but could have issues if you don't handle all of the weirdness with namespaces, class names, templates, inheritance, etc. I'll keep you guys updated if I ever get my shit compiling cross platform. Also, side note: tempted to create a node driven build platform that sort of follows Gulp but would be more flexible in what it can compile. The goal is to allow node to compile c/c++/etc. That way I can remove gyp entirely and simplify the build process. Effectively it would be among gyp, make, cmake, and autotools type tools. This would definitely increase cross platform support. Would any of you be interested in using such a thing? |
Probably me, to port all my NodeOS custom build bash scripts :-) I was thinking also to do it myself, since I got them to have a somewhat similar structure and checkings (download sources, configure, make, make install), just only I don't have time, but would be a matter of porting them. You can take a look at them to know how they are organized and we could chat about moving it forward :-D |
Hi, my electron application has node ref and ffi modules for dll linking and it works perfectly fine on windows with electron-rebuild and after electron-builder but when I clone the source code on Ubuntu 18 and run the electron-rebuild the created exe file says %1 is not win32 application. Could anybody please help me out in this? I'm struggling a lot to get it worked. Thanks in advance. |
@mjangir You need to recompile your dll to .so for Linux and electron app will be work fine. It maybe be better to create dinamic linking library for all support platforms, then create a nodejs addon with your export functions. Then you can compile the addon for the node or the Electron App. If you have a question about creating add-ons, you can ask them |
I'm going to close this because I think a pull request by someone who wants this is going to be the only way forward here. Otherwise this issue is just going to stay open perpetually with occasional drop-ins. This will require external help to get it moving anywhere if it's still needed. |
@rvagg I was able to successfully rebuild native modules, even with |
@artus9033 with what you're suggesting how would that work for building on Linux to support Windows platforms? |
@rvagg wrote:
@artus9033 wrote:
Is there a pull request as @rvagg requested? |
I haven't tested it yet, but when I find time, I will give
@cclauss I will try to prepare one and reach out then, for now I just wanted to share this approach, as at the moment I don't have enough time to try to implement this as part of node-gyp. |
Did anybody got any updates? I want to know where/how to get the shared libraries to link to the N-API functions while cross-compiling. |
I've writing an N-API extension on Node.js 14.16.0 |
node-gyp does not support cross compilation nodejs/node-gyp#829 . prebuild-install properly detects that the current system is arm64 and there are not prebuilts available which causes the node-gyp rebuild to be executed in yarn. However since node-gyp does not support cross compilation is ends up building x86_64 binaries again. Additionally, the package.json of desktop-trampoline and desktop-notifications call the system install of node-gyp and not the version installed by node. The system install of node-gyp has an issue that causes linking to fail during cross compilation. Calling with npx results in using the node install of node-gyp and avoids this issue.
node-gyp does not support cross compilation nodejs/node-gyp#829 . prebuild-install properly detects that the current system is arm64 and there are not prebuilts available which causes the node-gyp rebuild to be executed in yarn. However since node-gyp does not support cross compilation is ends up building x86_64 binaries again. Additionally, the package.json of desktop-trampoline and desktop-notifications call the system install of node-gyp and not the version installed by node. The system install of node-gyp has an issue that causes linking to fail during cross compilation. Calling with npx results in using the node install of node-gyp and avoids this issue.
node-gyp does not support cross compilation nodejs/node-gyp#829 . prebuild-install properly detects that the current system is arm64 and there are not prebuilts available which causes the node-gyp rebuild to be executed in yarn. However since node-gyp does not support cross compilation is ends up building x86_64 binaries again. Additionally, the package.json of desktop-trampoline and desktop-notifications call the system install of node-gyp and not the version installed by node. The system install of node-gyp has an issue that causes linking to fail during cross compilation. Calling with npx results in using the node install of node-gyp and avoids this issue.
node-gyp does not support cross compilation nodejs/node-gyp#829 . prebuild-install properly detects that the current system is arm64 and there are not prebuilts available which causes the node-gyp rebuild to be executed in yarn. However since node-gyp does not support cross compilation is ends up building x86_64 binaries again. Additionally, the package.json of desktop-trampoline and desktop-notifications call the system install of node-gyp and not the version installed by node. The system install of node-gyp has an issue that causes linking to fail during cross compilation. Calling with npx results in using the node install of node-gyp and avoids this issue.
node-gyp does not support cross compilation nodejs/node-gyp#829 . prebuild-install properly detects that the current system is arm64 and there are not prebuilts available which causes the node-gyp rebuild to be executed in yarn. However since node-gyp does not support cross compilation is ends up building x86_64 binaries again. Additionally, the package.json of desktop-trampoline and desktop-notifications call the system install of node-gyp and not the version installed by node. The system install of node-gyp has an issue that causes linking to fail during cross compilation. Calling with npx results in using the node install of node-gyp and avoids this issue.
node-gyp does not support cross compilation nodejs/node-gyp#829 . prebuild-install properly detects that the current system is arm64 and there are not prebuilts available which causes the node-gyp rebuild to be executed in yarn. However since node-gyp does not support cross compilation is ends up building x86_64 binaries again. Additionally, the package.json of desktop-trampoline and desktop-notifications call the system install of node-gyp and not the version installed by node. The system install of node-gyp has an issue that causes linking to fail during cross compilation. Calling with npx results in using the node install of node-gyp and avoids this issue.
node-gyp does not support cross compilation nodejs/node-gyp#829 . prebuild-install properly detects that the current system is arm64 and there are not prebuilts available which causes the node-gyp rebuild to be executed in yarn. However since node-gyp does not support cross compilation is ends up building x86_64 binaries again. Additionally, the package.json of desktop-trampoline and desktop-notifications call the system install of node-gyp and not the version installed by node. The system install of node-gyp has an issue that causes linking to fail during cross compilation. Calling with npx results in using the node install of node-gyp and avoids this issue.
node-gyp does not support cross compilation nodejs/node-gyp#829 . prebuild-install properly detects that the current system is arm64 and there are not prebuilts available which causes the node-gyp rebuild to be executed in yarn. However since node-gyp does not support cross compilation is ends up building x86_64 binaries again. Additionally, the package.json of desktop-trampoline and desktop-notifications call the system install of node-gyp and not the version installed by node. The system install of node-gyp has an issue that causes linking to fail during cross compilation. Calling with npx results in using the node install of node-gyp and avoids this issue.
rework arm/arm64 dependencies and environment variables set environment variables for x64 linux too otherwise they are set to empty and break compilation. these environment variables are necessary since node-gyp does not support cross compilation without them nodejs/node-gyp#829
rework arm/arm64 dependencies and environment variables set environment variables for x64 linux too otherwise they are set to empty and break compilation. these environment variables are necessary since node-gyp does not support cross compilation without them nodejs/node-gyp#829
the environment variables are necessary since node-gyp does not support cross compilation without them nodejs/node-gyp#829
Hello,
Is it possible to do cross-compilation with node-gyp? I want to compile native addon for linux while running node-gyp build on Windows machine.
I am able to build addon on each of the platforms, but I would like to do cross compilation.
Thank You,
Peter
The text was updated successfully, but these errors were encountered: