better-sqlite3 icon indicating copy to clipboard operation
better-sqlite3 copied to clipboard

Provide pre-built downloads for ARM64 architecture for Electron

Open rathboma opened this issue 4 years ago • 33 comments

I run Beekeeper Studio and I want to move to better-sqlite3 over sqlite3 due to a number of issues (you were right after all, it is better :-).

As part of the electron-builder build process it downloads pre-built binaries. This works great for Linux x64, but it'd be great to also provide an arm64 build.

Would that be possible? Not sure if you use Github Actions for build, but happy to give you access to my arm64 AWS box if you want to share it.

rathboma avatar Apr 20 '21 15:04 rathboma

I second this.

CyberSecDemon avatar Apr 29 '21 21:04 CyberSecDemon

Same problem here, happy to help to incorporate this on the github action

nsantos16 avatar May 22 '21 20:05 nsantos16

We've actually had to switch our development back to node-sqlite3 because this has persisted along with node miss match errors when building in electron.

matthewcoxx avatar May 22 '21 20:05 matthewcoxx

@rathboma Can we use your AWS box build? cc: @JoshuaWise

nsantos16 avatar May 25 '21 00:05 nsantos16

How build it from source when no prebuild binanry on M1 mac

baryon avatar Jun 20 '21 04:06 baryon

