Skip to content

Commit

Permalink
Allow SQLite to use atomic operations. (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncruces authored Jul 11, 2024
1 parent f537ab9 commit 0c7d0a0
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 14 deletions.
4 changes: 2 additions & 2 deletions embed/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ WASI_SDK="$ROOT/tools/wasi-sdk-22.0/bin"
-o sqlite3.wasm "$ROOT/sqlite3/main.c" \
-I"$ROOT/sqlite3" \
-mexec-model=reactor \
-msimd128 -mmutable-globals \
-matomics -msimd128 -mmutable-globals \
-mbulk-memory -mreference-types \
-mnontrapping-fptoint -msign-ext \
-fno-stack-protector -fno-stack-clash-protection \
-Wl,--initial-memory=327680 \
-Wl,--stack-first \
-Wl,--import-undefined \
-Wl,--initial-memory=327680 \
-D_HAVE_SQLITE_CONFIG_H \
-DSQLITE_CUSTOM_INCLUDE=sqlite_opt.h \
$(awk '{print "-Wl,--export="$0}' exports.txt)
Expand Down
Binary file modified embed/sqlite3.wasm
Binary file not shown.
11 changes: 7 additions & 4 deletions sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ncruces/go-sqlite3/vfs"
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/experimental"
)

// Configure SQLite Wasm.
Expand Down Expand Up @@ -44,12 +45,14 @@ var instance struct {
}

func compileSQLite() {
if RuntimeConfig == nil {
RuntimeConfig = wazero.NewRuntimeConfig()
ctx := context.Background()
cfg := RuntimeConfig
if cfg == nil {
cfg = wazero.NewRuntimeConfig()
}

ctx := context.Background()
instance.runtime = wazero.NewRuntimeWithConfig(ctx, RuntimeConfig)
instance.runtime = wazero.NewRuntimeWithConfig(ctx,
cfg.WithCoreFeatures(api.CoreFeaturesV2|experimental.CoreFeaturesThreads))

env := instance.runtime.NewHostModuleBuilder("env")
env = vfs.ExportHostFunctions(env)
Expand Down
5 changes: 4 additions & 1 deletion vfs/tests/mptest/mptest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/ncruces/go-sqlite3/vfs/memdb"
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/experimental"
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
)

Expand All @@ -40,7 +41,9 @@ var (

func TestMain(m *testing.M) {
ctx := context.Background()
cfg := wazero.NewRuntimeConfig().WithMemoryLimitPages(1024)
cfg := wazero.NewRuntimeConfig().
WithCoreFeatures(api.CoreFeaturesV2 | experimental.CoreFeaturesThreads).
WithMemoryLimitPages(1024)
rt = wazero.NewRuntimeWithConfig(ctx, cfg)
wasi_snapshot_preview1.MustInstantiate(ctx, rt)

Expand Down
2 changes: 1 addition & 1 deletion vfs/tests/mptest/testdata/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ WASI_SDK="$ROOT/tools/wasi-sdk-22.0/bin"
"$WASI_SDK/clang" --target=wasm32-wasi -std=c23 -flto -g0 -O2 \
-o mptest.wasm main.c \
-I"$ROOT/sqlite3" \
-msimd128 -mmutable-globals \
-matomics -msimd128 -mmutable-globals \
-mbulk-memory -mreference-types \
-mnontrapping-fptoint -msign-ext \
-fno-stack-protector -fno-stack-clash-protection \
Expand Down
4 changes: 2 additions & 2 deletions vfs/tests/mptest/testdata/mptest.wasm.bz2
Git LFS file not shown
6 changes: 5 additions & 1 deletion vfs/tests/speedtest1/speedtest1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
_ "embed"

"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/experimental"
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"

"github.com/ncruces/go-sqlite3/internal/util"
Expand All @@ -39,7 +41,9 @@ func TestMain(m *testing.M) {
initFlags()

ctx := context.Background()
rt = wazero.NewRuntime(ctx)
cfg := wazero.NewRuntimeConfig().
WithCoreFeatures(api.CoreFeaturesV2 | experimental.CoreFeaturesThreads)
rt = wazero.NewRuntimeWithConfig(ctx, cfg)
wasi_snapshot_preview1.MustInstantiate(ctx, rt)
env := vfs.ExportHostFunctions(rt.NewHostModuleBuilder("env"))
_, err := env.Instantiate(ctx)
Expand Down
2 changes: 1 addition & 1 deletion vfs/tests/speedtest1/testdata/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ WASI_SDK="$ROOT/tools/wasi-sdk-22.0/bin"
"$WASI_SDK/clang" --target=wasm32-wasi -std=c23 -flto -g0 -O2 \
-o speedtest1.wasm main.c \
-I"$ROOT/sqlite3" \
-msimd128 -mmutable-globals \
-matomics -msimd128 -mmutable-globals \
-mbulk-memory -mreference-types \
-mnontrapping-fptoint -msign-ext \
-fno-stack-protector -fno-stack-clash-protection \
Expand Down
4 changes: 2 additions & 2 deletions vfs/tests/speedtest1/testdata/speedtest1.wasm.bz2
Git LFS file not shown

0 comments on commit 0c7d0a0

Please sign in to comment.