Skip to content

Commit 8d0c654

Browse files
committed
Cross compilation.
1 parent 728e599 commit 8d0c654

22 files changed

+222
-181
lines changed

.github/workflows/bsd.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: BSD
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
test:
8+
runs-on: macos-12
9+
10+
steps:
11+
- uses: actions/checkout@v3
12+
with:
13+
lfs: 'true'
14+
15+
- name: Set up
16+
uses: actions/setup-go@v4
17+
with:
18+
go-version: stable
19+
20+
- name: Build
21+
run: GOOS=freebsd go test -c ./...
22+
23+
- name: Test
24+
uses: cross-platform-actions/[email protected]
25+
with:
26+
operating_system: freebsd
27+
version: '13.2'
28+
run: find . -name '*.test' -maxdepth 1 -exec {} -test.v \;

.github/workflows/cross.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
echo android ; GOOS=android GOARCH=amd64 go build .
4+
echo darwin ; GOOS=darwin GOARCH=amd64 go build .
5+
echo dragonfly ; GOOS=dragonfly GOARCH=amd64 go build .
6+
echo freebsd ; GOOS=freebsd GOARCH=amd64 go build .
7+
echo illumos ; GOOS=illumos GOARCH=amd64 go build .
8+
echo ios ; GOOS=ios GOARCH=amd64 go build .
9+
echo linux ; GOOS=linux GOARCH=amd64 go build .
10+
echo netbsd ; GOOS=netbsd GOARCH=amd64 go build .
11+
echo openbsd ; GOOS=openbsd GOARCH=amd64 go build .
12+
echo plan9 ; GOOS=plan9 GOARCH=amd64 go build .
13+
echo solaris ; GOOS=solaris GOARCH=amd64 go build .
14+
echo windows ; GOOS=windows GOARCH=amd64 go build .
15+
# echo aix ; GOOS=aix GOARCH=ppc64 go build .
16+
echo js ; GOOS=js GOARCH=wasm go build .
17+
echo wasip1 ; GOOS=wasip1 GOARCH=wasm go build .
18+
echo darwin-flock ; GOOS=darwin GOARCH=amd64 go build -tags sqlite3_flock .
19+
echo darwin-nosys ; GOOS=darwin GOARCH=amd64 go build -tags sqlite3_nosys .
20+
echo linux-nosys ; GOOS=linux GOARCH=amd64 go build -tags sqlite3_nosys .
21+
echo windows-nosys ; GOOS=windows GOARCH=amd64 go build -tags sqlite3_nosys .
22+
echo freebsd-nosys ; GOOS=freebsd GOARCH=amd64 go build -tags sqlite3_nosys .

.github/workflows/cross.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Cross compile
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
test:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v3
12+
with:
13+
lfs: 'true'
14+
15+
- name: Set up
16+
uses: actions/setup-go@v4
17+
with:
18+
go-version: stable
19+
20+
- name: Build
21+
run: .github/workflows/cross.sh

.github/workflows/go.yml

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,13 @@ jobs:
4646
- name: Test
4747
run: go test -v ./...
4848

49+
- name: Test no locks
50+
run: go test -v -tags sqlite3_nosys ./tests -run TestDB_nolock
51+
4952
- name: Test BSD locks
5053
run: go test -v -tags sqlite3_flock ./...
5154
if: matrix.os == 'macos-latest'
5255

53-
- name: Build FreeBSD tests
54-
run: GOOS=freebsd go test -c ./...
55-
if: matrix.os == 'macos-latest'
56-
57-
- name: Run FreeBSD tests in a xHyve VM
58-
uses: cross-platform-actions/action@master
59-
with:
60-
operating_system: freebsd
61-
version: '13.2'
62-
run: |
63-
find . -name '*.test' -maxdepth 1 -exec {} -test.v \;
64-
if: matrix.os == 'macos-latest'
65-
66-
- name: Test no locks
67-
run: go test -v -tags sqlite3_nolock .
68-
if: matrix.os == 'ubuntu-latest'
69-
7056
- name: Coverage report
7157
uses: ncruces/go-coverage-report@v0
7258
with:
@@ -76,4 +62,3 @@ jobs:
7662
if: |
7763
github.event_name == 'push' &&
7864
matrix.os == 'ubuntu-latest'
79-
continue-on-error: true

README.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,35 +47,31 @@ to use the [`database/sql`](https://pkg.go.dev/database/sql)
4747
driver with WAL mode databases you should disable connection pooling by calling
4848
[`db.SetMaxOpenConns(1)`](https://pkg.go.dev/database/sql#DB.SetMaxOpenConns).
4949

50-
#### POSIX Advisory Locks
50+
#### File Locking
5151

52-
POSIX advisory locks, which SQLite uses, are
52+
POSIX advisory locks, which SQLite uses on Unix, are
5353
[broken by design](https://www.sqlite.org/src/artifact/2e8b12?ln=1073-1161).
5454

5555
On Linux, macOS and illumos, this module uses
5656
[OFD locks](https://www.gnu.org/software/libc/manual/html_node/Open-File-Description-Locks.html)
5757
to synchronize access to database files.
58-
OFD locks are fully compatible with process-associated POSIX advisory locks.
58+
OFD locks are fully compatible with POSIX advisory locks.
5959

6060
On BSD Unixes, this module uses
6161
[BSD locks](https://man.freebsd.org/cgi/man.cgi?query=flock&sektion=2).
62-
On BSD Unixes, BSD locks _should_ be compatible with process-associated POSIX advisory locks.
62+
On BSD Unixes, BSD locks are fully compatible with POSIX advisory locks.
6363

64-
##### TL;DR
64+
On Windows, this module uses `LockFile`, `LockFileEx`, and `UnlockFile`, like SQLite.
6565

66-
In all platforms for which this package builds out of the box,
67-
it should be safe to use it to access databases concurrently,
68-
from multiple goroutines, processes, and
69-
with _other_ implementations of SQLite.
70-
71-
If the package does not build for your platform,
72-
see [this](vfs/README.md#portability).
66+
On all other platforms, file locking is not supported, and you must use
67+
[`nolock=1`](https://www.sqlite.org/uri.html#urinolock)
68+
to open database files.
7369

7470
#### Testing
7571

7672
The pure Go VFS is tested by running SQLite's
7773
[mptest](https://github.com/sqlite/sqlite/blob/master/mptest/mptest.c)
78-
on Linux, macOS and Windows.
74+
on Linux, macOS, Windows and FreeBSD.
7975
Performance is tested by running
8076
[speedtest1](https://github.com/sqlite/sqlite/blob/master/test/speedtest1.c).
8177

tests/db_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ func TestDB_file(t *testing.T) {
2525
testDB(t, filepath.Join(t.TempDir(), "test.db"))
2626
}
2727

28+
func TestDB_nolock(t *testing.T) {
29+
t.Parallel()
30+
testDB(t, "file:"+
31+
filepath.ToSlash(filepath.Join(t.TempDir(), "test.db"))+
32+
"?nolock=1")
33+
}
34+
2835
func TestDB_wal(t *testing.T) {
2936
t.Parallel()
3037
wal := filepath.Join(t.TempDir(), "test.db")

vfs/README.md

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,4 @@ This package implements the SQLite [OS Interface](https://www.sqlite.org/vfs.htm
44

55
It replaces the default SQLite VFS with a pure Go implementation.
66

7-
It also exposes interfaces that should allow you to implement your own custom VFSes.
8-
9-
## Portability
10-
11-
This package is continuously tested on Linux, macOS and Windows,
12-
but it should also work on BSD Unixes and illumos
13-
(code paths for those plaforms are tested on macOS and Linux, respectively).
14-
15-
In all platforms for which this package builds out of the box,
16-
it should be safe to use it to access databases concurrently,
17-
from multiple goroutines, processes, and
18-
with _other_ implementations of SQLite.
19-
20-
If the package does not build for your platform,
21-
you may try to use the `sqlite3_flock` or `sqlite3_nolock` build tags.
22-
23-
The `sqlite3_flock` tag uses
24-
[BSD locks](https://man.freebsd.org/cgi/man.cgi?query=flock&sektion=2).
25-
It should be safe to access databases concurrently from multiple goroutines and processes,
26-
but **not** with _other_ implementations of SQLite
27-
(_unless_ these are _also_ configured to use `flock`).
28-
29-
The `sqlite3_nolock` tag uses no locking at all.
30-
Database corruption is the likely result from concurrent write access.
7+
It also exposes interfaces that should allow you to implement your own custom VFSes.

vfs/lock.go

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
//go:build !sqlite3_nolock
2-
31
package vfs
42

5-
import (
6-
"os"
7-
8-
"github.com/ncruces/go-sqlite3/internal/util"
9-
)
3+
import "github.com/ncruces/go-sqlite3/internal/util"
104

115
const (
126
_PENDING_BYTE = 0x40000000
@@ -134,18 +128,3 @@ func (f *vfsFile) CheckReservedLock() (bool, error) {
134128
}
135129
return osCheckReservedLock(f.File)
136130
}
137-
138-
func osGetReservedLock(file *os.File) _ErrorCode {
139-
// Acquire the RESERVED lock.
140-
return osWriteLock(file, _RESERVED_BYTE, 1, 0)
141-
}
142-
143-
func osGetPendingLock(file *os.File) _ErrorCode {
144-
// Acquire the PENDING lock.
145-
return osWriteLock(file, _PENDING_BYTE, 1, 0)
146-
}
147-
148-
func osCheckReservedLock(file *os.File) (bool, _ErrorCode) {
149-
// Test the RESERVED lock.
150-
return osCheckLock(file, _RESERVED_BYTE, 1)
151-
}

vfs/nolock.go

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

vfs/os_bsd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build (freebsd || openbsd || netbsd || dragonfly || sqlite3_flock) && !sqlite3_nolock
1+
//go:build (freebsd || openbsd || netbsd || dragonfly || sqlite3_flock) && !sqlite3_nosys
22

33
package vfs
44

0 commit comments

Comments
 (0)