Skip to content

Commit 1165211

Browse files
authored
Switch from wazero to wasm2go (#362)
1 parent 137e269 commit 1165211

228 files changed

Lines changed: 2836 additions & 16325 deletions

File tree

Some content is hidden

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

.github/workflows/repro.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/workflows/repro.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ jobs:
6868
shell: bash
6969
run: |
7070
go work init .
71-
go work use -r embed/bcw2 gormlite
72-
go test ./embed/bcw2 ./gormlite
71+
go work use -r gormlite
72+
go test ./gormlite
7373
7474
- name: Test GORM
7575
shell: bash
@@ -104,6 +104,7 @@ jobs:
104104
- name: illumos
105105
action: omnios
106106
version: 'r151056'
107+
tflags: '-test.short'
107108
- name: openbsd
108109
version: '7.8'
109110
tflags: '-test.short'
@@ -144,11 +145,14 @@ jobs:
144145
os:
145146
- name: dragonfly
146147
action: 'vmactions/dragonflybsd-vm@v1'
148+
tflags: '-test.short'
147149
- name: illumos
148150
action: 'vmactions/openindiana-vm@v0'
151+
tflags: '-test.short'
149152
- name: solaris
150153
action: 'vmactions/solaris-vm@v1'
151154
bflags: '-tags sqlite3_dotlk'
155+
tflags: '-test.short'
152156
runs-on: ubuntu-latest
153157
needs: test
154158

@@ -166,27 +170,6 @@ jobs:
166170
- name: Test
167171
uses: ./.github/actions/vmactions
168172

169-
test-wasip1:
170-
runs-on: ubuntu-latest
171-
needs: test
172-
173-
steps:
174-
- uses: bytecodealliance/actions/wasmtime/setup@v1
175-
- uses: actions/checkout@v6
176-
- uses: actions/setup-go@v6
177-
with: { go-version: stable }
178-
179-
- name: Set path
180-
run: echo "$(go env GOROOT)/lib/wasm" >> "$GITHUB_PATH"
181-
182-
- name: Test wasmtime
183-
env:
184-
GOOS: wasip1
185-
GOARCH: wasm
186-
GOWASIRUNTIME: wasmtime
187-
GOWASIRUNTIMEARGS: '--env CI=true'
188-
run: go test -short -tags sqlite3_dotlk -skip Example ./...
189-
190173
test-qemu:
191174
runs-on: ubuntu-latest
192175
needs: test
@@ -198,15 +181,15 @@ jobs:
198181
with: { go-version: stable }
199182

200183
- name: Test 386 (32-bit)
201-
run: GOARCH=386 go test -short ./...
184+
run: GOARCH=386 go test ./...
202185

203-
- name: Test riscv64 (interpreter)
186+
- name: Test riscv64
204187
run: GOARCH=riscv64 go test -short ./...
205188

206-
- name: Test ppc64le (interpreter)
189+
- name: Test ppc64le
207190
run: GOARCH=ppc64le go test -short ./...
208191

209-
- name: Test loong64 (interpreter)
192+
- name: Test loong64
210193
run: GOARCH=loong64 go test -short ./...
211194

212195
- name: Test s390x (big-endian)
@@ -225,7 +208,7 @@ jobs:
225208
run: go test ./...
226209

227210
- name: Test arm (32-bit)
228-
run: GOARCH=arm GOARM=7 go test -short ./...
211+
run: GOARCH=arm GOARM=7 go test ./...
229212

230213
test-macintel:
231214
runs-on: macos-15-intel

README.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Go bindings to SQLite using wazero
1+
# Go bindings to SQLite using wasm2go
22

33
[![Go Reference](https://pkg.go.dev/badge/image)](https://pkg.go.dev/github.com/ncruces/go-sqlite3)
44
[![Go Report](https://goreportcard.com/badge/github.com/ncruces/go-sqlite3)](https://goreportcard.com/report/github.com/ncruces/go-sqlite3)
@@ -8,9 +8,9 @@ Go module `github.com/ncruces/go-sqlite3` is a `cgo`-free [SQLite](https://sqlit
88
It provides a [`database/sql`](https://pkg.go.dev/database/sql) compatible driver,
99
as well as direct access to most of the [C SQLite API](https://sqlite.org/cintro.html).
1010

11-
It wraps a [Wasm](https://webassembly.org/) [build](embed/) of SQLite,
12-
and uses [wazero](https://wazero.io/) as the runtime.\
13-
Go, wazero and [`x/sys`](https://pkg.go.dev/golang.org/x/sys) are the _only_ direct dependencies.
11+
It wraps a [Wasm](https://webassembly.org/) build of SQLite,
12+
and uses [wasm2go](https://github.com/ncruces/wasm2go) to translate it to Go.\
13+
Go and [`x/sys`](https://pkg.go.dev/golang.org/x/sys) are the _only_ direct dependencies.
1414

1515
### Getting started
1616

@@ -19,7 +19,6 @@ Using the [`database/sql`](https://pkg.go.dev/database/sql) driver:
1919

2020
import "database/sql"
2121
import _ "github.com/ncruces/go-sqlite3/driver"
22-
import _ "github.com/ncruces/go-sqlite3/embed"
2322

2423
var version string
2524
db, _ := sql.Open("sqlite3", "file:demo.db")
@@ -34,8 +33,6 @@ db.QueryRow(`SELECT sqlite_version()`).Scan(&version)
3433
- [`github.com/ncruces/go-sqlite3/driver`](https://pkg.go.dev/github.com/ncruces/go-sqlite3/driver)
3534
provides a [`database/sql`](https://pkg.go.dev/database/sql) driver
3635
([example](https://pkg.go.dev/github.com/ncruces/go-sqlite3/driver#example-package)).
37-
- [`github.com/ncruces/go-sqlite3/embed`](https://pkg.go.dev/github.com/ncruces/go-sqlite3/embed)
38-
embeds a build of SQLite into your application.
3936
- [`github.com/ncruces/go-sqlite3/vfs`](https://pkg.go.dev/github.com/ncruces/go-sqlite3/vfs)
4037
wraps the [C SQLite VFS API](https://sqlite.org/vfs.html) and provides a pure Go implementation.
4138
- [`github.com/ncruces/go-sqlite3/gormlite`](https://pkg.go.dev/github.com/ncruces/go-sqlite3/gormlite)
@@ -64,7 +61,6 @@ db.QueryRow(`SELECT sqlite_version()`).Scan(&version)
6461
- [statistics functions](https://pkg.go.dev/github.com/ncruces/go-sqlite3/ext/stats)
6562
- [encryption at rest](vfs/adiantum/README.md)
6663
- [many extensions](ext/README.md)
67-
- [and more…](embed/README.md)
6864

6965
### Caveats
7066

@@ -79,9 +75,7 @@ memory usage will be higher than alternatives.
7975
### Testing
8076

8177
This project aims for [high test coverage](https://github.com/ncruces/go-sqlite3/wiki/Test-coverage-report).
82-
It also benefits greatly from [SQLite's](https://sqlite.org/testing.html) and
83-
[wazero's](https://tetrate.io/blog/introducing-wazero-from-tetrate/#:~:text=Rock%2Dsolid%20test%20approach)
84-
thorough testing.
78+
It also benefits greatly from [SQLite's](https://sqlite.org/testing.html) thorough testing.
8579

8680
Every commit is tested on:
8781
* Linux: amd64, arm64, 386, arm, riscv64, ppc64le, loong64, s390x

backup.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,22 @@ func (src *Conn) BackupInit(srcDB, dstURI string) (*Backup, error) {
6262
}
6363

6464
func (c *Conn) backupInit(dst ptr_t, dstName string, src ptr_t, srcName string) (*Backup, error) {
65-
defer c.arena.mark()()
66-
dstPtr := c.arena.string(dstName)
67-
srcPtr := c.arena.string(srcName)
65+
defer c.arena.Mark()()
66+
dstPtr := c.arena.String(dstName)
67+
srcPtr := c.arena.String(srcName)
6868

6969
other := dst
7070
if c.handle == dst {
7171
other = src
7272
}
7373

74-
ptr := ptr_t(c.call("sqlite3_backup_init",
75-
stk_t(dst), stk_t(dstPtr),
76-
stk_t(src), stk_t(srcPtr)))
74+
ptr := ptr_t(c.wrp.Xsqlite3_backup_init(
75+
int32(dst), int32(dstPtr),
76+
int32(src), int32(srcPtr)))
7777
if ptr == 0 {
7878
defer c.closeDB(other)
79-
rc := res_t(c.call("sqlite3_errcode", stk_t(dst)))
80-
return nil, c.sqlite.error(rc, dst)
79+
rc := res_t(c.wrp.Xsqlite3_errcode(int32(dst)))
80+
return nil, c.errorFor(dst, rc)
8181
}
8282

8383
return &Backup{
@@ -97,7 +97,7 @@ func (b *Backup) Close() error {
9797
return nil
9898
}
9999

100-
rc := res_t(b.c.call("sqlite3_backup_finish", stk_t(b.handle)))
100+
rc := res_t(b.c.wrp.Xsqlite3_backup_finish(int32(b.handle)))
101101
b.c.closeDB(b.otherc)
102102
b.handle = 0
103103
return b.c.error(rc)
@@ -108,7 +108,7 @@ func (b *Backup) Close() error {
108108
//
109109
// https://sqlite.org/c3ref/backup_finish.html#sqlite3backupstep
110110
func (b *Backup) Step(nPage int) (done bool, err error) {
111-
rc := res_t(b.c.call("sqlite3_backup_step", stk_t(b.handle), stk_t(nPage)))
111+
rc := res_t(b.c.wrp.Xsqlite3_backup_step(int32(b.handle), int32(nPage)))
112112
if rc == _DONE {
113113
return true, nil
114114
}
@@ -120,7 +120,7 @@ func (b *Backup) Step(nPage int) (done bool, err error) {
120120
//
121121
// https://sqlite.org/c3ref/backup_finish.html#sqlite3backupremaining
122122
func (b *Backup) Remaining() int {
123-
n := int32(b.c.call("sqlite3_backup_remaining", stk_t(b.handle)))
123+
n := int32(b.c.wrp.Xsqlite3_backup_remaining(int32(b.handle)))
124124
return int(n)
125125
}
126126

@@ -129,6 +129,6 @@ func (b *Backup) Remaining() int {
129129
//
130130
// https://sqlite.org/c3ref/backup_finish.html#sqlite3backuppagecount
131131
func (b *Backup) PageCount() int {
132-
n := int32(b.c.call("sqlite3_backup_pagecount", stk_t(b.handle)))
132+
n := int32(b.c.wrp.Xsqlite3_backup_pagecount(int32(b.handle)))
133133
return int(n)
134134
}

0 commit comments

Comments
 (0)