Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Add MacOS arm64 support in release #346

Open
andreacavagna01 opened this issue Jan 20, 2021 · 18 comments
Open

Add MacOS arm64 support in release #346

andreacavagna01 opened this issue Jan 20, 2021 · 18 comments

Comments

@andreacavagna01
Copy link

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

@shiftkey
Copy link
Contributor

We had a shot at this for Electron in #329 but had to back it out in #340. I think we need to be on a later version of node-gyp but this may also depend on prebuild being aware of the new architecture.

@dennisameling
Copy link
Contributor

@andreacavagna01 I just did a new attempt to build the arm64 binary for Electron on a Mac I could borrow (x64 Intel), got it to work as follows:

export npm_config_arch=arm64
export npm_target_arch=arm64
npm install
npm run prebuild-electron-arm64 (could only do Electron 11 since that version added Apple Silicon support)

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:

$ file build/Release/keytar.node
build/Release/keytar.node: Mach-O 64-bit bundle arm64

@mkarp
Copy link

mkarp commented Feb 18, 2021

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:

  1. Checked out node-keytar repo

  2. Switch to LTS version of node:

    $ nvm use 14
    Now using node v14.15.1 (npm v6.14.8)
    
  3. Export the following env vars as suggested:

    $ export npm_config_arch=arm64
    $ export npm_target_arch=arm64
    
  4. Export SDKROOT as otherwise for some reason npm install fails:

    $ export SDKROOT=macosx

  5. Run npm install:

    $ npm install
    
    > keytar@7.4.0 install /Users/mkarp/Workspace/vendor/node-keytar
    > prebuild-install || npm run build
    
    prebuild-install WARN install No prebuilt binaries found (target=14.15.1 runtime=node arch=arm64 libc= platform=darwin)
    
    > keytar@7.4.0 build /Users/mkarp/Workspace/vendor/node-keytar
    > node-gyp rebuild
    
    CXX(target) Release/obj.target/keytar/src/async.o
    CXX(target) Release/obj.target/keytar/src/main.o
    CXX(target) Release/obj.target/keytar/src/keytar_mac.o
    SOLINK_MODULE(target) Release/keytar.node
    ld: warning: directory not found for option '-L/usr/local/opt/zlib/lib'
    audited 417 packages in 5.355s
    
    23 packages are looking for funding
    run `npm fund` for details
    
    found 12 low severity vulnerabilities
    run `npm audit fix` to fix them, or `npm audit` for details
    
  6. Run prebuild script as suggested:

    $ npm run prebuild-electron-arm64
    
    > keytar@7.4.0 prebuild-electron-arm64 /Users/mkarp/Workspace/vendor/node-keytar
    > prebuild -t 7.0.0 -t 8.0.0 -t 9.0.0 -t 10.0.0 -t 11.0.0 -r electron -a arm64 --strip
    
    prebuild info begin Prebuild version 10.0.1
    prebuild info build Preparing to prebuild keytar@7.4.0 for electron 7.0.0 on darwin-arm64 using node-gyp
    CXX(target) Release/obj.target/keytar/src/async.o
    CXX(target) Release/obj.target/keytar/src/main.o
    CXX(target) Release/obj.target/keytar/src/keytar_mac.o
    SOLINK_MODULE(target) Release/keytar.node
    ld: warning: directory not found for option '-L/usr/local/opt/zlib/lib'
    CXX(target) Release/obj.target/keytar/src/async.o
    CXX(target) Release/obj.target/keytar/src/main.o
    CXX(target) Release/obj.target/keytar/src/keytar_mac.o
    SOLINK_MODULE(target) Release/keytar.node
    ld: warning: directory not found for option '-L/usr/local/opt/zlib/lib'
    CXX(target) Release/obj.target/keytar/src/async.o
    CXX(target) Release/obj.target/keytar/src/main.o
    CXX(target) Release/obj.target/keytar/src/keytar_mac.o
    SOLINK_MODULE(target) Release/keytar.node
    ld: warning: directory not found for option '-L/usr/local/opt/zlib/lib'
    CXX(target) Release/obj.target/keytar/src/async.o
    CXX(target) Release/obj.target/keytar/src/main.o
    CXX(target) Release/obj.target/keytar/src/keytar_mac.o
    SOLINK_MODULE(target) Release/keytar.node
    ld: warning: directory not found for option '-L/usr/local/opt/zlib/lib'
    CXX(target) Release/obj.target/keytar/src/async.o
    CXX(target) Release/obj.target/keytar/src/main.o
    CXX(target) Release/obj.target/keytar/src/keytar_mac.o
    SOLINK_MODULE(target) Release/keytar.node
    ld: warning: directory not found for option '-L/usr/local/opt/zlib/lib'
    
  7. The output keytar.node file is still compiled for x64 for some reason:

    $ file build/Release/keytar.node
    build/Release/keytar.node: Mach-O 64-bit bundle x86_64
    

