Skip to content

Commit e278f3c

Browse files
committed
Replace deprectated prebuld
1 parent 2ca26e8 commit e278f3c

10 files changed

Lines changed: 387 additions & 1734 deletions

File tree

.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
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Test npm package
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
target_run_id:
6+
description: 'The Run ID of the upstream CI workflow'
7+
required: true
8+
type: string
9+
node_version:
10+
description: 'Node.js version to test with'
11+
required: false
12+
default: '20'
13+
type: string
14+
15+
jobs:
16+
test-artifact:
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
include:
21+
- os: ubuntu-latest
22+
platform: linux-x64
23+
- os: ubuntu-24.04-arm
24+
platform: linux-arm64
25+
- os: macos-latest
26+
platform: macos-arm64
27+
- os: windows-latest
28+
platform: win32-x64
29+
runs-on: ${{ matrix.os }}
30+
name: ${{ matrix.platform }}
31+
steps:
32+
- name: Download artifact from specific run
33+
uses: actions/download-artifact@v5
34+
with:
35+
run-id: ${{ github.event.inputs.target_run_id }}
36+
github-token: ${{ secrets.GITHUB_TOKEN }}
37+
name: npm-package-tarball
38+
path: ./downloads
39+
40+
- name: Set up Node.js
41+
uses: actions/setup-node@v6
42+
with:
43+
node-version: ${{ github.event.inputs.node_version || '20' }}
44+
45+
- name: Install tarball and verify
46+
shell: bash
47+
run: |
48+
TARBALL=$(ls ./downloads/*.tgz | head -1)
49+
echo "Installing tarball: $TARBALL"
50+
mkdir test-project && cd test-project
51+
npm init -y
52+
npm install "$TARBALL"
53+
echo "--- Installed package contents ---"
54+
ls -la node_modules/@homeofthings/sqlite3/ 2>/dev/null || dir node_modules\\@homeofthings\\sqlite3\\ 2>/dev/null || true
55+
echo "--- Prebuilds ---"
56+
find node_modules/@homeofthings/sqlite3/prebuilds -name "*.node" -type f 2>/dev/null || true
57+
58+
- name: Smoke test - callback API
59+
shell: bash
60+
run: |
61+
cd test-project
62+
node -e "
63+
const sqlite3 = require('@homeofthings/sqlite3');
64+
console.log('sqlite3 version:', sqlite3.VERSION);
65+
const db = new sqlite3.Database(':memory:');
66+
db.serialize(() => {
67+
db.run('CREATE TABLE test (id INT, name TEXT)');
68+
db.run('INSERT INTO test VALUES (1, \"hello\")');
69+
db.get('SELECT * FROM test', (err, row) => {
70+
if (err) { console.error('Query failed:', err); process.exit(1); }
71+
console.log('Callback API result:', JSON.stringify(row));
72+
db.close();
73+
});
74+
});
75+
"
76+
77+
- name: Smoke test - promise API
78+
shell: bash
79+
run: |
80+
cd test-project
81+
node -e "
82+
const sqlite3 = require('@homeofthings/sqlite3');
83+
const { SqliteDatabase } = sqlite3;
84+
async function main() {
85+
const db = await SqliteDatabase.open(':memory:');
86+
await db.run('CREATE TABLE test (id INT, name TEXT)');
87+
await db.run('INSERT INTO test VALUES (1, \"hello\")');
88+
const row = await db.get('SELECT * FROM test');
89+
console.log('Promise API result:', JSON.stringify(row));
90+
await db.close();
91+
}
92+
main().catch(err => { console.error(err); process.exit(1); });
93+
"

README.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,25 @@ yarn add @homeofthings/sqlite3
3636

3737
### Prebuilt binaries
3838

39-
`@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.
39+
`@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.
4040

41-
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:
41+
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:
4242

4343
* `darwin-arm64`
4444
* `darwin-x64`
45-
* `linux-arm64`
46-
* `linux-x64`
47-
* `linuxmusl-arm64`
48-
* `linuxmusl-x64`
45+
* `linux-arm64` (glibc)
46+
* `linux-x64` (glibc)
47+
* `linux-arm64` (musl)
48+
* `linux-x64` (musl)
4949
* `win32-x64`
5050

51-
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).
52-
5351
Support for other platforms and architectures may be added in the future if CI supports building on them.
5452

55-
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.
53+
If your platform isn't supported, `node-gyp-build` automatically falls back to building from source using `node-gyp`. For custom builds (e.g., SQLCipher, external SQLite), use `--build-from-source`:
54+
55+
```bash
56+
npm install @homeofthings/sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=/usr/
57+
```
5658

5759
### Other ways to install
5860

@@ -135,23 +137,23 @@ db.close();
135137
To skip searching for pre-compiled binaries, and force a build from source, use
136138

137139
```bash
138-
npm install --build-from-source --sqlite=/usr/local
140+
npm install @homeofthings/sqlite3 --build-from-source --sqlite=/usr/local
139141
```
140142

141143
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.
142144

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

145147
```bash
146-
npm install --build-from-source --sqlite=/usr/local/opt/sqlite/
148+
npm install @homeofthings/sqlite3 --build-from-source --sqlite=/usr/local/opt/sqlite/
147149
```
148150

149151
## Custom file header (magic)
150152

151153
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.
152154

153155
```bash
154-
npm install --build-from-source --sqlite_magic="MyCustomMagic15"
156+
npm install @homeofthings/sqlite3 --build-from-source --sqlite_magic="MyCustomMagic15"
155157
```
156158

157159
Note that the magic *must* be exactly 15 characters long (16 bytes including null terminator).
@@ -174,7 +176,7 @@ npm install @homeofthings/sqlite3 --build-from-source --runtime=node-webkit --ta
174176
You can also run this command from within a `@homeofthings/sqlite3` checkout:
175177

176178
```bash
177-
npm install --build-from-source --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)
179+
npm install @homeofthings/sqlite3 --build-from-source --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)
178180
```
179181

180182
Remember the following:

0 commit comments

Comments
 (0)