vscode-spellright icon indicating copy to clipboard operation
vscode-spellright copied to clipboard

How to rebuild Apple Silicon binaries (M1 / M2)

Open borekb opened this issue 3 years ago • 6 comments

I needed to do this again and it was not as easy as I hoped so I'd like to post this step by step guide. Anyone, feel free to post your notes. Based on https://github.com/bartosz-antosik/vscode-spellright/issues/502#issuecomment-1105281180 / PR #503.

When you need this

Spell Right sometimes stops working in VSCode, showing the "Activating extension ban.spellright failed" error in the console as reported in #502, #500 or #513.

The reason is that Spell Right binaries are built against specific Electron versions and if VSCode updates this, binaries have to be recompiled.

How to do it

1: Checkout this repo

2: cd lib/bin/node-spellchecker

3: Run npm i

4: Try to run ./build-macos-apple.sh. If it fails on node-gyp like this:

$ ./build-macos-apple.sh
./build-macos-apple.sh: line 5: node-gyp: command not found
cp: build/Release/spellchecker.node: No such file or directory
./build-macos-apple.sh: line 8: node-gyp: command not found
cp: build/Release/spellchecker.node: No such file or directory

then install node-gyp:

npm install -g node-gyp

5: Update the Electron version in a build script: find out the current version by invoking the Help: About command, you should see something like this:

Screen Shot 2022-07-08 at 18 38 50

Here, the new Electron version is 18.3.5.

6: Update the build-macos-apple.sh script: keep one older version and create a new one as recommended by @bartosz-antosik here. For example, this might be the diff:

#!/bin/bash

# requires node-gyp (npm install -g node-gyp) plus CLI developer tools

-node-gyp rebuild --target=13.1.7 --arch=arm64 --dist-url=https://electronjs.org/headers
-cp build/Release/spellchecker.node ../spellchecker-darwin-13.1.7-arm64.node

node-gyp rebuild --target=17.2.0 --arch=arm64 --dist-url=https://electronjs.org/headers
cp build/Release/spellchecker.node ../spellchecker-darwin-17.2.0-arm64.node

+node-gyp rebuild --target=18.3.5 --arch=arm64 --dist-url=https://electronjs.org/headers
+cp build/Release/spellchecker.node ../spellchecker-darwin-18.3.5-arm64.node

5: Run ./build-macos-apple.sh again. This time it should succeed.

Note: I think I was fighting with Python 2 vs. 3 when I last did this 3 months ago, see e.g. https://github.com/bartosz-antosik/vscode-spellright/pull/503#issuecomment-1105640961 or https://github.com/bartosz-antosik/vscode-spellright/issues/502#issuecomment-1105351546, but the current node-gyp (version 0.10.0) doesn't work with Python 2 and will use the Python 3 just fine.

6: Delete the old binary – in the example above, you'd remove the file for 13.1.7.

7: Test the new version locally, for example, to test the new 18.3.5 build with the 3.0.64 version of ban.spellright extension, do this:

cp ../spellchecker-darwin-18.3.5-arm64.node ~/.vscode/extensions/ban.spellright-3.0.64/lib/bin

The reload VSCode and spelling should work 🎉.

8: Commit the changes to ./build-macos-apple.sh and the new binaries, open a pull request.

borekb avatar Jul 08 '22 17:07 borekb

@bartosz-antosik possibly pin this issue?

borekb avatar Jul 08 '22 17:07 borekb

Hi @borekb! I have noticed that a new version of Electron appeared in Insiders version. If you could maybe rebuild Mac binaries would be great!

bartosz-antosik avatar Aug 10 '22 10:08 bartosz-antosik

@bartosz-antosik hi, I'll be happy to do this if I find a little bit of time 😄. BTW this is interesting: https://github.blog/changelog/2022-08-09-github-actions-self-hosted-runners-now-support-apple-m1-hardware/

UPDATE: done in #520.

borekb avatar Aug 11 '22 17:08 borekb

@borekb @bartosz-antosik Do this method still work? I followed the instructions and successfully compiled the Windows binary, but the extension still doesn't work with Electron 19.0.17 on VSCode 1.73.1 .

fabiorzfreitas avatar Nov 21 '22 19:11 fabiorzfreitas

@fabiorzfreitas I thing generally the extension at the moment works with 19.0.17 (insiders build here):

image

Also seems to be working fine with Electron 19.1.3 (also insiders build):

image

Generally, the method outlined above should be still ok.

bartosz-antosik avatar Nov 22 '22 08:11 bartosz-antosik

@bartosz-antosik That's interesting. I'll be opening a new issue (or rather I'll first check if it wouldn't be a duplicate), but it seems that the error that happen when trying to spell check large files is the same "spellright.command not found" error that happens in the issues mentioned here.

fabiorzfreitas avatar Nov 22 '22 17:11 fabiorzfreitas