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

Plans to Support Apple Silicon builds? #5392

Closed
eengoron opened this issue Nov 3, 2020 · 107 comments
Closed

Plans to Support Apple Silicon builds? #5392

eengoron opened this issue Nov 3, 2020 · 107 comments
Labels

Comments

@eengoron
Copy link

eengoron commented Nov 3, 2020

Are there current plans to support Apple Silicon builds with electron-builder? We're currently in the process of making sure our electron app is ready for ARM support, so I wanted to make sure that we'd be able to build to those targets using electron-builder.

If so, what does the release timeline look like for that?

Since #5095 was closed with no resolution, I figured it best to open a new issue.

@ahmadwaliesipick
Copy link

any update on this?

@ahmadwaliesipick
Copy link

Are there current plans to support Apple Silicon builds with electron-builder? We're currently in the process of making sure our electron app is ready for ARM support, so I wanted to make sure that we'd be able to build to those targets using electron-builder.

If so, what does the release timeline look like for that?

Since #5095 was closed with no resolution, I figured it best to open a new issue.

@eengoron see here they have put this ticket in backlog and marked closed even still electron-builder is not supporting ARM64 build. #5095

@eengoron
Copy link
Author

eengoron commented Nov 9, 2020

@ahmadwaliesipick -- I mentioned that ticket in my original message. That ticket was closed without resolution, so I opened a new one.

cc @develar

@ahmadwaliesipick
Copy link

@ahmadwaliesipick -- I mentioned that ticket in my original message. That ticket was closed without resolution, so I opened a new one.

cc @develar

Yes @eengoron . Do you have any information are they working on ARM64 build?

@aabuhijleh
Copy link

Unfortunately, it looks like it's time to consider migrating to electron-packager for this issue :(

@develar
Copy link
Member

develar commented Nov 11, 2020

Anyone is willing to open a pull request? Fix should be easy, as far I see.

@deathlyrage
Copy link

deathlyrage commented Nov 11, 2020

Can we get this issued pinned, saves all the duplicate issues being made and easier to focus for people helping out with pull requests and debugging. Either this one or any of the others
#5095

@mmaietta
Copy link
Collaborator

FWIW, I was able to build an arm64 electron example app with the help of patch-package on two files. Perhaps this will help/unblock people investigating further 🙂

I was able to package via both yarn electron-builder to use package.json and cli yarn electron-builder --dir --arm64

Unfortunately, I'm actually unable to test the app though as I don't have a compatible MacOS version installed right now. Just to be verbose, here's the error alert

You can’t use this version of the application “MyApp.app” with this version of macOS.
You have macOS 10.15.7. The application requires macOS 11.0 or later.

Maybe someone would be willing to test this? 😉


Here are the changes I made:

package.json excerpt:

"build": {
    "appId": "test",
    "mac": {
      "target" : { "target": "dir", "arch": "arm64" }
    }
  },
  "devDependencies": {
    "electron": "11.0.0-beta.20",
    "electron-builder": "^22.9.1"
  },

Patch 1:
app-builder-lib+22.9.1.patch

