Skip to content

Commit f36b103

Browse files
authored
Merge pull request #15 from gms1/feature/replace-deprecated-prebuild
Replace deprectated prebuild
2 parents bf1f8bc + bb80c21 commit f36b103

File tree

11 files changed

+311
-1749
lines changed

11 files changed

+311
-1749
lines changed

.github/workflows/ci.yml

Lines changed: 123 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -63,48 +63,82 @@ jobs:
6363
strategy:
6464
fail-fast: false
6565
matrix:
66-
os:
67-
- macos-latest
68-
- ubuntu-24.04
69-
- windows-latest
70-
host:
71-
- x64
72-
target:
73-
- x64
74-
node:
75-
- 20
76-
- 22
77-
- 24
78-
exclude:
79-
# Node 20 x64 crashes under Rosetta 2 on ARM64 macOS runners
66+
include:
8067
- os: macos-latest
68+
host: x64
69+
target: x64
70+
platform: macos-x64
8171
node: 20
72+
- os: macos-latest
8273
host: x64
83-
include:
74+
target: x64
75+
platform: macos-x64
76+
node: 22
8477
- os: macos-latest
78+
host: x64
79+
target: x64
80+
platform: macos-x64
81+
node: 24
82+
- os: ubuntu-24.04
83+
host: x64
84+
target: x64
85+
platform: linux-x64
86+
node: 20
87+
- os: ubuntu-24.04
88+
host: x64
89+
target: x64
90+
platform: linux-x64
91+
node: 22
92+
- os: ubuntu-24.04
93+
host: x64
94+
target: x64
95+
platform: linux-x64
96+
node: 24
97+
- os: windows-latest
98+
host: x64
99+
target: x64
100+
platform: win32-x64
85101
node: 20
102+
- os: windows-latest
103+
host: x64
104+
target: x64
105+
platform: win32-x64
106+
node: 22
107+
- os: windows-latest
108+
host: x64
109+
target: x64
110+
platform: win32-x64
111+
node: 24
112+
- os: macos-latest
86113
host: arm64
87114
target: arm64
115+
platform: macos-arm64
116+
node: 20
88117
- os: macos-latest
89-
node: 22
90118
host: arm64
91119
target: arm64
120+
platform: macos-arm64
121+
node: 22
92122
- os: macos-latest
93-
node: 24
94123
host: arm64
95124
target: arm64
125+
platform: macos-arm64
126+
node: 24
96127
- os: ubuntu-24.04-arm
97-
node: 20
98128
host: arm64
99129
target: arm64
130+
platform: linux-arm64
131+
node: 20
100132
- os: ubuntu-24.04-arm
101-
node: 22
102133
host: arm64
103134
target: arm64
135+
platform: linux-arm64
136+
node: 22
104137
- os: ubuntu-24.04-arm
105-
node: 24
106138
host: arm64
107139
target: arm64
140+
platform: linux-arm64
141+
node: 24
108142
name: ${{ matrix.os }} (node=${{ matrix.node }}, host=${{ matrix.host }}, target=${{ matrix.target }})
109143
steps:
110144
- uses: actions/checkout@v6
@@ -143,16 +177,17 @@ jobs:
143177
echo "CXXFLAGS=${CXXFLAGS:-} -include ../src/gcc-preinclude.h" >> $GITHUB_ENV
144178
145179
- name: Build binaries
146-
run: yarn prebuild -a ${{ env.TARGET }}
180+
run: yarn prebuild
147181

