Skip to content

Commit 605c7f9

Browse files
committedDec 24, 2023
Replaced @mapbox/node-pre-gyp in favor of prebuild + prebuild-install
fixes #1641 fixes #1721 fixes #1714 fixes #1713 fixes #1700 fixes #1704 - `@mapbox/node-pre-gyp` is effectively unmaintained [1] as has a few bugs which our users keep running into - it seems the prebuilt binary world has moved in favor of prebuild + it's various other forms - one option would be to use prebuildify to bundle all binaries into the package, but that's a step too far removed from the current situation for now - instead, we can use prebuild-install to download the binaries, and `prebuild` to build + upload the binaries - this means we can remove node-pre-gyp and fix a bunch of issues! - eventually, we could start providing electron prebuilt binaries too [1]: mapbox/node-pre-gyp#657
1 parent a2cee71 commit 605c7f9

File tree

7 files changed

+26
-56
lines changed

7 files changed

+26
-56
lines changed
 

‎.github/workflows/ci.yml

+10-15
Original file line numberDiff line numberDiff line change
@@ -82,40 +82,35 @@ jobs:
8282
echo "CFLAGS=${CFLAGS:-} -include ../src/gcc-preinclude.h" >> $GITHUB_ENV
8383
echo "CXXFLAGS=${CXXFLAGS:-} -include ../src/gcc-preinclude.h" >> $GITHUB_ENV
8484
85-
- name: Configure build
86-
run: yarn node-pre-gyp configure --target_arch=${{ env.TARGET }}
87-
8885
- name: Build binaries
89-
run: yarn node-pre-gyp build --target_arch=${{ env.TARGET }}
86+
run: yarn prebuild -a ${{ env.TARGET }}
9087

9188
- name: Print binary info
9289
if: contains(matrix.os, 'ubuntu')
9390
run: |
94-
ldd lib/binding/*/node_sqlite3.node
91+
ldd build/**/node_sqlite3.node
9592
echo "---"
96-
nm lib/binding/*/node_sqlite3.node | grep "GLIBC_" | c++filt || true
93+
nm build/**/node_sqlite3.node | grep "GLIBC_" | c++filt || true
9794
echo "---"
98-
file lib/binding/napi-v*/*
95+
file build/**/node_sqlite3.node
9996
10097
- name: Run tests
10198
run: yarn test
10299