What's interesting is that if I call node-gyp directly, it does the job as expected, and I can confirm that this binary runs on M1 just fine:

$ npx node-gyp rebuild --arch=arm64 --runtime=electron
gyp info it worked if it ends with ok
gyp info using node-gyp@7.1.2
gyp info using node@14.15.1 | darwin | x64
gyp info find Python using Python version 3.7.4 found at "/Users/mkarp/.pyenv/versions/3.7.4/bin/python3"
gyp info spawn /Users/mkarp/.pyenv/versions/3.7.4/bin/python3
gyp info spawn args [
gyp info spawn args   '/Users/mkarp/Workspace/vendor/node-keytar/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/mkarp/Workspace/vendor/node-keytar/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/mkarp/Workspace/vendor/node-keytar/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/mkarp/Library/Caches/node-gyp/14.15.1/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/mkarp/Library/Caches/node-gyp/14.15.1',
gyp info spawn args   '-Dnode_gyp_dir=/Users/mkarp/Workspace/vendor/node-keytar/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/mkarp/Library/Caches/node-gyp/14.15.1/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/mkarp/Workspace/vendor/node-keytar',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
CXX(target) Release/obj.target/keytar/src/async.o
CXX(target) Release/obj.target/keytar/src/main.o
CXX(target) Release/obj.target/keytar/src/keytar_mac.o
SOLINK_MODULE(target) Release/keytar.node
ld: warning: directory not found for option '-L/usr/local/opt/zlib/lib'
gyp info ok

$ file build/Release/keytar.node
build/Release/keytar.node: Mach-O 64-bit bundle arm64

I'd be glad to assist you with testing, please let me know how I can help.

@dennisameling
Copy link
Contributor

@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):

% npm run prebuild-electron-arm64-mac

> keytar@7.4.0 prebuild-electron-arm64-mac /Users/Dennis/GitHub/node-keytar
> prebuild -t 3 -r napi -a arm64 --strip

prebuild info begin Prebuild version 10.0.1
prebuild info build Preparing to prebuild keytar@7.4.0 for napi 3 on darwin-arm64 using node-gyp
  CXX(target) Release/obj.target/keytar/src/async.o
  CXX(target) Release/obj.target/keytar/src/main.o
  CXX(target) Release/obj.target/keytar/src/keytar_mac.o
  SOLINK_MODULE(target) Release/keytar.node
Dennis@MacBook-Pro node-keytar % file build/Release/keytar.node
build/Release/keytar.node: Mach-O 64-bit bundle arm64

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 👍🏼

@dennisameling
Copy link
Contributor

Alright, done! @mkarp could you try doing npm install @dennisameling/keytar-temp@7.4.99-beta? This is based on #331, so there's no need to build separately for Electron and Node anymore. I added a macOS arm64 prebuild: https://github.com/dennisameling/node-keytar/releases/tag/v7.4.99-beta

@mkarp
Copy link

mkarp commented Feb 19, 2021

@dennisameling Thank you for the quick response! TIL about Node-API :)

Running npm install @dennisameling/keytar-temp@7.4.99-beta doesn't seem to do the trick on its own, but maybe I'm holding it wrong. I'm using electron-builder with npmRebuild: true, and it uses prebuild (after some layers). It couldn't fetch the tar from GitHub:

  • install prebuilt binary  name=@dennisameling/keytar-temp version=7.4.99-beta platform=darwin arch=arm64
  • build native dependency from sources  name=@dennisameling/keytar-temp
                                          version=7.4.99-beta
                                          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.1
    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/mkarp/.npm/_prebuilds/0dc35e-keytar-temp-v7.4.99-beta-electron-v85-darwin-arm64.tar.gz
    prebuild-install http request GET https://github.com/dennisameling/node-keytar/releases/download/v7.4.99-beta/keytar-temp-v7.4.99-beta-electron-v85-darwin-arm64.tar.gz
    prebuild-install http 404 https://github.com/dennisameling/node-keytar/releases/download/v7.4.99-beta/keytar-temp-v7.4.99-beta-electron-v85-darwin-arm64.tar.gz
    prebuild-install WARN install No prebuilt binaries found (target=11.2.3 runtime=electron arch=arm64 libc= platform=darwin)

Clearly it looks for electron-v85 instead of napi-v3.

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 keytar still doesn't work on M1. electron-builder runs prebuild, but the output keytar.node has x86_arch architecture.

Then I've downloaded the Node-API build and hacked it as a preload for mainstream keytar:

$ wget https://github.com/dennisameling/node-keytar/releases/download/v7.4.99-beta/keytar-temp-v7.4.99-beta-napi-v3-darwin-arm64.tar.gz \
       -O ~/.npm/_prebuilds/481d95-keytar-v7.4.0-electron-v85-darwin-arm64.tar.gz

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 prebuild still works with the cached builds.

Thank you so much for looking into this!

@mkarp
Copy link

mkarp commented Feb 19, 2021

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 ../..

@dennisameling
Copy link
Contributor

dennisameling commented Feb 19, 2021

Haha, creative fix! 😂

I checked for similar issues in the lovell/sharp repo because they moved to N-API a few months ago already. Came across this one: lovell/sharp#2440 with an issue in electron-builder as well: electron-userland/electron-builder#5438

Someone fixed it in this PR, would that help for inspiration? https://github.com/develar/app-builder/pull/47/files

In lovell/sharp they fixed it with lovell/sharp@dcc42f8, but I already added that to the package.json for keytar as well. Just tested with desktop/desktop on Apple Silicon (have access to one at MacStadium thanks to @KishanBagaria), and it works with the N-API build on Electron 🎉

UPDATE: see my comment below for more details

@dennisameling
Copy link
Contributor

dennisameling commented Feb 19, 2021

I just did some more checks on Apple Silicon and the N-API issue (where it looks for electron prebuilds instead of N-API prebuilds) is in app-builder (as part of electron-builder), not keytar. As you can see below, I also tested with https://github.com/lovell/sharp, which switched to N-API prebuilds months ago. Even for them it's looking for sharp-v0.27.1-electron-v85-darwin-arm64.tar.gz, which obviously doesn't exist.

Here's a minimal repo that you can use for testing (just run yarn install and you'll see the output below) https://github.com/dennisameling/electron-webpack-quick-start/tree/apple-silicon

Output from Apple Silicon Mac (note that it looks for keytar-temp-v7.4.99-beta-electron-v85-darwin-arm64.tar.gz):

$ electron-builder install-app-deps
  • electron-builder  version=22.10.5
  • loaded configuration  file=package.json ("build" field)
  • loaded parent configuration  file=/Users/administrator/Documents/electron-webpack-quick-start/node_modules/electron-webpack/out/electron-builder.js
  • rebuilding native dependencies  dependencies=@dennisameling/keytar-temp@7.4.99-beta, keytar@7.4.0, sharp@0.27.1 platform=darwin arch=arm64
  • install prebuilt binary  name=keytar version=7.4.0 platform=darwin arch=arm64
  • install prebuilt binary  name=@dennisameling/keytar-temp version=7.4.99-beta platform=darwin arch=arm64
  • build native dependency from sources  name=@dennisameling/keytar-temp
                                          version=7.4.99-beta
                                          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.1
    prebuild-install info looking for cached prebuild @ /Users/administrator/.npm/_prebuilds/0dc35e-keytar-temp-v7.4.99-beta-electron-v85-darwin-arm64.tar.gz
    prebuild-install http request GET https://github.com/dennisameling/node-keytar/releases/download/v7.4.99-beta/keytar-temp-v7.4.99-beta-electron-v85-darwin-arm64.tar.gz
    prebuild-install http 404 https://github.com/dennisameling/node-keytar/releases/download/v7.4.99-beta/keytar-temp-v7.4.99-beta-electron-v85-darwin-arm64.tar.gz
    prebuild-install WARN install No prebuilt binaries found (target=11.2.3 runtime=electron arch=arm64 libc= platform=darwin)

  • install prebuilt binary  name=sharp version=0.27.1 platform=darwin arch=arm64
  • build native dependency from sources  name=keytar
                                          version=7.4.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.1
    prebuild-install info looking for cached prebuild @ /Users/administrator/.npm/_prebuilds/481d95-keytar-v7.4.0-electron-v85-darwin-arm64.tar.gz
    prebuild-install http request GET https://github.com/atom/node-keytar/releases/download/v7.4.0/keytar-v7.4.0-electron-v85-darwin-arm64.tar.gz
    prebuild-install http 404 https://github.com/atom/node-keytar/releases/download/v7.4.0/keytar-v7.4.0-electron-v85-darwin-arm64.tar.gz
    prebuild-install WARN install No prebuilt binaries found (target=11.2.3 runtime=electron arch=arm64 libc= platform=darwin)

  • build native dependency from sources  name=sharp
                                          version=0.27.1
                                          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.1
    prebuild-install info looking for cached prebuild @ /Users/administrator/.npm/_prebuilds/aad24c-sharp-v0.27.1-electron-v85-darwin-arm64.tar.gz
    prebuild-install http request GET https://github.com/lovell/sharp/releases/download/v0.27.1/sharp-v0.27.1-electron-v85-darwin-arm64.tar.gz
    prebuild-install http 404 https://github.com/lovell/sharp/releases/download/v0.27.1/sharp-v0.27.1-electron-v85-darwin-arm64.tar.gz
    prebuild-install WARN install No prebuilt binaries found (target=11.2.3 runtime=electron arch=arm64 libc= platform=darwin)

  • rebuilding native dependency  name=keytar version=7.4.0
  • rebuilding native dependency  name=@dennisameling/keytar-temp version=7.4.99-beta
  • rebuilding native dependency  name=sharp version=0.27.1