148182
- name: Print binary info
149183
if: contains(matrix.os, 'ubuntu')
150184
run: |
151-
ldd build/**/node_sqlite3.node
185+
BIN=$(find prebuilds -name "*.node" | head -1)
186+
ldd "$BIN"
152187
echo "---"
153-
nm build/**/node_sqlite3.node | grep "GLIBC_" | c++filt || true
188+
nm "$BIN" | grep "GLIBC_" | c++filt || true
154189
echo "---"
155-
file build/**/node_sqlite3.node
190+
file "$BIN"
156191
157192
- name: Run tests
158193
run: yarn test
@@ -161,13 +196,15 @@ jobs:
161196
uses: actions/upload-artifact@v7
162197
if: matrix.node == 24
163198
with:
164-
name: prebuilt-binaries-${{ matrix.os }}-${{ matrix.host }}
199+
name: prebuilt-binaries-${{ matrix.platform }}
165200
path: prebuilds/*
166201
retention-days: 7
167202

168203
- name: Upload binaries to GitHub Release
169-
run: yarn upload --upload-all ${{ github.token }}
204+
run: gh release upload ${GITHUB_REF#refs/tags/} prebuilds/* --clobber
170205
if: matrix.node == 24 && startsWith(github.ref, 'refs/tags/')
206+
env:
207+
GH_TOKEN: ${{ github.token }}
171208

172209
build-musl:
173210
permissions:
@@ -209,8 +246,54 @@ jobs:
209246
retention-days: 7
210247

211248
- name: Upload binaries to GitHub Release
212-
run: yarn install --frozen-lockfile --ignore-scripts && yarn upload --upload-all ${{ github.token }}
249+
run: |
250+
gh release upload ${GITHUB_REF#refs/tags/} prebuilds/* --clobber
213251
if: startsWith(github.ref, 'refs/tags/')
252+
env:
253+
GH_TOKEN: ${{ github.token }}
254+
255+
package:
256+
needs: [build]
257+
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request') || (github.event_name == 'push' && !startsWith(github.ref, 'refs/tags/'))
258+
runs-on: ubuntu-latest
259+
steps:
260+
- uses: actions/checkout@v6
261+
- uses: actions/setup-node@v6
262+
with:
263+
node-version: 24
264+
265+
- name: Install dependencies
266+
run: yarn install --frozen-lockfile --ignore-scripts
267+
268+
- name: Download all prebuilt binary artifacts
269+
uses: actions/download-artifact@v5
270+
with:
271+
path: prebuilds-artifacts
272+
merge-multiple: true
273+
274+
- name: Merge prebuilds into package
275+
run: |
276+
mkdir -p prebuilds
277+
# Each artifact may contain platform-specific subdirs
278+
# Copy all prebuilds from artifacts into prebuilds/
279+
cp -r prebuilds-artifacts/*/ prebuilds/ 2>/dev/null || true
280+
# Also handle flat structure (files directly in artifact root)
281+
cp -r prebuilds-artifacts/ prebuilds/ 2>/dev/null || true
282+
# Verify the prebuilds are present
283+
find prebuilds -name '*.node' -type f
284+
285+
- name: Create npm tarball
286+
run: |
287+
npm pack
288+
echo "npm tarball created:"
289+
ls -la *.tgz
290+
291+
- name: Upload npm tarball as commit artifact
292+
uses: actions/upload-artifact@v7
293+
with:
294+
name: npm-package-tarball
295+
path: '*.tgz'
296+
retention-days: 7
214297

215298
publish-npm:
216299
needs: [build, build-musl]
@@ -229,5 +312,18 @@ jobs:
229312
- name: Install dependencies
230313
run: yarn install --frozen-lockfile --ignore-scripts
231314

315+
- name: Download all prebuilt binary artifacts
316+
uses: actions/download-artifact@v5
317+
with:
318+
path: prebuilds-artifacts
319+
merge-multiple: true
320+
321+
- name: Merge prebuilds into package
322+
run: |
323+
mkdir -p prebuilds
324+
cp -r prebuilds-artifacts/*/ prebuilds/ 2>/dev/null || true
325+
cp -r prebuilds-artifacts/ prebuilds/ 2>/dev/null || true
326+
find prebuilds -name '*.node' -type f
327+
232328
- name: Publish to npm
233329
run: npm publish

README.md

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ Asynchronous, non-blocking [SQLite3](https://sqlite.org/) bindings for [Node.js]
1919

2020
- Straightforward query and parameter binding interface
2121
- Full Buffer/Blob support
22-
- Extensive [debugging support](https://github.com/gms1/node-sqlite3/wiki/Debugging)
23-
- [Query serialization](https://github.com/gms1/node-sqlite3/wiki/Control-Flow) API
24-
- [Extension support](https://github.com/gms1/node-sqlite3/wiki/API#databaseloadextensionpath-callback), including bundled support for the [json1 extension](https://www.sqlite.org/json1.html)
22+
- Extensive debugging support via [verbose mode](docs/API.md#verbose-mode)
23+
- [Query serialization](docs/API.md#databaseserialize) API
24+
- [Extension support](docs/API.md#databaseloadextension), including bundled support for the [json1 extension](https://www.sqlite.org/json1.html)
2525
- Big test suite
26-
- Written in modern C++ and tested for memory leaks
26+
- Written in modern C++
2727
- Bundles SQLite v3.53.0, or you can build using a local SQLite
2828

2929
# Installing
@@ -36,27 +36,24 @@ npm install @homeofthings/sqlite3
3636
# or
3737
yarn add @homeofthings/sqlite3
3838
```
39-
* GitHub's `main` branch: `npm install https://github.com/gms1/node-sqlite3/tarball/main`
4039

4140
### Prebuilt binaries
4241

43-
`@homeofthings/sqlite3` uses [Node-API](https://nodejs.org/api/n-api.html) so prebuilt binaries do not need to be built for specific Node versions. Prebuilt binaries are available for 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. Requires Node.js v20.17.0 or later.
42+
`@homeofthings/sqlite3` uses [Node-API](https://nodejs.org/api/n-api.html) so prebuilt binaries do not need to be built for specific Node versions. Prebuilt binaries are built as NAPI-version-agnostic (`@homeofthings+sqlite3.*.node`) using the `--napi` flag, and work on any Node.js version that supports the NAPI version used at compile time. Requires Node.js v20.17.0 or later.
4443

45-
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. The following targets are currently provided:
44+
Prebuilt binaries are bundled inside the npm package using [`prebuildify`](https://github.com/prebuild/prebuildify) and loaded at runtime by [`node-gyp-build`](https://github.com/prebuild/node-gyp-build). No separate download step is needed — `npm install` just works. The following targets are currently provided:
4645

4746
* `darwin-arm64`
4847
* `darwin-x64`
49-
* `linux-arm64`
50-
* `linux-x64`
51-
* `linuxmusl-arm64`
52-
* `linuxmusl-x64`
48+
* `linux-arm64` (glibc)
49+
* `linux-x64` (glibc)
50+
* `linux-arm64` (musl)
51+
* `linux-x64` (musl)
5352
* `win32-x64`
5453

55-
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).
56-
5754
Support for other platforms and architectures may be added in the future if CI supports building on them.
5855

59-
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.
56+
If your platform isn't supported, `node-gyp-build` automatically falls back to building from source using `node-gyp`.
6057

6158
### Other ways to install
6259

@@ -136,26 +133,29 @@ db.close();
136133

137134
## Source install
138135

139-
To skip searching for pre-compiled binaries, and force a build from source, use
136+
To build from source, use
140137

141138
```bash
142-
npm install --build-from-source --sqlite=/usr/local
139+
cd node_modules/@homeofthings/sqlite3
140+
npx node-gyp rebuild --sqlite=/usr/local
143141
```
144142

145143
If building against an external sqlite3 make sure to have the development headers available. Mac OS X ships with these by default. If you don't have them installed, install the `-dev` package with your package manager, e.g. `apt-get install libsqlite3-dev` for Debian/Ubuntu. Make sure that you have at least `libsqlite3` >= 3.6.
146144

147145
Note, if building against homebrew-installed sqlite on OS X you can do:
148146

149147
```bash
150-
npm install --build-from-source --sqlite=/usr/local/opt/sqlite/
148+
cd node_modules/@homeofthings/sqlite3
149+
npx node-gyp rebuild --sqlite=/usr/local/opt/sqlite/
151150
```
152151

153152
## Custom file header (magic)
154153

155154
The default sqlite file header is "SQLite format 3". You can specify a different magic, though this will make standard tools and libraries unable to work with your files.
156155

157156
```bash
158-
npm install --build-from-source --sqlite_magic="MyCustomMagic15"
157+
cd node_modules/@homeofthings/sqlite3
158+
npx node-gyp rebuild --sqlite_magic="MyCustomMagic15"
159159
```
160160

161161
Note that the magic *must* be exactly 15 characters long (16 bytes including null terminator).
@@ -172,13 +172,15 @@ To build `sqlite3` for node-webkit:
172172

173173
```bash
174174
NODE_WEBKIT_VERSION="0.8.6" # see latest version at https://github.com/rogerwang/node-webkit#downloads
175-
npm install @homeofthings/sqlite3 --build-from-source --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)
175+
cd node_modules/@homeofthings/sqlite3
176+
npx node-gyp rebuild --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)
176177
```
177178

178179
You can also run this command from within a `@homeofthings/sqlite3` checkout:
179180

180181
```bash
181-
npm install --build-from-source --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)
182+
cd node_modules/@homeofthings/sqlite3
183+
npx node-gyp rebuild --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)
182184
```
183185

184186
Remember the following:
@@ -197,7 +199,8 @@ For instructions on building SQLCipher, see [Building SQLCipher for Node.js](htt
197199
To run against SQLCipher, you need to compile `sqlite3` from source by passing build options like:
198200

199201
```bash
200-
npm install @homeofthings/sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=/usr/
202+
cd node_modules/@homeofthings/sqlite3
203+
npx node-gyp rebuild --sqlite_libname=sqlcipher --sqlite=/usr/
201204

202205
node -e 'require("@homeofthings/sqlite3")'
203206
```
@@ -211,7 +214,8 @@ Set the location where `brew` installed it:
211214
```bash
212215
export LDFLAGS="-L`brew --prefix`/opt/sqlcipher/lib"
213216
export CPPFLAGS="-I`brew --prefix`/opt/sqlcipher/include/sqlcipher"
214-
npm install @homeofthings/sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix`
217+
cd node_modules/@homeofthings/sqlite3
218+
npx node-gyp rebuild --sqlite_libname=sqlcipher --sqlite=`brew --prefix`
215219

216220
node -e 'require("@homeofthings/sqlite3")'
217221
```
@@ -224,23 +228,26 @@ Set the location where `make` installed it:
224228
export LDFLAGS="-L/usr/local/lib"
225229
export CPPFLAGS="-I/usr/local/include -I/usr/local/include/sqlcipher"
226230
export CXXFLAGS="$CPPFLAGS"
227-
npm install @homeofthings/sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=/usr/local --verbose
231+
cd node_modules/@homeofthings/sqlite3
232+
npx node-gyp rebuild --sqlite_libname=sqlcipher --sqlite=/usr/local --verbose
228233

229234
node -e 'require("@homeofthings/sqlite3")'
230235
```
231236

232237
### Custom builds and Electron
233238

234-
Running `sqlite3` through [electron-rebuild](https://github.com/electron/electron-rebuild) does not preserve the SQLCipher extension, so some additional flags are needed to make this build Electron compatible. Your `npm install @homeofthings/sqlite3 --build-from-source` command needs these additional flags (be sure to replace the target version with the current Electron version you are working with):
239+
Running `sqlite3` through [electron-rebuild](https://github.com/electron/electron-rebuild) does not preserve the SQLCipher extension, so some additional flags are needed to make this build Electron compatible. So your command needs these additional flags (be sure to replace the target version with the current Electron version you are working with):
235240

236241
```bash
237-
npm install @homeofthings/sqlite3 --build-from-source --runtime=electron --target=18.2.1 --dist-url=https://electronjs.org/headers
242+
cd node_modules/@homeofthings/sqlite3
243+
npx node-gyp rebuild --runtime=electron --target=18.2.1 --dist-url=https://electronjs.org/headers
238244
```
239245

240246
In the case of MacOS with Homebrew, the command should look like the following:
241247

242248
```bash
243-
npm install @homeofthings/sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix` --runtime=electron --target=18.2.1 --dist-url=https://electronjs.org/headers
249+
cd node_modules/@homeofthings/sqlite3
250+
npx node-gyp rebuild --sqlite_libname=sqlcipher --sqlite=`brew --prefix` --runtime=electron --target=18.2.1 --dist-url=https://electronjs.org/headers
244251
```
245252

246253
# Testing

binding.gyp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
},
1616
"include_dirs": [
1717
"<!@(node -p \"require('node-addon-api').include\")"],
18+
"dependencies": [
19+
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except"
20+
],
1821
"conditions": [
1922
["sqlite != 'internal'", {
2023
"include_dirs": [
@@ -36,7 +39,6 @@
3639
},
3740
{
3841
"dependencies": [
39-
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
4042
"deps/sqlite3.gyp:sqlite3"
4143
]
4244
}
@@ -94,4 +96,4 @@
9496
}
9597
}
9698
]
97-
}
99+
}

0 commit comments

Comments
 (0)