diff --git a/node_modules/app-builder-lib/out/macPackager.js b/node_modules/app-builder-lib/out/macPackager.js
index 4825f78..2aa682b 100644
--- a/node_modules/app-builder-lib/out/macPackager.js
+++ b/node_modules/app-builder-lib/out/macPackager.js
@@ -258,7 +258,7 @@ class MacPackager extends _platformPackager().PlatformPackager {
 
     if (!hasMas || targets.length > 1) {
       const appPath = prepackaged == null ? path.join(this.computeAppOutDir(outDir, arch), `${this.appInfo.productFilename}.app`) : prepackaged;
-      nonMasPromise = (prepackaged ? Promise.resolve() : this.doPack(outDir, path.dirname(appPath), this.platform.nodeName, arch, this.platformSpecificBuildOptions, targets)).then(() => this.packageInDistributableFormat(appPath, _builderUtil().Arch.x64, targets, taskManager));
+      nonMasPromise = (prepackaged ? Promise.resolve() : this.doPack(outDir, path.dirname(appPath), this.platform.nodeName, arch, this.platformSpecificBuildOptions, targets)).then(() => this.packageInDistributableFormat(appPath, arch, targets, taskManager));
     }
 
     for (const target of targets) {

Patch 2:
electron-builder+22.9.1.patch

diff --git a/node_modules/electron-builder/out/builder.js b/node_modules/electron-builder/out/builder.js
index 59383a1..8b9aef7 100644
--- a/node_modules/electron-builder/out/builder.js
+++ b/node_modules/electron-builder/out/builder.js
@@ -69,10 +69,6 @@ function normalizeOptions(args) {
 
   function processTargets(platform, types) {
     function commonArch(currentIfNotSpecified) {
-      if (platform === _appBuilderLib().Platform.MAC) {
-        return args.x64 || currentIfNotSpecified ? [_builderUtil().Arch.x64] : [];
-      }
-
       const result = Array();
 
       if (args.x64) {
@@ -242,7 +238,7 @@ function createTargets(platforms, type, arch) {
   const targets = new Map();
 
   for (const platform of platforms) {
-    const archs = platform === _appBuilderLib().Platform.MAC ? [_builderUtil().Arch.x64] : arch === "all" ? [_builderUtil().Arch.x64, _builderUtil().Arch.ia32] : [(0, _builderUtil().archFromString)(arch == null ? process.arch : arch)];
+    const archs = arch === "all" && platform !== _appBuilderLib().Platform.MAC ? [_builderUtil().Arch.x64, _builderUtil().Arch.ia32] : [(0, _builderUtil().archFromString)(arch == null ? process.arch : arch)];
     const archToType = new Map();
     targets.set(platform, archToType);
 

@ahmadwaliesipick
Copy link

FWIW, I was able to build an arm64 electron example app with the help of patch-package on two files. Perhaps this will help/unblock people investigating further 🙂

I was able to package via both yarn electron-builder to use package.json and cli yarn electron-builder --dir --arm64

Unfortunately, I'm actually unable to test the app though as I don't have a compatible MacOS version installed right now. Just to be verbose, here's the error alert

You can’t use this version of the application “MyApp.app” with this version of macOS.
You have macOS 10.15.7. The application requires macOS 11.0 or later.

Maybe someone would be willing to test this? 😉

Here are the changes I made:

package.json excerpt:

"build": {
    "appId": "test",
    "mac": {
      "target" : { "target": "dir", "arch": "arm64" }
    }
  },
  "devDependencies": {
    "electron": "11.0.0-beta.20",
    "electron-builder": "^22.9.1"
  },

Patch 1:
app-builder-lib+22.9.1.patch

diff --git a/node_modules/app-builder-lib/out/macPackager.js b/node_modules/app-builder-lib/out/macPackager.js
index 4825f78..2aa682b 100644
--- a/node_modules/app-builder-lib/out/macPackager.js
+++ b/node_modules/app-builder-lib/out/macPackager.js
@@ -258,7 +258,7 @@ class MacPackager extends _platformPackager().PlatformPackager {
 
     if (!hasMas || targets.length > 1) {
       const appPath = prepackaged == null ? path.join(this.computeAppOutDir(outDir, arch), `${this.appInfo.productFilename}.app`) : prepackaged;
-      nonMasPromise = (prepackaged ? Promise.resolve() : this.doPack(outDir, path.dirname(appPath), this.platform.nodeName, arch, this.platformSpecificBuildOptions, targets)).then(() => this.packageInDistributableFormat(appPath, _builderUtil().Arch.x64, targets, taskManager));
+      nonMasPromise = (prepackaged ? Promise.resolve() : this.doPack(outDir, path.dirname(appPath), this.platform.nodeName, arch, this.platformSpecificBuildOptions, targets)).then(() => this.packageInDistributableFormat(appPath, arch, targets, taskManager));
     }
 
     for (const target of targets) {

Patch 2:
electron-builder+22.9.1.patch

diff --git a/node_modules/electron-builder/out/builder.js b/node_modules/electron-builder/out/builder.js
index 59383a1..8b9aef7 100644
--- a/node_modules/electron-builder/out/builder.js
+++ b/node_modules/electron-builder/out/builder.js
@@ -69,10 +69,6 @@ function normalizeOptions(args) {
 
   function processTargets(platform, types) {
     function commonArch(currentIfNotSpecified) {
-      if (platform === _appBuilderLib().Platform.MAC) {
-        return args.x64 || currentIfNotSpecified ? [_builderUtil().Arch.x64] : [];
-      }
-
       const result = Array();
 
       if (args.x64) {
@@ -242,7 +238,7 @@ function createTargets(platforms, type, arch) {
   const targets = new Map();
 
   for (const platform of platforms) {
-    const archs = platform === _appBuilderLib().Platform.MAC ? [_builderUtil().Arch.x64] : arch === "all" ? [_builderUtil().Arch.x64, _builderUtil().Arch.ia32] : [(0, _builderUtil().archFromString)(arch == null ? process.arch : arch)];
+    const archs = arch === "all" && platform !== _appBuilderLib().Platform.MAC ? [_builderUtil().Arch.x64, _builderUtil().Arch.ia32] : [(0, _builderUtil().archFromString)(arch == null ? process.arch : arch)];
     const archToType = new Map();
     targets.set(platform, archToType);
 

I have Apple Silicon Big Sur machine will check and back to you.

@ahmadwaliesipick
Copy link

ahmadwaliesipick commented Nov 12, 2020

f (platform === _appBuilderLib().Platform.MAC) {

@mmaietta I have tested but build failed because some packages not found while rebuild
https://github.com/atom/node-keytar/releases/download/v7.0.0/keytar-v7.0.0-electron-v82-darwin-arm64.tar.gz

https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v3.1.13/node-v64-darwin-x64.tar.gz

@deathlyrage
Copy link

@mmaietta your patches are working I managed to build my app for arm. It can be opened on the Apple DTK but crashes shortly after related to something about a electron, I will investigate and see If I can find any fixes. If you need your app tested on a DTK I'm free to test it.

@aabuhijleh
Copy link

@abhishekmatcha I expect native node modules are going to cause some issues for arm64 builds (see blog)

@aabuhijleh
Copy link

aabuhijleh commented Nov 12, 2020

@mmaietta I noticed another place where x64 is hardcoded but it's not included in your patch

await this.dispatchArtifactCreated(artifactPath, null, Arch.x64, this.computeSafeArtifactName(artifactName, "pkg"))

@deathlyrage can you please also test if you can sign/notarize your application well? And what about MAS builds?

@ggreco
Copy link

ggreco commented Nov 12, 2020

@mmaietta I have tested but build failed because some packages not found while rebuild
https://github.com/atom/node-keytar/releases/download/v7.0.0/keytar-v7.0.0-electron-v82-darwin-arm64.tar.gz

You need at least node-gyp 7.1.2 to build native modules for Mac/ARM64

@deathlyrage
Copy link

deathlyrage commented Nov 12, 2020

Attempting to use x64 and arm64 targets together result in them uploading under the same name in deployment.
Can be solved by adding "artifactName" : "${productName}-${arch}-${version}.${ext}", under the mac tag in package.json.

Edit: doesn't look like this works, might be hard coded somewhere.

@deathlyrage
Copy link

deathlyrage commented Nov 12, 2020

@aabuhijleh signing and notarization is working. Haven't tested MAS as I'm not using it yet.

@ahmadwaliesipick
Copy link

ahmadwaliesipick commented Nov 12, 2020

@mmaietta I have tested but build failed because some packages not found while rebuild
https://github.com/atom/node-keytar/releases/download/v7.0.0/keytar-v7.0.0-electron-v82-darwin-arm64.tar.gz

You need at least node-gyp 7.1.2 to build native modules for Mac/ARM64

I am able to create build and notarized. But i have sqlite3 error now.
Uncaught Exception: Error: dlopen(/Users/kalpit/Documents/project/todo-xplat/dist-app/mac-arm64/Todo Cloud.app/Contents/Resources/app.asar.unpacked/node_modules/todo-api/node_modules/sqlite3/lib/binding/electron-v11.0-darwin-arm64/node_sqlite3.node, 1): no suitable image found. Did find: /Users/kalpit/Documents/project/todo-xplat/dist-app/mac-arm64/Todo Cloud.app/Contents/Resources/app.asar.unpacked/node_modules/todo-api/node_modules/sqlite3/lib/binding/electron-v11.0-darwin-arm64/node_sqlite3.node: mach-o, but wrong architecture /Users/kalpit/Documents/project/todo-xplat/dist-app/mac-arm64/Todo Cloud.app/Contents/Resources/app.asar.unpacked/node_modules/todo-api/node_modules/sqlite3/lib/binding/electron-v11.0-darwin-arm64/node_sqlite3.node: mach-o, but wrong architecture at process.func [as dlopen] (electron/js2c/asar_bundle.js:5:1812) at Object.Module._extensions..node (internal/modules/cjs/loader.js:1203:18) at Object.func [as .node] (electron/js2c/asar_bundle.js:5:2039) at Module.load (internal/modules/cjs/loader.js:992:32) at Module._load (internal/modules/cjs/loader.js:885:14) at Function.f._load (electron/js2c/asar_bundle.js:5:12694) at Module.require (internal/modules/cjs/loader.js:1032:19) at require (internal/modules/cjs/helpers.js:72:18) at Object.<anonymous> (/Users/kalpit/Documents/project/todo-xplat/dist-app/mac-arm64/Todo Cloud.app/Contents/Resources/app.asar/node_modules/todo-api/node_modules/sqlite3/lib/sqlite3-binding.js:4:15) at Module._compile (internal/modules/cjs/loader.js:1152:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1173:10) at Module.load (internal/modules/cjs/loader.js:992:32) at Module._load (internal/modules/cjs/loader.js:885:14) at Function.f._load (electron/js2c/asar_bundle.js:5:12694) at Module.require (internal/modules/cjs/loader.js:1032:19) at require (internal/modules/cjs/helpers.js:72:18) at Object.<anonymous> (/Users/kalpit/Documents/project/todo-xplat/dist-app/mac-arm64/Todo Cloud.app/Contents/Resources/app.asar/node_modules/todo-api/node_modules/sqlite3/lib/sqlite3.js:2:15) at Module._compile (internal/modules/cjs/loader.js:1152:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1173:10) at Module.load (internal/modules/cjs/loader.js:992:32) at Module._load (internal/modules/cjs/loader.js:885:14) at Function.f._load (electron/js2c/asar_bundle.js:5:12694) at Module.require (internal/modules/cjs/loader.js:1032:19) at require (internal/modules/cjs/helpers.js:72:18) at Object.<anonymous> (/Users/kalpit/Documents/project/todo-xplat/dist-app/mac-arm64/Todo Cloud.app/Contents/Resources/app.asar/node_modules/todo-api/node_modules/any-db-sqlite3/index.js:3:20) at Module._compile (internal/modules/cjs/loader.js:1152:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1173:10) at Module.load (internal/modules/cjs/loader.js:992:32) at Module._load (internal/modules/cjs/loader.js:885:14) at Function.f._load (electron/js2c/asar_bundle.js:5:12694) at Module.require (internal/modules/cjs/loader.js:1032:19) at require (internal/modules/cjs/helpers.js:72:18) at getAdapter (/Users/kalpit/Documents/project/todo-xplat/dist-app/mac-arm64/Todo Cloud.app/Contents/Resources/app.asar/node_modules/todo-api/node_modules/any-db/index.js:27

@ahmadwaliesipick
Copy link

@aabuhijleh signing and notarization is working. Haven't tested MAS as I'm not using it yet.

can we create dmg for arm64?

@ahmadwaliesipick
Copy link

ahmadwaliesipick commented Nov 12, 2020

I have installed latest sqlite3 but still facing same error
rror: dlopen(/dist-app/mac-arm64/Todo Cloud.app/Contents/Resources/app.asar.unpacked/node_modules/todo-api/node_modules/sqlite3/lib/binding/napi-v3-darwin-arm64/node_sqlite3.node, 1): no suitable image found

@deathlyrage
Copy link

@aabuhijleh signing and notarization is working. Haven't tested MAS as I'm not using it yet.

can we create dmg for arm64?

You need to use a dmg or .zip when transfering your .app to your mac, as copying the folder can loose some attributes and macos big sur won't load images that it cant verify, I had this problem and changed the target to dmg and it worked.

@ljy-xian
Copy link

I have installed latest sqlite3 but still facing same error
rror: dlopen(/dist-app/mac-arm64/Todo Cloud.app/Contents/Resources/app.asar.unpacked/node_modules/todo-api/node_modules/sqlite3/lib/binding/napi-v3-darwin-arm64/node_sqlite3.node, 1): no suitable image found

I 'm not good at english ~
try lipo -info "your node_sqlite3.node path" see which arch it is
sqlite3 is using node-pre-gyp to build addon , node-pre-gyp is not support apple silicon , when you set "--arch=arm64" as configuration it don't work
you can try electron-rebuild to rebuild your addon , then try electron-builder to build the dmg
i'm trying this, it seems work

@mmaietta
Copy link
Collaborator

mmaietta commented Nov 12, 2020

Wow, I wasn't expecting such quick responses! 😁

@mmaietta I have tested but build failed because some packages not found while rebuild
https://github.com/atom/node-keytar/releases/download/v7.0.0/keytar-v7.0.0-electron-v82-darwin-arm64.tar.gz
https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v3.1.13/node-v64-darwin-x64.tar.gz

@ahmadwaliesipick you'll need 11.0.0-beta.1 or higher, that's when arm64 dist started to be released for Electron. For any native modules, you'll likely need to recompile directly as @ljy-xian mentioned since it'll be highly unlikely any other packages have already been packaging/storing arm64 builds for mac yet. The sqlite error is due to the fact that your native addon is not available in arm64 - no suitable image found

From: https://www.electronjs.org/blog/apple-silicon#native-modules
You need the following dependencies + versions

  • Xcode >=12.0.0
  • node-gyp >=7.1.0
  • electron-rebuild >=1.12.0
  • electron-packager >=15.1.0

Can be solved by adding "artifactName" : "${productName}-${arch}-${version}.${ext}", under the mac tag in package.json.

I recall some additional code that was conditional for adding the arch in the name, but I'll need to look that back up. I previously had to write some scripting for doing the same artifactName arch-injection for compiling ia32 vs x64 Windows apps separately. Seems the patch files might need to get a bit longer, possibly better in a gist soon

Nice catch @aabuhijleh! I don't use mas and definitely overlooked that point.

@ahmadwaliesipick
Copy link

ahmadwaliesipick commented Nov 13, 2020

I have installed latest sqlite3 but still facing same error
rror: dlopen(/dist-app/mac-arm64/Todo Cloud.app/Contents/Resources/app.asar.unpacked/node_modules/todo-api/node_modules/sqlite3/lib/binding/napi-v3-darwin-arm64/node_sqlite3.node, 1): no suitable image found

I 'm not good at english ~
try lipo -info "your node_sqlite3.node path" see which arch it is
sqlite3 is using node-pre-gyp to build addon , node-pre-gyp is not support apple silicon , when you set "--arch=arm64" as configuration it don't work
you can try electron-rebuild to rebuild your addon , then try electron-builder to build the dmg
i'm trying this, it seems work

@ljy-xian Thanks for reply.
i am already using electron-rebuild. But still facing error.
can you verify the command and target should be this?
electron-builder --arm64
"target" : ["dmg","pkg"],

@ahmadwaliesipick
Copy link

Wow, I wasn't expecting such quick responses! 😁

@mmaietta I have tested but build failed because some packages not found while rebuild
https://github.com/atom/node-keytar/releases/download/v7.0.0/keytar-v7.0.0-electron-v82-darwin-arm64.tar.gz
https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v3.1.13/node-v64-darwin-x64.tar.gz

@ahmadwaliesipick you'll need 11.0.0-beta.1 or higher, that's when arm64 dist started to be released for Electron. For any native modules, you'll likely need to recompile directly as @ljy-xian mentioned since it'll be highly unlikely any other packages have already been packaging/storing arm64 builds for mac yet. The sqlite error is due to the fact that your native addon is not available in arm64 - no suitable image found

From: https://www.electronjs.org/blog/apple-silicon#native-modules
You need the following dependencies + versions

  • Xcode >=12.0.0
  • node-gyp >=7.1.0
  • electron-rebuild >=1.12.0
  • electron-packager >=15.1.0

Can be solved by adding "artifactName" : "${productName}-${arch}-${version}.${ext}", under the mac tag in package.json.

I recall some additional code that was conditional for adding the arch in the name, but I'll need to look that back up. I previously had to write some scripting for doing the same artifactName arch-injection for compiling ia32 vs x64 Windows apps separately. Seems the patch files might need to get a bit longer, possibly better in a gist soon

Nice catch @aabuhijleh! I don't use mas and definitely overlooked that point.

@mmaietta i am using 11.0.0-beta.20

@ljy-xian
Copy link

ljy-xian commented Nov 13, 2020

erify the command and target should be this?

i patch electron-builder directly as @mmaietta mentioned
then run electron-builder --arm64 it works
then run the dmg on silicon MacOS 11.0.1 beta , it works too

@ahmadwaliesipick
Copy link

ahmadwaliesipick commented Nov 13, 2020

erify the command and target should be this?

i patch electron-builder directly as @mmaietta mentioned
then run electron-builder --arm64 it works
then run the dmg on silicon MacOS 11.0.1 beta , it works too

@ljy-xian what should be in target?
once i create build with this electron-builder --arm64 and set "target" : ["dmg","pkg"] it create mac build.
and once i run electron-builder --mac with target
"target": { "target": "dir", "arch": "arm64" },

then it create correct mac-arm-64 build but dmg not create.

@ahmadwaliesipick
Copy link

Please anyone share the correct format of electron-builder params and target params to create arm64 dmg.

@ahmadwaliesipick
Copy link

@mmaietta i am still not able to resolve sqlite3 error. Do you have any solution?

I have installed latest sqlite3 but still facing same error
rror: dlopen(/dist-app/mac-arm64/Todo Cloud.app/Contents/Resources/app.asar.unpacked/node_modules/todo-api/node_modules/sqlite3/lib/binding/napi-v3-darwin-arm64/node_sqlite3.node, 1): no suitable image found

@mmaietta
Copy link
Collaborator

mmaietta commented Dec 10, 2020

@ahmadwaliesipick because you're getting the same error for the same issue, and the info you're providing is very limited to assist.
Your bindings npm module can't find the correct file, likely because it's not available/copied into your .app. My advice, check your app.asar.unpacked and see what node images are actually present. To simplify your work, just run this in the working directory: find . -name '*.node' | xargs -I {} lipo -info {} | grep -e Non-fat

Also, sqlite3 built to that directory just fine for me...

$ rm -rf node_modules/**/*.node; yarn node-gyp clean;
yarn electron-builder install-app-deps --arch=arm64 && \
(find . -name '*.node' | xargs -I {} lipo -info {} | grep -e Non-fat)

yarn run v1.22.10
$ /shell-builder/node_modules/.bin/node-gyp clean
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | darwin | x64
gyp info ok
✨  Done in 0.26s.

yarn run v1.22.10
$ /shell-builder/node_modules/.bin/electron-builder install-app-deps --arch=arm64
  • electron-builder  version=22.9.1
  • loaded configuration  file=/<...>/shell-builder/electron-builder.js
  • rebuilding native dependencies  [email protected] platform=darwin arch=arm64
  • rebuilding native dependency  name=sqlite3 version=5.0.0
✨  Done in 43.02s.

Non-fat file: ./node_modules/sqlite3/build-tmp-napi-v3/Release/node_sqlite3.node is architecture: arm64
Non-fat file: ./node_modules/sqlite3/lib/binding/napi-v3-darwin-arm64/node_sqlite3.node is architecture: arm64

@mmaietta
Copy link
Collaborator

PR has been merged and release cut performed! Please upgrade and begin stress testing.

Probably should open new issues for anything found and close this issue. For posterity's sake, maybe also link any new issues here for tracking purposes?

@Xiphe
Copy link

Xiphe commented Jan 4, 2021

Please upgrade and begin stress testing.

Would like to help testing but am totally lost. Could anyone give an update on the current steps required to build for M1?

@lutzroeder
Copy link
Contributor

  1. Update to latest preview [email protected]
  2. Run npx electron-builder --mac --arm64 or npx electron-builder --mac --universal

There are some open PRs to fix follow-up issues.

@csett86
Copy link
Contributor

csett86 commented Jan 5, 2021

@Xiphe If you are looking for the package.json updates required for universal builds, you could try this: https://github.com/csett86/jitsi-meet-electron/blob/universal/package.json

But as @lutzroeder said, there are some follup fixes currently required, see https://github.com/csett86/jitsi-meet-electron/tree/universal/patches

@Xiphe
Copy link

Xiphe commented Jan 7, 2021

Thanks a lot! I decided to go with separate builds for mac in order to have less size overhead.
Up until now everything worked well with [email protected] and running npx electron-builder --mac --arm64 --x64 last thing I need to test is if the auto update works correctly so that arm versions stay on their arch.

@transparentech
Copy link

Thanks a lot for everyone's work on this!

@transparentech
Copy link

But has anyone gotten the auto updating to work with arm64? I am able to build 2 separate versions for mac (x64 and arm64). But when I auto update the arm64 version, it updates to the x64 version. Is there something we need to do to tell the auto-updater which arch we need?

@davej
Copy link
Contributor

davej commented Jan 8, 2021

But when I auto update the arm64 version, it updates to the x64 version.

@transparentech You will need to update electron-updater to the 4.3.7 beta. Works for me.

@mikeyyyzhao
Copy link

mikeyyyzhao commented Jan 8, 2021

Anyone running into "ReferenceError: u is not defined" for auto update for arm64?
electron-builder: "22.10.4"
electron-updater: "4.3.7"

I have two separate s3 bucket, one for arm64 and one for x64. When I check for updates on arm64, the autoUpdater gets "ReferenceError: u is not defined" but not for x64. The only difference is how I build the app:

Arm64: electron-builder --mac --arm64
x64: electron-builder --mac --x64

Really appreciate all the hard work on this!

Update: I think it might have been a problem with s3 (not 100% sure) but I came back to this without any code changes or loading a new build and the error disappeared and auto update works now

@AleksMeshkov
Copy link

AleksMeshkov commented Jan 11, 2021

Hm, strange...
I have:

"electron": "^11.1.1",
"electron-builder": "^22.10.4",
"electron-updater": "^4.3.7",

and when I run npx electron-builder --mac --universal , I get this:

npx electron-builder --mac --universal
  • electron-builder  version=22.10.4 os=19.6.0
  • loaded configuration  file=package.json ("build" field)
  • writing effective config  file=release/builder-effective-config.yaml
  • rebuilding native dependencies  [email protected], [email protected] platform=darwin arch=x64
  • install prebuilt binary  name=keytar version=7.3.0 platform=darwin arch=x64
  • packaging       platform=darwin arch=x64 electron=11.1.1 appOutDir=release/mac-universal-x64
  • rebuilding native dependencies  [email protected], [email protected] platform=darwin arch=arm64
  • install prebuilt binary  name=keytar version=7.3.0 platform=darwin arch=arm64
  • build native dependency from sources  name=keytar
                                          version=7.3.0
                                          platform=darwin
                                          arch=arm64
                                          reason=prebuild-install failed with error (run with env DEBUG=electron-builder to get more information)
                                          error=prebuild-install info begin Prebuild-install version 6.0.0
    prebuild-install WARN install prebuilt binaries enforced with --force!
    prebuild-install WARN install prebuilt binaries may be out of date!
    prebuild-install info looking for cached prebuild @ /Users/alexey/.npm/_prebuilds/77ee54-keytar-v7.3.0-electron-v85-darwin-arm64.tar.gz
    prebuild-install http request GET https://github.com/atom/node-keytar/releases/download/v7.3.0/keytar-v7.3.0-electron-v85-darwin-arm64.tar.gz
    prebuild-install http 404 https://github.com/atom/node-keytar/releases/download/v7.3.0/keytar-v7.3.0-electron-v85-darwin-arm64.tar.gz
    prebuild-install WARN install No prebuilt binaries found (target=11.1.1 runtime=electron arch=arm64 libc= platform=darwin)
    
  • packaging       platform=darwin arch=arm64 electron=11.1.1 appOutDir=release/mac-universal-arm64
  • packaging       platform=darwin arch=universal electron=11.1.1 appOutDir=release/mac-universal
 

 ⨯ Expected all non-binary files to have identical SHAs when creating a universal build but "Contents/Info.plist" did not  stackTrace=
  Error: Expected all non-binary files to have identical SHAs when creating a universal build but "Contents/Info.plist" did not
      at exports.makeUniversalApp (/Users/alexey/Devel/slate/ssd-im-new/node_modules/@electron/universal/src/index.ts:107:15)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:93:5)
      at MacPackager.doPack (/Users/alexey/Devel/slate/ssd-im-new/node_modules/app-builder-lib/src/macPackager.ts:116:9)
      at MacPackager.pack (/Users/alexey/Devel/slate/ssd-im-new/node_modules/app-builder-lib/src/macPackager.ts:167:7)
      at Packager.doBuild (/Users/alexey/Devel/slate/ssd-im-new/node_modules/app-builder-lib/src/packager.ts:434:9)
      at executeFinally (/Users/alexey/Devel/slate/ssd-im-new/node_modules/builder-util/src/promise.ts:12:14)
      at Packager._build (/Users/alexey/Devel/slate/ssd-im-new/node_modules/app-builder-lib/src/packager.ts:369:31)
      at Packager.build (/Users/alexey/Devel/slate/ssd-im-new/node_modules/app-builder-lib/src/packager.ts:333:12)
      at executeFinally (/Users/alexey/Devel/slate/ssd-im-new/node_modules/builder-util/src/promise.ts:12:14)

removing node_modules completely, then running npm install didn't help...

@quanglam2807
Copy link
Contributor

Hm, strange...
I have:

"electron": "^11.1.1",
"electron-builder": "^22.10.4",
"electron-updater": "^4.3.7",

and when I run npx electron-builder --mac --universal , I get this:

npx electron-builder --mac --universal
  • electron-builder  version=22.10.4 os=19.6.0
  • loaded configuration  file=package.json ("build" field)
  • writing effective config  file=release/builder-effective-config.yaml
  • rebuilding native dependencies  [email protected], [email protected] platform=darwin arch=x64
  • install prebuilt binary  name=keytar version=7.3.0 platform=darwin arch=x64
  • packaging       platform=darwin arch=x64 electron=11.1.1 appOutDir=release/mac-universal-x64
  • rebuilding native dependencies  [email protected], [email protected] platform=darwin arch=arm64
  • install prebuilt binary  name=keytar version=7.3.0 platform=darwin arch=arm64
  • build native dependency from sources  name=keytar
                                          version=7.3.0
                                          platform=darwin
                                          arch=arm64
                                          reason=prebuild-install failed with error (run with env DEBUG=electron-builder to get more information)
                                          error=prebuild-install info begin Prebuild-install version 6.0.0
    prebuild-install WARN install prebuilt binaries enforced with --force!
    prebuild-install WARN install prebuilt binaries may be out of date!
    prebuild-install info looking for cached prebuild @ /Users/alexey/.npm/_prebuilds/77ee54-keytar-v7.3.0-electron-v85-darwin-arm64.tar.gz
    prebuild-install http request GET https://github.com/atom/node-keytar/releases/download/v7.3.0/keytar-v7.3.0-electron-v85-darwin-arm64.tar.gz
    prebuild-install http 404 https://github.com/atom/node-keytar/releases/download/v7.3.0/keytar-v7.3.0-electron-v85-darwin-arm64.tar.gz
    prebuild-install WARN install No prebuilt binaries found (target=11.1.1 runtime=electron arch=arm64 libc= platform=darwin)
    
  • packaging       platform=darwin arch=arm64 electron=11.1.1 appOutDir=release/mac-universal-arm64
  • packaging       platform=darwin arch=universal electron=11.1.1 appOutDir=release/mac-universal
 

 ⨯ Expected all non-binary files to have identical SHAs when creating a universal build but "Contents/Info.plist" did not  stackTrace=
  Error: Expected all non-binary files to have identical SHAs when creating a universal build but "Contents/Info.plist" did not
      at exports.makeUniversalApp (/Users/alexey/Devel/slate/ssd-im-new/node_modules/@electron/universal/src/index.ts:107:15)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:93:5)
      at MacPackager.doPack (/Users/alexey/Devel/slate/ssd-im-new/node_modules/app-builder-lib/src/macPackager.ts:116:9)
      at MacPackager.pack (/Users/alexey/Devel/slate/ssd-im-new/node_modules/app-builder-lib/src/macPackager.ts:167:7)
      at Packager.doBuild (/Users/alexey/Devel/slate/ssd-im-new/node_modules/app-builder-lib/src/packager.ts:434:9)
      at executeFinally (/Users/alexey/Devel/slate/ssd-im-new/node_modules/builder-util/src/promise.ts:12:14)
      at Packager._build (/Users/alexey/Devel/slate/ssd-im-new/node_modules/app-builder-lib/src/packager.ts:369:31)
      at Packager.build (/Users/alexey/Devel/slate/ssd-im-new/node_modules/app-builder-lib/src/packager.ts:333:12)
      at executeFinally (/Users/alexey/Devel/slate/ssd-im-new/node_modules/builder-util/src/promise.ts:12:14)

removing node_modules completely, then running npm install didn't help...

@lutzroeder This is similar to what I mentioned earlier (#5481 (comment))

@AleksMeshkov You can apply this patch to fix the bug: https://github.com/webcatalog/translatium/blob/master/patches/app-builder-lib%2B22.10.4.patch

@prabhatsaini91
Copy link

Is notarization working when built using npx electron-builder --mac --arm64?
I am unable to get my app notarized when building for arm64. However, x64 builds are notarized.

Using electron-notarize to perform notarization

@mmaietta
Copy link
Collaborator

mmaietta commented Feb 18, 2021

I'd imagine that would be in an afterSign hook. Not sure if it's an electron-builder issue here. Here's my setup that validates the notarization as well:

import * as builder from "electron-builder";

async function notarizeMac(context: builder.AfterPackContext) {
    const appPath = path.join(context.appOutDir, `${ context.packager.appInfo.productFilename }.app`);
    await notarize({ appBundleId, appPath, ascProvider, appleId, appleIdPassword})
        .catch(err => { throw err; });
    executeCommand("spctl", ["-a", "-t", "open", "--context", "context:primary-signature", "-v", appPath])
}

@pliablepixels
Copy link

pliablepixels commented Feb 20, 2021

Edit: Problem solved. The ${arch} variable was not being honored, resulting in dmg overwrites.
Fixed by updating to [email protected]

Old post:

Hi, I am a little confused on what I am doing wrong.

./node_modules/.bin/electron-builder --version
22.9.1

This is my package.json

 "scripts": {
    "electron": "electron .",
    "dist-win": "./electron_js/sync_versions.sh && ./node_modules/.bin/electron-builder -w",
    "dist-lin": "./electron_js/sync_versions.sh && ./node_modules/.bin/electron-builder -l",
    "dist-mac": "./electron_js/sync_versions.sh && ./node_modules/.bin/electron-builder -m",
    "dist-all": "./electron_js/sync_versions.sh && ./node_modules/.bin/electron-builder -wlm"
  },
<snip>
 "build": {
    "artifactName": "${productName}-${version}-${os}-${arch}.${ext}",
    "appId": "com.pliablepixels.zmninja-pro",
    "productName": "zmninja-pro",
    "compression": "normal",
    "asar": true,
    "afterSign": "electron_js/notarize.js",
    "directories": {
      "buildResources": "electron_js/icons"
    },
<snip>
    "dmg": {
      "sign": false
    },
    "mac": {
      "category": "productivity",
      "target": {
        "target": "dmg",
        "arch": [
          "arm64",
          "x64"
        ]
      },

As you see, I have both arm64 and x64 in my mac target

The M1 mac app is built out, but only one dmg file is produced (x64) when I run npm run dist-mac

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