To ensure your native dependencies are always matched electron version, simply add script `"postinstall": "electron-builder install-app-deps" to your `package.json`
  • writing effective config  file=dist/builder-effective-config.yaml
  • rebuilding native dependencies  [email protected], [email protected] platform=darwin arch=arm64
  • install prebuilt binary  name=keytar version=7.7.0 platform=darwin arch=arm64 napi= 
  • install prebuilt binary  name=better-sqlite3 version=7.4.1 platform=darwin arch=arm64 napi=
  • build native dependency from sources  name=better-sqlite3
                                          version=7.4.1
                                          platform=darwin
                                          arch=arm64
                                          napi=
                                          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.1.2
    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 local prebuild @ prebuilds/better-sqlite3-v7.4.1-electron-v89-darwin-arm64.tar.gz
    prebuild-install info looking for cached prebuild @ /Users/xxx/.npm/_prebuilds/993ab9-better-sqlite3-v7.4.1-electron-v89-darwin-arm64.tar.gz
    prebuild-install http request GET https://github.com/JoshuaWise/better-sqlite3/releases/download/v7.4.1/better-sqlite3-v7.4.1-electron-v89-darwin-arm64.tar.gz
    prebuild-install http 404 https://github.com/JoshuaWise/better-sqlite3/releases/download/v7.4.1/better-sqlite3-v7.4.1-electron-v89-darwin-arm64.tar.gz
    prebuild-install WARN install No prebuilt binaries found (target=13.1.2 runtime=electron arch=arm64 libc= platform=darwin)
    
  • rebuilding native dependency  name=better-sqlite3 version=7.4.1

it stoped at rebuilding status over one hour. whats happen? how fix it?

baryon avatar Jun 21 '21 11:06 baryon

I found why rebuild stopped. ./node_modules/.bin/electron-builder build --mac --arm64 works npx electron-builder build --mac --arm64 stopped

baryon avatar Jul 02 '21 01:07 baryon

@JoshuaWise email me and I'll give you a sudo enabled login to my AWS arm box if you want it. First name dot lastname Gmail. :-)

rathboma avatar Jul 03 '21 21:07 rathboma

also win32-ia32 with Electron

jackple avatar Aug 03 '21 07:08 jackple

Any update on this? I could really use a pre-build binary for arm64 as well. Or, alternatively, is there any way to avoid rebuilding the module every time? I'd sure like reducing the 5-10 minute builds every time on my Pi 4.

cutmoney avatar Sep 08 '21 04:09 cutmoney

Same question here, any update or help you need about this? 🤔

nsantos16 avatar Sep 09 '21 05:09 nsantos16

Just chiming in here - it'd probably be most future-proof if this project switches to N-API first. Currently, there's already 26 prebuilds for every release, and every new Electron or Node version adds to that. When adding additional platforms/architectures to the mix, that number will once again increase exponentially.

We did the same in node-keytar and it reduced the amount of prebuilds from 92 (!) to 12.

A large part (but not all) of the N-API migration can be handled by its conversion tool. I've blocked some time towards the end of this month to look into that 👍🏼

dennisameling avatar Sep 09 '21 07:09 dennisameling

On a related side note, does anyone know if there's an option in electron-forge to prevent natively rebuilding the module every time? I realize that electron-builder has that option, but that's erroring out for me on my Pi build for some reason.

cutmoney avatar Sep 09 '21 15:09 cutmoney

I found why rebuild stopped. ./node_modules/.bin/electron-builder build --mac --arm64 works npx electron-builder build --mac --arm64 stopped

Hello @baryon, Did you succeed to compile better-sql for arm64 apple M1 and use it? On my side, it seems to crash at runtime with a no suitable image found while importing Database Thanks for your help

alagrede avatar Oct 19 '21 13:10 alagrede

Yes, no problem here

1,check your node versison, if you use M1, update node to the latest version 16

% node -v
v16.10.0

2,write package.json like

{
.... ....
  "scripts": {
    "build:mac:arm64": "DEBUG=electron-builder ./node_modules/.bin/electron-builder build --mac --arm64",
    "postinstall": "./node_modules/.bin/electron-builder install-app-deps"
  },
.... ....

  "devDependencies": {
    "electron": "^13.5.1",
    "electron-builder": "^22.14.5",
    "electron-notarize": "^1.1.1",
    "electron-osx-sign": "^0.5.0"
.... ....
  },
  "dependencies": {
    "better-sqlite3": "^7.4.3"
.... ....
  }
}

3, npm install or yarn 4, npm run build:mac:arm64

baryon avatar Oct 20 '21 01:10 baryon

@JoshuaWise Now that Node 16 is LTS, would it be possible for a new version to be released with ARM64 Electron prebuilds? I would love to be able to fully swap to this from node-sqlite3, but the prebuilds are holding me up

adambailey- avatar Nov 01 '21 21:11 adambailey-

I too am being held up, every time I try to build an app I'm try to port across from x64 to arm64 I keep having to rebuild this module but it seems to fail... a prebuilt binary would definitely help me too

BugInACode avatar Nov 03 '21 23:11 BugInACode

Same here. An arm64 binary would be extremely helpful!

cutmoney avatar Nov 04 '21 02:11 cutmoney

@JoshuaWise Is there any sort of update you could possibly provide for this? I'm sure you're busy, and with the holidays coming up, it might get even harder to get this done 😅 . If you could provide any sort of rough guess on when you expect to be able to take this on, it would be greatly appreciated, even if the answer is that it will be months

adambailey- avatar Nov 08 '21 14:11 adambailey-

Alternatively to doing this for us, @JoshuaWise where could we find the build instructions? We might be able to give it a shot ourselves to ease some of the work off you.

BugInACode avatar Nov 14 '21 03:11 BugInACode

I would like to chime in that binaries for linux ia32 (electron and node) would be very helpful.

cbartondock avatar Nov 18 '21 13:11 cbartondock

A great example of optimal binary distribution is the Node Sharp project, using N-API v5 and github actions, resulting in just 8 binaries for all OS's that can be used for Electron or just bare NodeJS.

https://github.com/lovell/sharp/tree/master/.github/workflows

gpetrov avatar Nov 19 '21 16:11 gpetrov

I ended up just forking this project and modifying the build actions to make the binaries I need. My actual project now downloads its binaries from there. To do the linux ia32 binaries it was necessary to first apt-get install g++-multilib and gcc-multilib, but otherwise simple.

cbartondock avatar Nov 22 '21 16:11 cbartondock

Nice! Would it be pretty simple to put together a PR with those changes onto this repo?

adambailey- avatar Nov 22 '21 16:11 adambailey-

Yes although I made another somewhat hacky change in able to get the library to work when called from electron's renderer process like we are always told never to do 👀. I could make a clean fork that only changes the build actions though. The additional action is:

   - if: matrix.os == 'ubuntu-latest'
        run: |
          sudo apt-get update
          sudo apt-get install gcc-multilib g++-multilib
          npx --no-install prebuild -r electron -t 10.0.0 -t 11.0.0 -t 12.0.0 -t 13.0.0 -t 14.0.0 -t 15.0.0 -t 16.0.0 --include-regex 'better_sqlite3.node$' --arch ia32 -u ${{ secrets.GITHUB_TOKEN }}

cbartondock avatar Nov 22 '21 16:11 cbartondock

@cbartondock I tried adding your repo to my package.json file but now it fails to run yarn grunt. Did you mind expanding on what you did that allowed you to use your fork? Thanks in advance

BugInACode avatar Dec 06 '21 00:12 BugInACode

Other than changes to the build actions all I did was this: https://github.com/cbartondock/better-sqlite3/commit/5b1a7901a01c296aa0d21a3e9a87d9168794f66f

To make it compatible with my typescript stack. That said I made a lot of changes to the build.yml file and removed many builds I was not using to save time, so potentially that could be causing your issue as well.

The relevant code that needs to be added to get it to build linux ia32 is above.

cbartondock avatar Dec 06 '21 16:12 cbartondock

This is actually a dependency of an app I'm trying to build, so in the package.json file I've changed the url to your fork, then delete the yarn.lock file and run yarn install but fails. Should I build this dependency separately then try building my app? Thanks

BugInACode avatar Dec 06 '21 22:12 BugInACode

Perhaps this is a low-hanging fruit, now that https://github.com/JoshuaWise/better-sqlite3/pull/714 is merged. PRs welcome.

JoshuaWise avatar Jan 19 '22 03:01 JoshuaWise

Can't easily test this as a PR, but a cropped up version of

  prebuild-armv7-alpine:
    name: Prebuild on armhf alpine
    runs-on: ubuntu-latest
    needs: publish
    steps:
      - uses: docker/setup-qemu-action@v1
      - run: |
          docker run --rm --entrypoint /bin/sh --platform linux/arm/v7 node:16-alpine -c "apk add build-base git python3 --update-cache && \
          git clone ${{ github.event.repository.clone_url }} && \
          cd ${{ github.event.repository.name }} && \
          npm install --ignore-scripts && \
          npx --no-install prebuild -r node -t 10.20.0 -t 12.0.0 -t 14.0.0 -t 16.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }}

seems to build ok. How would one go about testing the result?

Having prebuilts is really a must for adoption on RPi, people tend to report stuck installs when it just takes forever.

I can submit a PR blindly if that helps.

tkurki avatar Jan 27 '22 21:01 tkurki