-
Notifications
You must be signed in to change notification settings - Fork 194
Add MacOS arm64 support in release #346
Comments
@andreacavagna01 I just did a new attempt to build the
Do you have an M1 Mac to potentially test this on? Since the CI infrastructure currently is x64 only, the only option we have for now is cross-compilation. The generated file looks good but I don't have an M1 Mac to test this on:
|
I'd be glad to help out on this, as we need to do some tricky workarounds to be able to package a universal macOS app, and I have an M1 laptop at hand. Here's what I've done so far, on an Intel mac:
What's interesting is that if I call
I'd be glad to assist you with testing, please let me know how I can help. |
@mkarp I'm seeing the same as you on an Intel Mac. However, prebuild for N-API arm64 works correctly on Mac (cross-compiled from Intel Mac with Big Sur installed):
So it looks like it has to do something with the combination Prebuild + Electron. However, if N-API does work as expected, it's probably more straightforward and future-proof to switch to N-API altogether, which I've been doing in #331. Will add Apple Silicon to the mix there as well 👍🏼 |
Alright, done! @mkarp could you try doing |
@dennisameling Thank you for the quick response! TIL about Node-API :) Running
Clearly it looks for I could have looked into it deeper, but decided to treat it as a blackbox to save some time, so here's what I've done. First, I've cleaned the cached prebuilds and verified that packaging the app with mainstream Then I've downloaded the Node-API build and hacked it as a preload for mainstream keytar:
Then packaged the app and verified that it runs well on Intel and M1 Macs. So I'm guessing the switch to Node-API does the trick. Please make sure that Thank you so much for looking into this! |
Meanwhile, for folks who will be looking for a temporary hack, you can run the following script before packaging your Electron app: #!/usr/bin/env bash
set -euox pipefail
# This whole script is a huge hack. There's an issue in keytar
# https://github.com/atom/node-keytar/issues/346, actually seems more like an
# issue in node prebuild with the combination of Electron, which causes x86_64
# keytar.node to end up in app-amd64.asar, when building a universal macOS app.
#
# In order to mitigate the issue, we compile keytar manually, tarball it, and
# put in the cache directory where npm rebuild will be looking for it.
npm install
ELECTRON_VERSION=$(npm view electron version)
cd node_modules/keytar
# Cleanup existing build artefacts just in case
rm -rf build/Release prebuilds
# Compile keytar using node-gyp directly
SDKROOT=macosx npx node-gyp rebuild \
--arch=arm64 \
--runtime=electron \
--dist-url=https://atom.io/download/electron \
--target="$ELECTRON_VERSION" \
--build_v8_with_gn=false
KEYTAR_OUT=build/Release/keytar.node
# Check the arch, should be arm64
lipo -archs $KEYTAR_OUT
ABI=$(node -p "require('node-abi').getAbi('$ELECTRON_VERSION', 'electron')")
KEYTAR_VERSION=$(npm view keytar version)
KEYTAR_TAR_NAME="keytar-v$KEYTAR_VERSION-electron-v$ABI-darwin-arm64.tar.gz"
# npm prebuild-install prepends the filename with a short digest of the download URL
# * https://github.com/prebuild/prebuild/blob/master/util.js#L6
# * https://github.com/prebuild/prebuild-install/blob/master/util.js#L72
DIGEST=$(md5 -qs "https://github.com/atom/node-keytar/releases/download/v$KEYTAR_VERSION/$KEYTAR_TAR_NAME")
DIGEST=${DIGEST:0:6}
PREBUILDS_CACHE_DIR=$(npm config get cache)"/_prebuilds"
mkdir -p "$PREBUILDS_CACHE_DIR"
tar -zcvf "$PREBUILDS_CACHE_DIR/$DIGEST-$KEYTAR_TAR_NAME" $KEYTAR_OUT
# Should contain cached keytar prebuild
ls -la "$PREBUILDS_CACHE_DIR"/*keytar*
cd ../.. |
Haha, creative fix! 😂 I checked for similar issues in the
In UPDATE: see my comment below for more details |
I just did some more checks on Apple Silicon and the N-API issue (where it looks for Here's a minimal repo that you can use for testing (just run Output from Apple Silicon Mac (note that it looks for
From within the
So I guess this is the most future-proof way forward (correct me if I'm wrong):
|
Any news on this one? I had an issue with the hack created by @mkarp since I know it's not pretty, I was too lazy to read the
|
@thegnuu Correct, my bad with the |
Okay I have some good news and bad news. The good news is that
The bad news is that the same approach doesn't work for Electron 11 on that same Intel Mac:
I've just created a PR to provide Electron 12 prebuilds for Apple Silicon: #376 The end goal will be to offer N-API prebuilds only, which work both on Node and Electron, while eliminating the need to provide prebuilds for every new Electron/Node version: #331 |
The switch to N-API has been completed now. An upcoming release should no longer have the need for separate Electron + Node builds, but rather "just work" on Apple Silicon with a single N-API binary. To be continued 🚀 |
Should I be able to build a universal Mac DMG with Keytar 7.7.0 today or do we need to wait for a new version with the single N-API binary? |
we have solution for universal build arm64 and x86_64 in one keytar.node file #415 |
I can confirm that building our Electron 13 app with electron-builder and keytar 7.7.0 with N-API prebuilds works flawlessly 🎉 We have removed all the prebuild hacks posted before. I guess this issue can be closed? Or are we waiting for a single N-API library? In any case, I'm really looking forward to having a single library because most likely it will allow us to use a single asar file and cut the distribution size almost in half. |
How to install keytar with n-api with the correct arch? @mkarp |
@andreacavagna01 I think the answer to this question will be different based on what else you're using. In my case, packaging the app electron-builder and keytar 7.7.0 "just works". |
Summary
I'm trying to build an application that uses Keytar for arm64 Mac. Native dependencies not working properly.
Motivation
When I try to build native dependencies:
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
The text was updated successfully, but these errors were encountered: