chore(deps): Update sqlite dependencies
This commit is contained in:
176
vendor/modernc.org/sqlite/generator.go
generated
vendored
176
vendor/modernc.org/sqlite/generator.go
generated
vendored
@ -10,14 +10,16 @@ package main
|
||||
import (
|
||||
"archive/zip"
|
||||
"bufio"
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"modernc.org/ccgo/v3/lib"
|
||||
@ -145,7 +147,7 @@ import (
|
||||
// -lpthread
|
||||
|
||||
const (
|
||||
volatiles = "-volatile=sqlite3_io_error_pending,sqlite3_open_file_count,sqlite3_pager_readdb_count,sqlite3_pager_writedb_count,sqlite3_pager_writej_count,sqlite3_search_count,sqlite3_sort_count,saved_cnt"
|
||||
volatiles = "-volatile=sqlite3_io_error_pending,sqlite3_open_file_count,sqlite3_pager_readdb_count,sqlite3_pager_writedb_count,sqlite3_pager_writej_count,sqlite3_search_count,sqlite3_sort_count,saved_cnt,randomnessPid"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -156,7 +158,7 @@ var (
|
||||
"-DSQLITE_ENABLE_COLUMN_METADATA",
|
||||
"-DSQLITE_ENABLE_FTS5",
|
||||
"-DSQLITE_ENABLE_GEOPOLY",
|
||||
"-DSQLITE_ENABLE_JSON1",
|
||||
"-DSQLITE_ENABLE_MATH_FUNCTIONS",
|
||||
"-DSQLITE_ENABLE_MEMORY_MANAGEMENT",
|
||||
"-DSQLITE_ENABLE_OFFSET_SQL_FUNC",
|
||||
"-DSQLITE_ENABLE_PREUPDATE_HOOK",
|
||||
@ -168,6 +170,7 @@ var (
|
||||
"-DSQLITE_ENABLE_UNLOCK_NOTIFY", // Adds sqlite3_unlock_notify().
|
||||
"-DSQLITE_LIKE_DOESNT_MATCH_BLOBS",
|
||||
"-DSQLITE_MUTEX_APPDEF=1",
|
||||
"-DSQLITE_MUTEX_NOOP",
|
||||
"-DSQLITE_SOUNDEX",
|
||||
"-DSQLITE_THREADSAFE=1",
|
||||
//DONT "-DNDEBUG", // To enable GO_GENERATE=-DSQLITE_DEBUG
|
||||
@ -207,7 +210,7 @@ var (
|
||||
"-DSQLITE_ENABLE_EXPLAIN_COMMENTS",
|
||||
"-DSQLITE_ENABLE_FTS5",
|
||||
"-DSQLITE_ENABLE_GEOPOLY",
|
||||
"-DSQLITE_ENABLE_JSON1",
|
||||
"-DSQLITE_ENABLE_MATH_FUNCTIONS",
|
||||
"-DSQLITE_ENABLE_MEMORY_MANAGEMENT",
|
||||
"-DSQLITE_ENABLE_OFFSET_SQL_FUNC",
|
||||
"-DSQLITE_ENABLE_PREUPDATE_HOOK",
|
||||
@ -218,9 +221,9 @@ var (
|
||||
"-DSQLITE_ENABLE_STAT4",
|
||||
"-DSQLITE_ENABLE_STMTVTAB", // testfixture
|
||||
"-DSQLITE_ENABLE_UNLOCK_NOTIFY", // Adds sqlite3_unlock_notify().
|
||||
"-DSQLITE_HAVE_ZLIB=1", // testfixture
|
||||
"-DSQLITE_LIKE_DOESNT_MATCH_BLOBS",
|
||||
"-DSQLITE_MUTEX_APPDEF=1",
|
||||
"-DSQLITE_MUTEX_NOOP",
|
||||
"-DSQLITE_SOUNDEX",
|
||||
"-DSQLITE_TEMP_STORE=1", // testfixture
|
||||
"-DSQLITE_TEST",
|
||||
@ -252,16 +255,16 @@ var (
|
||||
sz int
|
||||
dev bool
|
||||
}{
|
||||
{sqliteDir, "https://www.sqlite.org/2021/sqlite-amalgamation-3360000.zip", 2457, false},
|
||||
{sqliteSrcDir, "https://www.sqlite.org/2021/sqlite-src-3360000.zip", 12814, false},
|
||||
{sqliteDir, "https://www.sqlite.org/2022/sqlite-amalgamation-3390400.zip", 2457, false},
|
||||
{sqliteSrcDir, "https://www.sqlite.org/2022/sqlite-src-3390400.zip", 12814, false},
|
||||
}
|
||||
|
||||
sqliteDir = filepath.FromSlash("testdata/sqlite-amalgamation-3360000")
|
||||
sqliteSrcDir = filepath.FromSlash("testdata/sqlite-src-3360000")
|
||||
sqliteDir = filepath.FromSlash("testdata/sqlite-amalgamation-3390400")
|
||||
sqliteSrcDir = filepath.FromSlash("testdata/sqlite-src-3390400")
|
||||
)
|
||||
|
||||
func download() {
|
||||
tmp, err := ioutil.TempDir("", "")
|
||||
tmp, err := os.MkdirTemp("", "")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
return
|
||||
@ -371,7 +374,13 @@ func fail(s string, args ...interface{}) {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var (
|
||||
oFullPathComments = flag.Bool("full-path-comments", false, "")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
fmt.Printf("Running on %s/%s.\n", runtime.GOOS, runtime.GOARCH)
|
||||
env := os.Getenv("GO_GENERATE")
|
||||
goarch := runtime.GOARCH
|
||||
goos := runtime.GOOS
|
||||
@ -393,14 +402,27 @@ func main() {
|
||||
}
|
||||
more = append(more, ndebug...)
|
||||
download()
|
||||
// experimental pthreads support currently only on linux/amd64
|
||||
if goos != "linux" || goarch != "amd64" {
|
||||
configProduction = append(configProduction, "-DSQLITE_MUTEX_NOOP")
|
||||
configTest = append(configTest, "-DSQLITE_MUTEX_NOOP")
|
||||
}
|
||||
switch goos {
|
||||
case "linux", "freebsd":
|
||||
case "linux", "freebsd", "openbsd":
|
||||
configProduction = append(configProduction, "-DSQLITE_OS_UNIX=1")
|
||||
case "netbsd":
|
||||
configProduction = append(configProduction, []string{
|
||||
"-DSQLITE_OS_UNIX=1",
|
||||
"-D__libc_cond_broadcast=pthread_cond_broadcast",
|
||||
"-D__libc_cond_destroy=pthread_cond_destroy",
|
||||
"-D__libc_cond_init=pthread_cond_init",
|
||||
"-D__libc_cond_signal=pthread_cond_signal",
|
||||
"-D__libc_cond_wait=pthread_cond_wait",
|
||||
"-D__libc_mutex_destroy=pthread_mutex_destroy",
|
||||
"-D__libc_mutex_init=pthread_mutex_init",
|
||||
"-D__libc_mutex_lock=pthread_mutex_lock",
|
||||
"-D__libc_mutex_trylock=pthread_mutex_trylock",
|
||||
"-D__libc_mutex_unlock=pthread_mutex_unlock",
|
||||
"-D__libc_mutexattr_destroy=pthread_mutexattr_destroy",
|
||||
"-D__libc_mutexattr_init=pthread_mutexattr_init",
|
||||
"-D__libc_mutexattr_settype=pthread_mutexattr_settype",
|
||||
"-D__libc_thr_yield=sched_yield",
|
||||
}...)
|
||||
case "darwin":
|
||||
configProduction = append(configProduction,
|
||||
"-DSQLITE_OS_UNIX=1",
|
||||
@ -447,7 +469,7 @@ func configure(goos, goarch string) {
|
||||
cmd.Run()
|
||||
var args []string
|
||||
switch goos {
|
||||
case "linux", "freebsd":
|
||||
case "linux", "freebsd", "netbsd", "openbsd":
|
||||
// nop
|
||||
case "darwin":
|
||||
args = append(args, "--with-tcl=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Tcl.framework")
|
||||
@ -512,6 +534,7 @@ func makeTestfixture(goos, goarch string, more []string) {
|
||||
"ext/misc/normalize.c",
|
||||
"ext/misc/percentile.c",
|
||||
"ext/misc/prefixes.c",
|
||||
"ext/misc/qpvtab.c",
|
||||
"ext/misc/regexp.c",
|
||||
"ext/misc/remember.c",
|
||||
"ext/misc/series.c",
|
||||
@ -519,8 +542,8 @@ func makeTestfixture(goos, goarch string, more []string) {
|
||||
"ext/misc/totype.c",
|
||||
"ext/misc/unionvtab.c",
|
||||
"ext/misc/wholenumber.c",
|
||||
"ext/misc/zipfile.c",
|
||||
"ext/rbu/test_rbu.c",
|
||||
"ext/rtree/test_rtreedoc.c",
|
||||
"ext/session/test_session.c",
|
||||
"ext/userauth/userauth.c",
|
||||
"src/tclsqlite.c",
|
||||
@ -576,6 +599,34 @@ func makeTestfixture(goos, goarch string, more []string) {
|
||||
}
|
||||
configure(goos, goarch)
|
||||
|
||||
var defines, includes []string
|
||||
switch goos {
|
||||
case "freebsd", "openbsd":
|
||||
includes = []string{"-I/usr/local/include/tcl8.6"}
|
||||
case "linux":
|
||||
includes = []string{"-I/usr/include/tcl8.6"}
|
||||
case "windows":
|
||||
includes = []string{"-I/usr/include/tcl8.6"}
|
||||
case "netbsd":
|
||||
includes = []string{"-I/usr/pkg/include"}
|
||||
defines = []string{
|
||||
"-D__libc_cond_broadcast=pthread_cond_broadcast",
|
||||
"-D__libc_cond_destroy=pthread_cond_destroy",
|
||||
"-D__libc_cond_init=pthread_cond_init",
|
||||
"-D__libc_cond_signal=pthread_cond_signal",
|
||||
"-D__libc_cond_wait=pthread_cond_wait",
|
||||
"-D__libc_mutex_destroy=pthread_mutex_destroy",
|
||||
"-D__libc_mutex_init=pthread_mutex_init",
|
||||
"-D__libc_mutex_lock=pthread_mutex_lock",
|
||||
"-D__libc_mutex_trylock=pthread_mutex_trylock",
|
||||
"-D__libc_mutex_unlock=pthread_mutex_unlock",
|
||||
"-D__libc_mutexattr_destroy=pthread_mutexattr_destroy",
|
||||
"-D__libc_mutexattr_init=pthread_mutexattr_init",
|
||||
"-D__libc_mutexattr_settype=pthread_mutexattr_settype",
|
||||
"-D__libc_thr_yield=sched_yield",
|
||||
}
|
||||
}
|
||||
|
||||
args := join(
|
||||
[]string{
|
||||
"ccgo",
|
||||
@ -584,9 +635,13 @@ func makeTestfixture(goos, goarch string, more []string) {
|
||||
"-DSQLITE_SERVER=1",
|
||||
"-DTCLSH_INIT_PROC=sqlite3TestInit",
|
||||
"-D_HAVE_SQLITE_CONFIG_H",
|
||||
"-I/usr/include/tcl8.6", //TODO should not be hardcoded
|
||||
},
|
||||
defines,
|
||||
includes,
|
||||
[]string{
|
||||
"-export-defines", "",
|
||||
"-export-fields", "F",
|
||||
"-ignore-unsupported-alignment",
|
||||
"-trace-translation-units",
|
||||
volatiles,
|
||||
"-lmodernc.org/sqlite/libtest",
|
||||
@ -603,32 +658,38 @@ func makeTestfixture(goos, goarch string, more []string) {
|
||||
fmt.Sprintf("-I%s", sqliteDir),
|
||||
fmt.Sprintf("-I%s", sqliteSrcDir),
|
||||
},
|
||||
otherOpts(),
|
||||
files,
|
||||
more,
|
||||
configTest,
|
||||
)
|
||||
// experimental pthreads support currently only on linux/amd64
|
||||
if goos != "linux" || goarch != "amd64" {
|
||||
args = append(args, "-lmodernc.org/sqlite/internal/libc2")
|
||||
}
|
||||
task := ccgo.NewTask(args, nil, nil)
|
||||
if err := task.Main(); err != nil {
|
||||
fail("%s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func otherOpts() (r []string) {
|
||||
if *oFullPathComments {
|
||||
r = append(r, "-full-path-comments")
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func makeSpeedTest(goos, goarch string, more []string) {
|
||||
task := ccgo.NewTask(
|
||||
join(
|
||||
[]string{
|
||||
"ccgo",
|
||||
"-export-defines", "",
|
||||
"-ignore-unsupported-alignment",
|
||||
"-o", filepath.FromSlash(fmt.Sprintf("speedtest1/main_%s_%s.go", goos, goarch)),
|
||||
"-trace-translation-units",
|
||||
filepath.Join(sqliteSrcDir, "test", "speedtest1.c"),
|
||||
fmt.Sprintf("-I%s", sqliteDir),
|
||||
"-l", "modernc.org/sqlite/lib",
|
||||
},
|
||||
otherOpts(),
|
||||
more,
|
||||
configProduction,
|
||||
),
|
||||
@ -646,12 +707,15 @@ func makeMpTest(goos, goarch string, more []string) {
|
||||
[]string{
|
||||
"ccgo",
|
||||
"-export-defines", "",
|
||||
"-ignore-unsupported-alignment",
|
||||
"-o", filepath.FromSlash(fmt.Sprintf("internal/mptest/main_%s_%s.go", goos, goarch)),
|
||||
"-trace-translation-units",
|
||||
filepath.Join(sqliteSrcDir, "mptest", "mptest.c"),
|
||||
// filepath.Join(sqliteSrcDir, "mptest", "mptest.c"),
|
||||
filepath.Join("testdata", "mptest.c"),
|
||||
fmt.Sprintf("-I%s", sqliteDir),
|
||||
"-l", "modernc.org/sqlite/lib",
|
||||
},
|
||||
otherOpts(),
|
||||
more,
|
||||
configProduction,
|
||||
),
|
||||
@ -664,6 +728,7 @@ func makeMpTest(goos, goarch string, more []string) {
|
||||
}
|
||||
|
||||
func makeSqliteProduction(goos, goarch string, more []string) {
|
||||
fn := filepath.FromSlash(fmt.Sprintf("lib/sqlite_%s_%s.go", goos, goarch))
|
||||
task := ccgo.NewTask(
|
||||
join(
|
||||
[]string{
|
||||
@ -674,11 +739,14 @@ func makeSqliteProduction(goos, goarch string, more []string) {
|
||||
"-export-externs", "X",
|
||||
"-export-fields", "F",
|
||||
"-export-typedefs", "",
|
||||
"-ignore-unsupported-alignment",
|
||||
"-pkgname", "sqlite3",
|
||||
"-o", filepath.FromSlash(fmt.Sprintf("lib/sqlite_%s_%s.go", goos, goarch)),
|
||||
volatiles,
|
||||
"-o", fn,
|
||||
"-trace-translation-units",
|
||||
filepath.Join(sqliteDir, "sqlite3.c"),
|
||||
},
|
||||
otherOpts(),
|
||||
more,
|
||||
configProduction,
|
||||
),
|
||||
@ -688,9 +756,14 @@ func makeSqliteProduction(goos, goarch string, more []string) {
|
||||
if err := task.Main(); err != nil {
|
||||
fail("%s\n", err)
|
||||
}
|
||||
|
||||
if err := patchXsqlite3_initialize(fn); err != nil {
|
||||
fail("%s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func makeSqliteTest(goos, goarch string, more []string) {
|
||||
fn := filepath.FromSlash(fmt.Sprintf("libtest/sqlite_%s_%s.go", goos, goarch))
|
||||
task := ccgo.NewTask(
|
||||
join(
|
||||
[]string{
|
||||
@ -701,12 +774,15 @@ func makeSqliteTest(goos, goarch string, more []string) {
|
||||
"-export-externs", "X",
|
||||
"-export-fields", "F",
|
||||
"-export-typedefs", "",
|
||||
"-ignore-unsupported-alignment",
|
||||
"-pkgname", "sqlite3",
|
||||
"-o", filepath.FromSlash(fmt.Sprintf("libtest/sqlite_%s_%s.go", goos, goarch)),
|
||||
volatiles,
|
||||
"-o", fn,
|
||||
"-trace-translation-units",
|
||||
volatiles,
|
||||
filepath.Join(sqliteDir, "sqlite3.c"),
|
||||
},
|
||||
otherOpts(),
|
||||
more,
|
||||
configTest,
|
||||
),
|
||||
@ -716,6 +792,10 @@ func makeSqliteTest(goos, goarch string, more []string) {
|
||||
if err := task.Main(); err != nil {
|
||||
fail("%s\n", err)
|
||||
}
|
||||
|
||||
if err := patchXsqlite3_initialize(fn); err != nil {
|
||||
fail("%s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func join(a ...[]string) (r []string) {
|
||||
@ -729,3 +809,47 @@ func join(a ...[]string) (r []string) {
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func patchXsqlite3_initialize(fn string) error {
|
||||
const s = "func Xsqlite3_initialize(tls *libc.TLS) int32 {"
|
||||
return patch(fn, func(b []byte) []diff {
|
||||
x := bytes.Index(b, []byte(s))
|
||||
return []diff{{x, x + len(s), `
|
||||
var mu mutex
|
||||
|
||||
func init() { mu.recursive = true }
|
||||
|
||||
func Xsqlite3_initialize(tls *libc.TLS) int32 {
|
||||
mu.enter(tls.ID)
|
||||
defer mu.leave(tls.ID)
|
||||
|
||||
`}}
|
||||
})
|
||||
}
|
||||
|
||||
type diff struct {
|
||||
from, to int // byte offsets
|
||||
replace string // replaces b[from:to]
|
||||
}
|
||||
|
||||
func patch(fn string, f func([]byte) []diff) error {
|
||||
b, err := os.ReadFile(fn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
diffs := f(b)
|
||||
sort.Slice(diffs, func(i, j int) bool { return diffs[i].from < diffs[j].from })
|
||||
var patched [][]byte
|
||||
off := 0
|
||||
for _, diff := range diffs {
|
||||
from := diff.from - off
|
||||
to := diff.to - off
|
||||
patched = append(patched, b[:from])
|
||||
patched = append(patched, []byte(diff.replace))
|
||||
b = b[to:]
|
||||
off += to
|
||||
}
|
||||
patched = append(patched, b)
|
||||
return os.WriteFile(fn, bytes.Join(patched, nil), 0660)
|
||||
}
|
||||
|
Reference in New Issue
Block a user