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

Overriding the platform? #176

Closed
xaviergonz opened this issue May 25, 2017 · 5 comments
Closed

Overriding the platform? #176

xaviergonz opened this issue May 25, 2017 · 5 comments

Comments

@xaviergonz
Copy link

I'd like to cross compile an OSX electron application from linux using electron-packager, and while electron-rebuild allows to override the arch it seems to take the platform from process.platform.

Would it be possible to add a parameter to override the target platform?

@MarshallOfSound
Copy link
Member

@xaviergonz You can't cross compile native node modules, it just doesn't work. That's why you can't override process.platform. Native modules require OS specific header files that typically only exist on the target OS

@KillerCodeMonkey
Copy link

KillerCodeMonkey commented May 14, 2019

So a little question after all these year:

Lovell linked an issue created by me on his beautiful sharp node module.
I want to make a crossplatform (linux os to mac package) build with sharp as native module.

I am using electron-builder and sharp provides prebuilds for the target-platform os.
In the https://www.electron.build/multi-platform-build docs you can read that

Don’t expect that you can build app for all platforms on one platform.

But

If your app has native dependency, it can be compiled only on the target platform unless prebuild is not used.

prebuild is a solution, but most node modules don’t provide prebuilt binaries.

And this is now the case. But when i am building my app on Ubunutu for macOS it does not work, because the target binaries are used instead of the platform even if there are the right files available.

Is there any was to achieve my goal?

Thanks :)

@fishbone1
Copy link

@MarshallOfSound Yeah - I had the same thought as @KillerCodeMonkey . I understand it's a problem to cross compile native modules, but my native modules are available as "prebuild". So no cross compilation required. Would this be possible or is it a problem in this case as well? If yes - how is electron-builder achieving it? At least their docs state that it's possible (see KillerCodeMonkey's quote above).

@fishbone1
Copy link

@KillerCodeMonkey It seems you confuse electron-builder with electron-packager/electron-rebuild. You do not need electron-rebuld if you are using electron-builder, it does everything for you.

However I use electron-packager and electron-winstaller, because I want to keep Squirrel installer (instead of NSIS) with auto-updates on a generic HTTP server, which seems not possible with electron-builder.

Due to a lucky coincidence, I found out, how electron-builder manages Windows builds on Linux. I created a temporary branch and installed electron-builder to figure it out. When I did something wrong, electron-builder revealed how it invoked prebuild-install. It turned out that prebuild-install has hidden parameters --platform and --force:

(cd node_modules/@thiagoelg/node-printer && node /home/myuser/myapp/src/electron/node_modules/prebuild-install/bin.js --platform=win32 --arch=x64 --target=10.1.3 --runtime=electron --verbose --force)

After that I run electron-packager. First it didn't work. But it was just because electron-rebuild reverts everything. I had to remove the hook:

packager: ({
  // ...
  // afterCopy: [(buildPath, electronVersion, platform, arch, callback) => {
  //   rebuild({ buildPath, electronVersion, arch })
  //     .then(() => callback())
  //     .catch((error) => callback(error));
  // }],
})

Now I successfully packaged my Windows application on Linux, including native dependecy (YEAH!)

Well the question is why did I expect anything different from electron-rebuild. Either you rebuild or you have prebuilt? On the other hand I think it would be more convenient if electron-rebuild does the call for you as end users like me don't understand all the little details. It took me hours to figure everything out. As you can see above I have to cd into the dependencies directory. Effectively I trick prebuild-install to think it's running in a project root.... Yes I think this should also be fixed by prebuild-install and you could say it is not electron-rebuild's responsibility. But isn't the whole purpose of electron-rebuild better convenience in the first place? What do you think @MarshallOfSound ?

@cocktailpeanut
Copy link

Hey guys, I've been struggling with this problem too, and think I might have solved the problem.

Basically I found that the cross platform prebuild-install was NOT working as intended, from the very beginning.

The reason was, for some reason the platform attribute was always set to process.platform no matter what flag you pass into electron-builder AND rebuild.

I had to update both electron-builder AND @electron/rebuild to respect the platform option. Please check out the PRs:

Hoping this will get merged in soon so I can use it without monkey patching node_modules no my side all the time.

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

No branches or pull requests

5 participants