Skip to content

Commit 2f62305

Browse files
authored
Switch libSQL JavaScript SDK to use napi-rs (#182)
This pull request ports the libSQL JavaScript package to use `napi-rs` to replace Neon bindings. The main motivation is that -- despite multiple attempts -- I have not been able to upgrade Neon bindings (the toolchain changed significantly). But perhaps more importantly, most projects seem to have converged around `napi-rs` and it has more complete support for NAPI anyway. Fixes #184
2 parents ff914ef + e2cb98c commit 2f62305

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+4514
-4788
lines changed

.cargo/config.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
[target.x86_64-unknown-linux-musl]
2-
rustflags = ["-C", "target-feature=-crt-static"]
31
[target.aarch64-unknown-linux-musl]
2+
linker = "aarch64-alpine-linux-musl-gcc"
43
rustflags = ["-C", "target-feature=-crt-static"]
54
[target.arm-unknown-linux-musleabihf]
65
rustflags = ["-C", "target-feature=-crt-static"]

.github/workflows/CI.yml

Lines changed: 344 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,344 @@
1+
name: CI
2+
env:
3+
DEBUG: napi:*
4+
APP_NAME: libsql
5+
MACOSX_DEPLOYMENT_TARGET: '10.13'
6+
permissions:
7+
contents: write
8+
id-token: write
9+
'on':
10+
push:
11+
branches:
12+
- main
13+
tags-ignore:
14+
- '**'
15+
paths-ignore:
16+
- '**/*.md'
17+
- LICENSE
18+
- '**/*.gitignore'
19+
- .editorconfig
20+
- docs/**
21+
pull_request: null
22+
jobs:
23+
build:
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
settings:
28+
- host: macos-latest
29+
target: x86_64-apple-darwin
30+
build: yarn build --target x86_64-apple-darwin
31+
- host: windows-latest
32+
build: yarn build --target x86_64-pc-windows-msvc
33+
target: x86_64-pc-windows-msvc
34+
- host: ubuntu-latest
35+
target: x86_64-unknown-linux-gnu
36+
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
37+
build: |-
38+
apt-get update -yq &&
39+
apt-get install -yq lld &&
40+
CMAKE_C_COMPILER=x86_64-linux-gnu-gcc CMAKE_CXX_COMPILER=x86_64-linux-gnu-g++ yarn build --target x86_64-unknown-linux-gnu
41+
- host: ubuntu-latest
42+
target: x86_64-unknown-linux-musl
43+
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
44+
build: apk add musl-dev musl-utils gcc && ls -l /usr/bin && CC=x86_64-alpine-linux-musl-gcc CMAKE_C_COMPILER=x86_64-alpine-linux-musl-gcc CMAKE_CXX_COMPILER=x86_64-alpine-linux-musl-g++ yarn build --target x86_64-unknown-linux-musl
45+
- host: macos-latest
46+
target: aarch64-apple-darwin
47+
build: yarn build --target aarch64-apple-darwin
48+
- host: ubuntu-24.04
49+
target: aarch64-unknown-linux-gnu
50+
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64
51+
build: |-
52+
apt-get update -yq &&
53+
apt-get install -yq gcc-aarch64-linux-gnu g++-aarch64-linux-gnu lld &&
54+
ls -l /usr/bin &&
55+
rustup target add aarch64-unknown-linux-gnu &&
56+
CC=x86_64-linux-gnu-gcc CMAKE_C_COMPILER=aarch64-linux-gnu-gcc CMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ RUSTC_LINKER=aarch64-linux-gnu-gcc yarn build --target aarch64-unknown-linux-gnu
57+
- host: ubuntu-24.04-arm
58+
target: aarch64-unknown-linux-musl
59+
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
60+
build: |-
61+
set -e &&
62+
apk add gcc musl-dev &&
63+
ls -l /usr/bin &&
64+
rustup target add aarch64-unknown-linux-musl &&
65+
CC=aarch64-alpine-linux-musl-gcc CMAKE_C_COMPILER=aarch64-alpine-linux-musl-gcc CMAKE_CXX_COMPILER=aarch64-alpine-linux-musl-g++ yarn build --target aarch64-unknown-linux-musl
66+
name: stable - ${{ matrix.settings.target }} - node@20
67+
runs-on: ${{ matrix.settings.host }}
68+
steps:
69+
- uses: actions/checkout@v4
70+
- name: Setup node
71+
uses: actions/setup-node@v4
72+
if: ${{ !matrix.settings.docker }}
73+
with:
74+
node-version: 20
75+
cache: yarn
76+
- name: Install
77+
uses: dtolnay/rust-toolchain@stable
78+
if: ${{ !matrix.settings.docker }}
79+
with:
80+
toolchain: stable
81+
targets: ${{ matrix.settings.target }}
82+
- name: Cache cargo
83+
uses: actions/cache@v4
84+
with:
85+
path: |
86+
~/.cargo/registry/index/
87+
~/.cargo/registry/cache/
88+
~/.cargo/git/db/
89+
.cargo-cache
90+
target/
91+
key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }}
92+
- uses: goto-bus-stop/setup-zig@v2
93+
if: ${{ matrix.settings.target == 'armv7-unknown-linux-gnueabihf' || matrix.settings.target == 'armv7-unknown-linux-musleabihf' }}
94+
with:
95+
version: 0.13.0
96+
- name: Setup toolchain
97+
run: ${{ matrix.settings.setup }}
98+
if: ${{ matrix.settings.setup }}
99+
shell: bash
100+
- name: Setup node x86
101+
if: matrix.settings.target == 'i686-pc-windows-msvc'
102+
run: yarn config set supportedArchitectures.cpu "ia32"
103+
shell: bash
104+
- name: Install dependencies
105+
run: yarn install
106+
- name: Setup node x86
107+
uses: actions/setup-node@v4
108+
if: matrix.settings.target == 'i686-pc-windows-msvc'
109+
with:
110+
node-version: 20
111+
cache: yarn
112+
architecture: x86
113+
- name: Build in docker
114+
uses: addnab/docker-run-action@v3
115+
if: ${{ matrix.settings.docker }}
116+
with:
117+
image: ${{ matrix.settings.docker }}
118+
options: '--user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build'
119+
run: ${{ matrix.settings.build }}
120+
shell: bash
121+
- name: Build
122+
run: ${{ matrix.settings.build }}
123+
if: ${{ !matrix.settings.docker }}
124+
shell: bash
125+
- name: Upload artifact
126+
uses: actions/upload-artifact@v4
127+
with:
128+
name: bindings-${{ matrix.settings.target }}
129+
path: ${{ env.APP_NAME }}.*.node
130+
if-no-files-found: error
131+
test-macOS-windows-binding:
132+
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
133+
needs:
134+
- build
135+
strategy:
136+
fail-fast: false
137+
matrix:
138+
settings:
139+
- host: macos-latest
140+
target: x86_64-apple-darwin
141+
- host: windows-latest
142+
target: x86_64-pc-windows-msvc
143+
node:
144+
- '22'
145+
runs-on: ${{ matrix.settings.host }}
146+
steps:
147+
- uses: actions/checkout@v4
148+
- name: Setup node
149+
uses: actions/setup-node@v4
150+
with:
151+
node-version: ${{ matrix.node }}
152+
cache: yarn
153+
architecture: x64
154+
- name: Install dependencies
155+
run: yarn install
156+
- name: Download artifacts
157+
uses: actions/download-artifact@v4
158+
with:
159+
name: bindings-${{ matrix.settings.target }}
160+
path: .
161+
- name: List packages
162+
run: ls -R .
163+
shell: bash
164+
- name: Test bindings
165+
run: yarn test
166+
test-linux-x64-gnu-binding:
167+
name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
168+
needs:
169+
- build
170+
strategy:
171+
fail-fast: false
172+
matrix:
173+
node:
174+
- '20'
175+
- '22'
176+
runs-on: ubuntu-latest
177+
steps:
178+
- uses: actions/checkout@v4
179+
- name: Setup node
180+
uses: actions/setup-node@v4
181+
with:
182+
node-version: ${{ matrix.node }}
183+
cache: yarn
184+
- name: Install dependencies
185+
run: yarn install
186+
- name: Download artifacts
187+
uses: actions/download-artifact@v4
188+
with:
189+
name: bindings-x86_64-unknown-linux-gnu
190+
path: .
191+
- name: List packages
192+
run: ls -R .
193+
shell: bash
194+
- name: Test bindings
195+
run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim yarn test
196+
test-linux-x64-musl-binding:
197+
name: Test bindings on x86_64-unknown-linux-musl - node@${{ matrix.node }}
198+
needs:
199+
- build
200+
strategy:
201+
fail-fast: false
202+
matrix:
203+
node:
204+
- '20'
205+
- '22'
206+
runs-on: ubuntu-latest
207+
steps:
208+
- uses: actions/checkout@v4
209+
- name: Setup node
210+
uses: actions/setup-node@v4
211+
with:
212+
node-version: ${{ matrix.node }}
213+
cache: yarn
214+
- name: Install dependencies
215+
run: |
216+
yarn config set supportedArchitectures.libc "musl"
217+
yarn install
218+
- name: Download artifacts
219+
uses: actions/download-artifact@v4
220+
with:
221+
name: bindings-x86_64-unknown-linux-musl
222+
path: .
223+
- name: List packages
224+
run: ls -R .
225+
shell: bash
226+
- name: Test bindings
227+
run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-alpine yarn test
228+
test-linux-aarch64-gnu-binding:
229+
name: Test bindings on aarch64-unknown-linux-gnu - node@${{ matrix.node }}
230+
needs:
231+
- build
232+
strategy:
233+
fail-fast: false
234+
matrix:
235+
node:
236+
- '20'
237+
- '22'
238+
runs-on: ubuntu-latest
239+
steps:
240+
- uses: actions/checkout@v4
241+
- name: Download artifacts
242+
uses: actions/download-artifact@v4
243+
with:
244+
name: bindings-aarch64-unknown-linux-gnu
245+
path: .
246+
- name: List packages
247+
run: ls -R .
248+
shell: bash
249+
- name: Install dependencies
250+
run: |
251+
yarn config set supportedArchitectures.cpu "arm64"
252+
yarn config set supportedArchitectures.libc "glibc"
253+
yarn install
254+
- name: Set up QEMU
255+
uses: docker/setup-qemu-action@v3
256+
with:
257+
platforms: arm64
258+
- run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
259+
- name: Setup and run tests
260+
uses: addnab/docker-run-action@v3
261+
with:
262+
image: node:${{ matrix.node }}-slim
263+
options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build'
264+
run: |
265+
set -e
266+
yarn test
267+
ls -la
268+
test-linux-aarch64-musl-binding:
269+
name: Test bindings on aarch64-unknown-linux-musl - node@${{ matrix.node }}
270+
needs:
271+
- build
272+
runs-on: ubuntu-latest
273+
steps:
274+
- uses: actions/checkout@v4
275+
- name: Download artifacts
276+
uses: actions/download-artifact@v4
277+
with:
278+
name: bindings-aarch64-unknown-linux-musl
279+
path: .
280+
- name: List packages
281+
run: ls -R .
282+
shell: bash
283+
- name: Install dependencies
284+
run: |
285+
yarn config set supportedArchitectures.cpu "arm64"
286+
yarn config set supportedArchitectures.libc "musl"
287+
yarn install
288+
- name: Set up QEMU
289+
uses: docker/setup-qemu-action@v3
290+
with:
291+
platforms: arm64
292+
- run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
293+
- name: Setup and run tests
294+
uses: addnab/docker-run-action@v3
295+
with:
296+
image: node:lts-alpine
297+
options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build'
298+
run: |
299+
set -e
300+
yarn test
301+
publish:
302+
name: Publish
303+
runs-on: ubuntu-latest
304+
needs:
305+
- test-macOS-windows-binding
306+
- test-linux-x64-gnu-binding
307+
- test-linux-x64-musl-binding
308+
- test-linux-aarch64-gnu-binding
309+
- test-linux-aarch64-musl-binding
310+
steps:
311+
- uses: actions/checkout@v4
312+
- name: Setup node
313+
uses: actions/setup-node@v4
314+
with:
315+
node-version: 20
316+
cache: yarn
317+
- name: Install dependencies
318+
run: yarn install
319+
- name: Download all artifacts
320+
uses: actions/download-artifact@v4
321+
with:
322+
path: artifacts
323+
- name: Move artifacts
324+
run: yarn artifacts
325+
- name: List packages
326+
run: ls -R ./npm
327+
shell: bash
328+
- name: Publish
329+
run: |
330+
npm config set provenance true
331+
if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
332+
then
333+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
334+
npm publish --access public
335+
elif git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+";
336+
then
337+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
338+
npm publish --tag next --access public
339+
else
340+
echo "Not a release, skipping publish"
341+
fi
342+
env:
343+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
344+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)