From 122d2b8fa83fd6cf72f8b44350f221f3c1e6be70 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 14 Apr 2022 09:12:05 +0100 Subject: [PATCH] Added prebuilt Linux ARM64 binaries to CI refs https://github.com/TryGhost/node-sqlite3/pull/1362 - the referenced PR added Linux ARM64 and ARMv7 prebuilds to CI so we can get prebuilt binaries upon releasing - CI has recently been reworked so I've rebased the PR and fixed it up - unfortunately, `node-pre-gyp` seems to ignore the difference between armv6 and armv7, and treats them both as `arm` so I've had to disable prebuilds for them for now - building via QEMU is INCREDIBLY slow so I've configured it to only run during a release or upon manual execution - full credit to @n1ru4l for the original PR --- .github/workflows/ci.yml | 50 ++++++++++++++++++++++++++++++++++ README.md | 8 +++++- tools/BinaryBuilder.Dockerfile | 25 +++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 tools/BinaryBuilder.Dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 789111f57..83efd50aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,3 +79,53 @@ jobs: if: matrix.node == 16 && startsWith(github.ref, 'refs/tags/') env: NODE_PRE_GYP_GITHUB_TOKEN: ${{ github.token }} + build-qemu: + runs-on: ubuntu-latest + if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/') + strategy: + fail-fast: false + matrix: + node: + - 16 + architecture: + - linux/arm64 + variant: + - bullseye + - alpine + name: ${{ matrix.variant }} ${{ matrix.architecture }} - Node ${{ matrix.node }} + steps: + - uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Build binaries and test + run: | + docker buildx build \ + --file ./tools/BinaryBuilder.Dockerfile \ + --load \ + --tag sqlite-builder \ + --platform ${{ matrix.architecture }} \ + --no-cache \ + --build-arg VARIANT=${{ matrix.variant }} \ + --build-arg NODE_VERSION=${{ matrix.node }} \ + . + CONTAINER_ID=$(docker create -it sqlite-builder) + docker cp $CONTAINER_ID:/usr/src/build/build/ ./build + + - name: Upload binaries to commit artifacts + uses: actions/upload-artifact@v3 + if: matrix.node == 16 + with: + name: prebuilt-binaries + path: build/stage/*/* + retention-days: 7 + + - name: Upload binaries to GitHub Release + run: yarn node-pre-gyp-github publish + if: matrix.node == 16 && startsWith(github.ref, 'refs/tags/') + env: + NODE_PRE_GYP_GITHUB_TOKEN: ${{ github.token }} diff --git a/README.md b/README.md index a4e9472fd..c0b029393 100644 --- a/README.md +++ b/README.md @@ -40,21 +40,27 @@ The module uses [node-pre-gyp](https://github.com/mapbox/node-pre-gyp) to downlo Format: `napi-v{napi_build_version}-{platform}-{libc}-{arch}` * `napi-v3-darwin-unknown-x64` +* `napi-v3-linux-glibc-arm64` * `napi-v3-linux-glibc-x64` +* `napi-v3-linux-musl-arm64` * `napi-v3-win32-unknown-ia32` * `napi-v3-win32-unknown-x64` * `napi-v6-darwin-unknown-x64` +* `napi-v6-linux-glibc-arm64` * `napi-v6-linux-glibc-x64` +* `napi-v6-linux-musl-arm64` * `napi-v6-win32-unknown-ia32` * `napi-v6-win32-unknown-x64` +Unfortunately, [node-pre-gyp](https://github.com/mapbox/node-pre-gyp) cannot differentiate between `armv6` and `armv7`, and instead uses `arm` as the `{arch}`. Until that is fixed, you will still need to install `sqlite3` from [source](#source-install). + Support for other platforms and architectures may be added in the future if CI supports building on them. If your environment isn't supported, it'll use `node-gyp` to build SQLite but you will need to install a C++ compiler and linker. ### Other ways to install -It is also possible to make your own build of `sqlite3` from its source instead of its npm package ([See below.](#building-from-the-source)). +It is also possible to make your own build of `sqlite3` from its source instead of its npm package ([See below.](#source-install)). The `sqlite3` module also works with [node-webkit](https://github.com/rogerwang/node-webkit) if node-webkit contains a supported version of Node.js engine. [(See below.)](#building-for-node-webkit) diff --git a/tools/BinaryBuilder.Dockerfile b/tools/BinaryBuilder.Dockerfile new file mode 100644 index 000000000..20f63ef36 --- /dev/null +++ b/tools/BinaryBuilder.Dockerfile @@ -0,0 +1,25 @@ +ARG NODE_VERSION=16 +ARG VARIANT=bullseye + +FROM node:$NODE_VERSION-$VARIANT + +ARG VARIANT + +RUN if [ "$VARIANT" = "alpine" ] ; then apk add build-base python3 --update-cache ; fi + +WORKDIR /usr/src/build + +COPY . . +RUN npm install --ignore-scripts + +# Workaround for https://github.com/mapbox/node-pre-gyp/issues/644 +RUN cd node_modules/\@mapbox/node-pre-gyp \ + && npm install fs-extra@10.0.1 \ + && sed -i -e s/\'fs/\'fs-extra/ -e s/fs\.renameSync/fs.moveSync/ ./lib/util/napi.js + +RUN npx node-pre-gyp configure +RUN npx node-pre-gyp build +RUN npm run test +RUN npx node-pre-gyp package + +CMD ["sh"]