Files
sqlite3/compile.go

48 lines
701 B
Go
Raw Normal View History

2023-01-12 13:43:35 +00:00
package sqlite3
import (
"context"
"os"
"sync"
"sync/atomic"
"github.com/tetratelabs/wazero"
)
// Configure SQLite.
var (
Binary []byte // Binary to load.
Path string // Path to load the binary from.
)
var (
once sync.Once
wasm wazero.Runtime
module wazero.CompiledModule
counter atomic.Uint64
)
func compile() {
ctx := context.Background()
wasm = wazero.NewRuntime(ctx)
2023-01-18 01:30:11 +00:00
if err := vfsInstantiate(ctx, wasm); err != nil {
panic(err)
}
2023-01-12 13:43:35 +00:00
if Binary == nil && Path != "" {
if bin, err := os.ReadFile(Path); err != nil {
panic(err)
} else {
Binary = bin
}
}
if m, err := wasm.CompileModule(ctx, Binary); err != nil {
panic(err)
} else {
module = m
}
}