103-
- name: Package prebuilt binaries
104-
run: yarn node-pre-gyp package --target_arch=${{ env.TARGET }}
105-
106100
- name: Upload binaries to commit artifacts
107101
uses: actions/upload-artifact@v3
108102
if: matrix.node == 18
109103
with:
110104
name: prebuilt-binaries
111-
path: build/stage/*/*
105+
path: prebuilds/*
112106
retention-days: 7
113107

114108
- name: Upload binaries to GitHub Release
115-
run: yarn node-pre-gyp-github publish
109+
run: yarn upload
116110
if: matrix.node == 18 && startsWith(github.ref, 'refs/tags/')
117111
env:
118-
NODE_PRE_GYP_GITHUB_TOKEN: ${{ github.token }}
112+
GITHUB_TOKEN: ${{ github.token }}
113+
119114
build-qemu:
120115
runs-on: ubuntu-latest
121116
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/')
@@ -167,7 +162,7 @@ jobs:
167162
retention-days: 7
168163

169164
- name: Upload binaries to GitHub Release
170-
run: yarn install --ignore-scripts && yarn node-pre-gyp-github publish
165+
run: yarn install --ignore-scripts && yarn upload
171166
if: matrix.node == 18 && startsWith(github.ref, 'refs/tags/')
172167
env:
173-
NODE_PRE_GYP_GITHUB_TOKEN: ${{ github.token }}
168+
GITHUB_TOKEN: ${{ github.token }}

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ setup.sh
2929
*.tgz
3030
package-lock.json
3131
yarn.lock
32+
prebuilds

‎README.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ yarn add sqlite3
3535

3636
`sqlite3` v5+ was rewritten to use [Node-API](https://nodejs.org/api/n-api.html) so prebuilt binaries do not need to be built for specific Node versions. `sqlite3` currently builds for both Node-API v3 and v6. Check the [Node-API version matrix](https://nodejs.org/api/n-api.html#node-api-version-matrix) to ensure your Node version supports one of these. The prebuilt binaries should be supported on Node v10+.
3737

38-
The module uses [node-pre-gyp](https://github.com/mapbox/node-pre-gyp) to download the prebuilt binary for your platform, if it exists. These binaries are hosted on GitHub Releases for `sqlite3` versions above 5.0.2, and they are hosted on S3 otherwise. The following targets are currently provided:
38+
The module uses [`prebuild-install`](https://github.com/prebuild/prebuild-install) to download the prebuilt binary for your platform, if it exists. These binaries are hosted on GitHub Releases for `sqlite3` versions above 5.0.2, and they are hosted on S3 otherwise. The following targets are currently provided:
3939

4040
Format: `napi-v{napi_build_version}-{platform}-{libc}-{arch}`
4141

@@ -56,11 +56,11 @@ Format: `napi-v{napi_build_version}-{platform}-{libc}-{arch}`
5656
* `napi-v6-win32-unknown-ia32`
5757
* `napi-v6-win32-unknown-x64`
5858

59-
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).
59+
Unfortunately, [prebuild](https://github.com/prebuild/prebuild/issues/174) 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).
6060

6161
Support for other platforms and architectures may be added in the future if CI supports building on them.
6262

63-
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.
63+
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.
6464

6565
### Other ways to install
6666

@@ -148,8 +148,6 @@ NODE_WEBKIT_VERSION="0.8.6" # see latest version at https://github.com/rogerwang
148148
npm install sqlite3 --build-from-source --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)
149149
```
150150

151-
This command internally calls out to [`node-pre-gyp`](https://github.com/mapbox/node-pre-gyp) which itself calls out to [`nw-gyp`](https://github.com/rogerwang/nw-gyp) when the `--runtime=node-webkit` option is passed.
152-
153151
You can also run this command from within a `sqlite3` checkout:
154152

155153
```bash

‎binding.gyp

+2-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"includes": [ "deps/common-sqlite.gypi" ],
33
"variables": {
44
"sqlite%":"internal",
5-
"sqlite_libname%":"sqlite3"
5+
"sqlite_libname%":"sqlite3",
6+
"module_name": "node_sqlite3",
67
},
78
"targets": [
89
{
@@ -52,17 +53,6 @@
5253
"src/statement.cc"
5354
],
5455
"defines": [ "NAPI_VERSION=<(napi_build_version)", "NAPI_DISABLE_CPP_EXCEPTIONS=1" ]
55-
},
56-
{
57-
"target_name": "action_after_build",
58-
"type": "none",
59-
"dependencies": [ "<(module_name)" ],
60-
"copies": [
61-
{
62-
"files": [ "<(PRODUCT_DIR)/<(module_name).node" ],
63-
"destination": "<(module_path)"
64-
}
65-
]
6656
}
6757
]
6858
}

‎lib/sqlite3-binding.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
const binary = require('@mapbox/node-pre-gyp');
2-
const path = require('path');
3-
const binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')));
4-
const binding = require(binding_path);
5-
module.exports = exports = binding;
1+
module.exports = require('bindings')('node_sqlite3.node');

‎package.json

+7-10
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88
"url": "https://mapbox.com/"
99
},
1010
"binary": {
11-
"module_name": "node_sqlite3",
12-
"module_path": "./lib/binding/napi-v{napi_build_version}-{platform}-{libc}-{arch}",
13-
"host": "https://github.com/TryGhost/node-sqlite3/releases/download/",
14-
"remote_path": "v{version}",
15-
"package_name": "napi-v{napi_build_version}-{platform}-{libc}-{arch}.tar.gz",
1611
"napi_versions": [
1712
3,
1813
6
@@ -49,14 +44,15 @@
4944
"url": "https://github.com/TryGhost/node-sqlite3.git"
5045
},
5146
"dependencies": {
52-
"@mapbox/node-pre-gyp": "^1.0.0",
47+
"bindings": "^1.5.0",
5348
"node-addon-api": "^4.2.0",
49+
"prebuild-install": "^7.1.1",
5450
"tar": "^6.1.11"
5551
},
5652
"devDependencies": {
5753
"eslint": "8.56.0",
5854
"mocha": "10.2.0",
59-
"node-pre-gyp-github": "1.4.4"
55+
"prebuild": "12.1.0"
6056
},
6157
"peerDependencies": {
6258
"node-gyp": "8.x"
@@ -70,9 +66,10 @@
7066
"node-gyp": "8.x"
7167
},
7268
"scripts": {
73-
"build": "node-pre-gyp build",
74-
"build:debug": "node-pre-gyp build --debug",
75-
"install": "node-pre-gyp install --fallback-to-build",
69+
"install": "prebuild-install -r napi || node-gyp rebuild",
70+
"prebuild": "prebuild --runtime napi --all --verbose",
71+
"rebuild": "node-gyp rebuild",
72+
"upload": "prebuild --upload-all ${GITHUB_TOKEN}",
7673
"test": "node test/support/createdb.js && mocha -R spec --timeout 480000"
7774
},
7875
"license": "BSD-3-Clause",

‎tools/BinaryBuilder.Dockerfile

+2-9
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,12 @@ WORKDIR /usr/src/build
1212
COPY . .
1313
RUN npm install --ignore-scripts
1414

15-
# Workaround for https://github.com/mapbox/node-pre-gyp/issues/644
16-
RUN cd node_modules/\@mapbox/node-pre-gyp \
17-
&& npm install fs-extra@10.0.1 \
18-
&& sed -i -e s/\'fs/\'fs-extra/ -e s/fs\.renameSync/fs.moveSync/ ./lib/util/napi.js
19-
2015
ENV CFLAGS="${CFLAGS:-} -include ../src/gcc-preinclude.h"
2116
ENV CXXFLAGS="${CXXFLAGS:-} -include ../src/gcc-preinclude.h"
22-
RUN npx node-pre-gyp configure
23-
RUN npx node-pre-gyp build
17+
RUN npm run prebuild
2418

25-
RUN if case $VARIANT in "alpine"*) false;; *) true;; esac; then ldd lib/binding/*/node_sqlite3.node; nm lib/binding/*/node_sqlite3.node | grep \"GLIBC_\" | c++filt || true ; fi
19+
RUN if case $VARIANT in "alpine"*) false;; *) true;; esac; then ldd build/**/node_sqlite3.node; nm build/**/node_sqlite3.node | grep \"GLIBC_\" | c++filt || true ; fi
2620

2721
RUN npm run test
28-
RUN npx node-pre-gyp package
2922

3023
CMD ["sh"]

0 commit comments

Comments
 (0)