✨  Done in 25.96s.

From within the node-keytar directory, when I run prebuild-install --verbose, it correctly downloads the N-API package:

% npx prebuild-install --verbose
prebuild-install info begin Prebuild-install version 6.0.1
prebuild-install info looking for cached prebuild @ /Users/administrator/.npm/_prebuilds/158a2d-keytar-temp-v7.4.99-beta-napi-v3-darwin-arm64.tar.gz
prebuild-install http request GET https://github.com/dennisameling/node-keytar/releases/download/v7.4.99-beta/keytar-temp-v7.4.99-beta-napi-v3-darwin-arm64.tar.gz
prebuild-install http 200 https://github.com/dennisameling/node-keytar/releases/download/v7.4.99-beta/keytar-temp-v7.4.99-beta-napi-v3-darwin-arm64.tar.gz
prebuild-install info downloading to @ /Users/administrator/.npm/_prebuilds/158a2d-keytar-temp-v7.4.99-beta-napi-v3-darwin-arm64.tar.gz.29670-988e553f1bf39.tmp
prebuild-install info renaming to @ /Users/administrator/.npm/_prebuilds/158a2d-keytar-temp-v7.4.99-beta-napi-v3-darwin-arm64.tar.gz
prebuild-install info unpacking @ /Users/administrator/.npm/_prebuilds/158a2d-keytar-temp-v7.4.99-beta-napi-v3-darwin-arm64.tar.gz
prebuild-install info unpack resolved to /Users/administrator/Documents/node-keytar/build/Release/keytar.node
prebuild-install info install Successfully installed prebuilt binary!

So I guess this is the most future-proof way forward (correct me if I'm wrong):

@thegnuu
Copy link

thegnuu commented Mar 10, 2021

Any news on this one?

I had an issue with the hack created by @mkarp since npm view <package> version will return the current registry version, not the actually installed one. Here is an updated version which works in my case.

I know it's not pretty, I was too lazy to read the sed docs.... ;)

#!/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.

# Prepare variables
ELECTRON_VERSION=$(npm ls electron | grep "electron@.*" | sed 's/^.*electron@//' | sed 's/^[ \t]*//;s/[ \t]*$//')
KEYTAR_OUT=build/Release/keytar.node
ABI=$(node -p "require('node-abi').getAbi('$ELECTRON_VERSION', 'electron')")
KEYTAR_VERSION=$(npm ls keytar | grep "keytar@.*" | sed 's/^.*keytar@//'| sed 's/^[ \t]*//;s/[ \t]*$//')
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"

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

# Check the arch, should be arm64
lipo -archs $KEYTAR_OUT

# create tar
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-v"$KEYTAR_VERSION"*

cd ../..

@mkarp
Copy link

mkarp commented Mar 10, 2021

@thegnuu Correct, my bad with the npm view thing, I've also switched to parsing the keytar version from package.json. Oh, workarounds :)

@dennisameling
Copy link
Contributor

Okay I have some good news and bad news. The good news is that prebuild for Mac arm64 works correctly for Electron 12+ (compiled on an Intel Mac on Big Sur):

% tar -xvzf keytar-v7.6.0-electron-v87-darwin-arm64.tar.gz
x build/Release/keytar.node
% file build/Release/keytar.node                          
build/Release/keytar.node: Mach-O 64-bit bundle arm64

The bad news is that the same approach doesn't work for Electron 11 on that same Intel Mac:

% tar -xvzf keytar-v7.6.0-electron-v85-darwin-arm64.tar.gz
x build/Release/keytar.node
% file build/Release/keytar.node
build/Release/keytar.node: Mach-O 64-bit bundle x86_64

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

@dennisameling
Copy link
Contributor

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 🚀

@voidrender
Copy link

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?

@poisonReact
Copy link

we have solution for universal build arm64 and x86_64 in one keytar.node file #415

@mkarp
Copy link

mkarp commented Oct 6, 2021

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.

@andreacavagna01
Copy link
Author

How to install keytar with n-api with the correct arch? @mkarp

@mkarp
Copy link

mkarp commented Feb 18, 2022

@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".

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

Successfully merging a pull request may close this issue.

7 participants