Cross compile native modules for electron.js


#1

I’ve spent a few hours looking for the proper suggestion or documentation on the way to go for compiling a native module for another platform. So for example say I want to build an eletron.js application for OSX. I do have an OSX host to test with. Is there a method for cross compiling? If not do I need to create the eletron package independently on each OS (linux,osx,win32) or can I just compile the required module and somehow use it on my system to create the packages for all os’s.


#2

So technically, the answer is no. You can use something like [electron-packager] (https://github.com/maxogden/electron-packager) and set it to the all option. However, you will not be able to set a number of platform specific options if you do so. If you are doing something more professional then you will want to set all these options. You will then have at least 3 different distributions. (Windows, Linux, Mac). For testing on OSX there’s not a ton of options. I’ve read articles where you can hack older osx to run shittly on older virtual box, or if you expect to make any money at all from this, buy a used mac off craigslist, and if you don’t expect any money, just wait for user feedback.


#3

Some project maintainers have a repo with pre-build binaries for all common node.js variants (e.g. node-sqlite3). They use node-pre-gyp to install the version matching your system or build configuration.

So if you just rely on modules that utilizes these methods you might be lucky to have a cross-build running successfully.

Needless to say that if you have your own C/C++ code that you want to integrate with Electron you still have to build the wrapper on all possible platforms.