Skip to content

Commit 2b0bd83

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

File tree

9 files changed

+294
-1734
lines changed

9 files changed

+294
-1734
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: 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:

docs/DEVELOP.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ This project uses [npm version](https://docs.npmjs.com/cli/v10/commands/npm-vers
2222
```
2323

2424
The CI workflow will automatically:
25-
- Build binaries for all platforms
26-
- Upload them as release assets
27-
- Publish the package to npm
25+
- Build prebuilt binaries for all platforms
26+
- Upload them to GitHub Release
27+
- Publish the package to npm (with bundled prebuilt binaries)
2828

2929
3. ** Edit the generated Pre-release
3030
- select "Generate release notes" and adjust them to your needs
@@ -44,12 +44,15 @@ When you push a tag (e.g., `v6.0.2`), the CI workflow will:
4444

4545
1. Build prebuilt binaries for:
4646
- macOS (x64, arm64)
47-
- Linux (x64, arm64)
48-
- Windows (x64, ia32)
47+
- Linux glibc (x64, arm64)
48+
- Linux musl (x64, arm64)
49+
- Windows (x64)
4950

5051
2. Upload binaries to GitHub Release
5152

52-
3. Publish to npm using trusted publishing (no NPM_TOKEN required)
53+
3. Merge all prebuilt binaries into the npm package and publish to npm
54+
55+
On PRs and pushes to main (non-tag), the CI also creates an npm tarball artifact (via `npm pack`) so the package contents can be inspected before publishing.
5356

5457
## Checking the release
5558

@@ -75,4 +78,4 @@ This ensures:
7578
Before committing changes:
7679
1. Run `yarn lint --fix` to fix code style issues
7780
2. Run `yarn test` to ensure all tests pass
78-
3. Review changes before pushing
81+
3. Review changes before pushing

lib/sqlite3-binding.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('bindings')('node_sqlite3.node');
1+
module.exports = require('node-gyp-build')(require('path').join(__dirname, '..'));

0 commit comments

Comments
 (0)