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-builder and cross platform build #1697

Closed
KillerCodeMonkey opened this issue May 13, 2019 · 9 comments
Closed

electron-builder and cross platform build #1697

KillerCodeMonkey opened this issue May 13, 2019 · 9 comments
Labels

Comments

@KillerCodeMonkey
Copy link

Hey there i want to build a macos electron app on an ubuntu machine.

Sharp is the only "native" module. But i think the problem is, that when electron-builder is running, it simply uses the linux native module instead of installing the version for the target electron build os.

Is this even possible or is there a way to achieve this?

The build on my CI works withou any error, but when i start my app it freezes directly without throwing an error. If i remove sharp, it works again.

I thought when this repo provides all native prebuilts electron-builder downloads the one necessary for the target platform.

@lovell
Copy link
Owner

lovell commented May 13, 2019

The prebuild-install module used by sharp looks for the --platform flag when (re)building.

However electron/rebuild#176 suggests that electron-rebuild does not support this flag, which makes sense when compiling from source but not when using prebuilt binaries. Perhaps ask on that repo if they'll reconsider?

@KillerCodeMonkey
Copy link
Author

KillerCodeMonkey commented May 14, 2019

Thanks for your fast response. I am a little bit confused which electron-userland build tools is using other libraries like electron-rebuild :D and how without digging to deep into them.

And in the electron-build documentation it is mentioned that crossplatform builds are possbile if the native module provides prebuilds for each platform.

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.

@KillerCodeMonkey
Copy link
Author

Hey i checked the output of my ci when building the app on ubuntu for macos:

• rebuilding native production dependencies platform=darwin arch=x64
• rebuilding native dependency name=sharp

and electron-builder seems like to use node-pre-gyp

@lovell
Copy link
Owner

lovell commented May 14, 2019

sharp provides pre-built binaries via prebuild rather than node-pre-gyp, but their approach is similar.

The options listed at https://www.electron.build/configuration/configuration#Configuration-buildDependenciesFromSource might help, e.g. npmRebuild might need to be set to false to prevent a compilation attempt.

Failing that you'll need to ask this on the relevant electron repo - good luck!

@KillerCodeMonkey
Copy link
Author

@lovell yeah sorry to bother you with that. But like i said i lost my mind during searching through all the possibilities. And do not understand the arguments. I thought buildDependenciesFromSource does not use the prebuild ones, instead it builds the things from source code. and npmRebuild is the right option to rebuild node-modules for the correct platform during the build step.

So sorry and thanks for your help :). Nice support and fast.

@KillerCodeMonkey
Copy link
Author

so i will close this issue here. Thanks again 👍

@ustun
Copy link

ustun commented Oct 21, 2020

Sorry to bump a closed issue, but I think this is still the case and I think the only way to make it work is to build under the target platform rather than cross-compiling.

Here is what I found out:

1/ Pre-v0.26, separate electron prebuilts were provided, but it seems that with v0.26, there is a single napi release.

electron-builder uses a package called prebuild-install internally, with the following command inside sharp directory:

node ../prebuild-install/bin.js --platform=win32 --arch=x64 --target=8.5.2 --runtime=electron --verbose --force

This fails since it makes a request to the following non-existent url: https://github.com/lovell/sharp/releases/download/v0.26.2/sharp-v0.26.2-electron-v76-win32-x64.tar.gz

pre-0.26, it was making a request to the following url, which succeeded:

https://github.com/lovell/sharp/releases/download/v0.25.4/sharp-v0.25.4-electron-v76-win32-x64.tar.gz

2/ The issue of libvips.

However, even at v0.25, it was not properly working since libvips was still using the host library version. So, the correct sharp.node would be bundled, but the other libraries would be the incorrect versions.

That leads me to conclude that the only way to make it work is to build on the target platform (or via docker.) Could you please confirm that is the case or do you know if there is anything I'm missing?

@lovell
Copy link
Owner

lovell commented Oct 21, 2020

@ustun As of v0.26.0, Electron should use the same N-API binaries as Node.js - see commit dcc42f8 - make sure you're not overriding target or runtime in your own configuration.

If you're still having problems, please open a new issue with a reference to a complete, standalone code repo that allows someone else to reproduce this.

@ustun
Copy link

ustun commented Oct 21, 2020

Thank you for the explanation @lovell

I believe the issue is with prebuilt-install and electron-builder. I'll ask those maintainers on how to proceed.

In the meantime, we are planning to use GitHub Action to compile and get a prebuilt version for our needs.

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

No branches or pull requests

3 participants