Skip to content

Commit ec3d9c3

Browse files
committed
*: fix non-cgo builds
The package offers very little runtime functionality without CGO but must be able to be depended upon without breaking cross builds. A CI check is added, and two issues are resolved that block non-CGO builds.
1 parent 6cfe794 commit ec3d9c3

File tree

9 files changed

+32
-5
lines changed

9 files changed

+32
-5
lines changed

.github/workflows/test-sqlite.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ jobs:
2727
run: go test -v ./...
2828

2929
- name: Race
30-
run: go test -v -race ./...
30+
run: go test -v -race ./...
31+
32+
- name: No CGO build
33+
run: CGO_ENABLED=0 go install ./...

sqlite.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,3 +1131,6 @@ type ConnLogger interface {
11311131
// Rollback is called after a rollback statement.
11321132
Rollback()
11331133
}
1134+
1135+
// LogCallback receives SQLite log messages.
1136+
type LogCallback func(code sqliteh.Code, msg string)

sqlite_cgo.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@ package sqlite
55

66
import (
77
"github.com/tailscale/sqlite/cgosqlite"
8-
"github.com/tailscale/sqlite/sqliteh"
98
)
109

1110
func init() {
1211
Open = cgosqlite.Open
1312
}
1413

15-
// LogCallback receives SQLite log messages.
16-
type LogCallback func(code sqliteh.Code, msg string)
17-
1814
// SetLogCallback sets the global SQLite log callback.
1915
// If callback is nil, logs are discarded.
2016
func SetLogCallback(callback LogCallback) error {

sqlite_nocgo.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//go:build !cgo
2+
// +build !cgo
3+
4+
package sqlite
5+
6+
// SetLogCallback sets the global SQLite log callback.
7+
// If callback is nil, logs are discarded.
8+
func SetLogCallback(callback LogCallback) error {
9+
return nil
10+
}

sqlitepool/queryglue.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build cgo
2+
// +build cgo
3+
14
package sqlitepool
25

36
// This file contains bridging functions designed to let users of

sqlitepool/queryglue_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build cgo
2+
// +build cgo
3+
14
package sqlitepool
25

36
import (

sqlitepool/sqlitepool.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build cgo
2+
// +build cgo
3+
14
// Package sqlitepool implements a pool of SQLite database connections.
25
package sqlitepool
36

sqlitepool/sqlitepool_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build cgo
2+
// +build cgo
3+
14
package sqlitepool
25

36
import (

sqlitepool/util.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build cgo
2+
// +build cgo
3+
14
package sqlitepool
25

36
import (

0 commit comments

Comments
 (0)