electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.64k stars 1.74k forks source link

Native dependencies (leveldown): building on (macOS) arm64 for x64 #7586

Closed rasgo-cc closed 1 year ago

rasgo-cc commented 1 year ago

My app has leveldown as a dependency (through pouchdb) and it seems that whenever building it on macOS arm64 and for x64, the binaries picked are still the ones for arm64. When running the app on x64, the app never really starts and I get this error on Sentry (not sure how I could get it any other way as the stdout/stderr doesn't show this):

dlopen(/Applications/BOMIST.app/Contents/Resources/app.asar.unpacked/node_modules/leveldown/build/Release/leveldown.node, 1): no suitable image found.

While building the app this is what I get:

  • writing effective config  file=dist/builder-effective-config.yaml
  • rebuilding native dependencies  dependencies=leveldown@5.6.0, leveldown@5.6.0 platform=darwin arch=x64
  • rebuilding native dependency  name=leveldown version=5.6.0
  • rebuilding native dependency  name=leveldown version=5.6.0
  • packaging       platform=darwin arch=x64 electron=24.3.0 appOutDir=dist/mac
  • signing         file=dist/mac/BOMIST.app 

From here it looks like it picks the arch correctly but in practice the arm64 binaries are still used?

On arm64 I get a build directory on node_modules/leveldown/build/Release but on x64 that directory is not created, not sure if that helps.

Initially I was trying to build for arch=universal but figured that simply building for x64 from arm64 would yield the same result.

Any idea what's going wrong?

rasgo-cc commented 1 year ago

Was able to overcome this by building "fat" binaries for leveldown and manually copying them (the build folder) into node_modules/leveldown/build (this, on macOS arm64).

Reference: https://github.com/Level/leveldown/issues/766#issuecomment-907793537

rasgo-cc commented 1 year ago

For reference: Setting buildDependenciesFromSource=true should also work.

ufukomer commented 10 months ago

@rasgo-cc buildDependenciesFromSource=true does not work when I build on arm64 and run on x64. Can you help me with adding prebuild leveldown into my project? https://github.com/Level/leveldown/issues/766#issuecomment-907793537 I am using PouchDB and leveldown is a dependency of it. I have no idea how to do this.