Build using wasi-sdk.

This commit is contained in:
Nuno Cruces
2023-04-14 00:09:40 +01:00
parent 005b15610a
commit c1a640f7d8
15 changed files with 71 additions and 47 deletions

View File

@@ -55,7 +55,7 @@ jobs:
if: matrix.os == 'macos-latest'
- name: Coverage report
uses: ncruces/go-coverage-report@main
uses: ncruces/go-coverage-report@v0
with:
chart: 'true'
amend: 'true'

View File

@@ -19,4 +19,5 @@ The following optional features are compiled in:
See the [configuration options](../sqlite3/sqlite_cfg.h).
Built using [`zig`](https://ziglang.org/) version 0.10.1.
Built using [`wasi-sdk`](https://github.com/WebAssembly/wasi-sdk),
and [`binaryen`](https://github.com/WebAssembly/binaryen).

View File

@@ -1,18 +1,28 @@
#!/usr/bin/env bash
set -eo pipefail
set -euo pipefail
cd -P -- "$(dirname -- "$0")"
zig cc --target=wasm32-wasi -flto -g0 -O2 \
-o sqlite3.wasm ../sqlite3/main.c \
-I../sqlite3/ \
ROOT=../
BINARYEN="$ROOT/tools/binaryen-version_112/bin"
WASI_SDK="$ROOT/tools/wasi-sdk-20.0/bin"
"$WASI_SDK/clang" --target=wasm32-wasi -flto -g0 -O2 \
-o sqlite3.wasm "$ROOT/sqlite3/main.c" \
-I"$ROOT/sqlite3" \
-mexec-model=reactor \
-mmutable-globals \
-mbulk-memory -mreference-types \
-mnontrapping-fptoint -msign-ext \
-mexec-model=reactor \
-Wl,--initial-memory=327680 \
-Wl,--stack-first \
-Wl,--import-undefined \
-D_HAVE_SQLITE_CONFIG_H \
$(awk '{print "-Wl,--export="$0}' exports.txt)
trap 'rm -f sqlite3.tmp' EXIT
wasm-ctor-eval -g -c _initialize sqlite3.wasm -o sqlite3.tmp
wasm-opt -g -O2 sqlite3.tmp -o sqlite3.wasm
"$BINARYEN/wasm-ctor-eval" -g -c _initialize sqlite3.wasm -o sqlite3.tmp
"$BINARYEN/wasm-opt" -g -O2 sqlite3.tmp -o sqlite3.wasm \
--enable-multivalue --enable-mutable-globals \
--enable-bulk-memory --enable-reference-types \
--enable-nontrapping-float-to-int --enable-sign-ext

Binary file not shown.

View File

@@ -1,17 +1,29 @@
#!/usr/bin/env bash
set -eo pipefail
set -euo pipefail
cd -P -- "$(dirname -- "$0")"
zig cc --target=wasm32-wasi -flto -g0 -O2 \
ROOT=../../../../../
BINARYEN="$ROOT/tools/binaryen-version_112/bin"
WASI_SDK="$ROOT/tools/wasi-sdk-20.0/bin"
"$WASI_SDK/clang" --target=wasm32-wasi -flto -g0 -O2 \
-o mptest.wasm main.c \
-I../../../../../sqlite3/ \
-I"$ROOT/sqlite3" \
-mmutable-globals \
-mbulk-memory -mreference-types \
-mnontrapping-fptoint -msign-ext \
-Wl,--stack-first \
-Wl,--import-undefined \
-D_HAVE_SQLITE_CONFIG_H \
-DSQLITE_DEFAULT_SYNCHRONOUS=0 \
-DSQLITE_DEFAULT_LOCKING_MODE=0 \
-DHAVE_USLEEP -DSQLITE_NO_SYNC \
-DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION \
-D_WASI_EMULATED_GETPID -lwasi-emulated-getpid
-D_WASI_EMULATED_GETPID -lwasi-emulated-getpid
"$BINARYEN/wasm-opt" -g -O2 mptest.wasm -o mptest.tmp \
--enable-multivalue --enable-mutable-globals \
--enable-bulk-memory --enable-reference-types \
--enable-nontrapping-float-to-int --enable-sign-ext
mv mptest.tmp mptest.wasm

View File

@@ -4,7 +4,6 @@
#include "sqlite3.c"
//
#include "os.c"
#include "qsort.c"
sqlite3_destructor_type malloc_destructor = &free;
size_t sqlite3_interrupt_offset = offsetof(sqlite3, u1.isInterrupted);

4
internal/vfs/tests/mptest/testdata/mptest.wasm vendored Executable file → Normal file
View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:21efc4fb06ac7a3316634f438c51b66c93b1e75b70a850eb3acd6ff8c1c64b3d
size 1630624
oid sha256:37ceeed293b9f09e9770b40eda3f625447f5a3a74208709886d4411d12f93414
size 1486113

View File

@@ -1,12 +1,24 @@
#!/usr/bin/env bash
set -eo pipefail
set -euo pipefail
cd -P -- "$(dirname -- "$0")"
zig cc --target=wasm32-wasi -flto -g0 -O2 \
-o speedtest1.wasm main.c \
-I../../../../../sqlite3/ \
ROOT=../../../../../
BINARYEN="$ROOT/tools/binaryen-version_112/bin"
WASI_SDK="$ROOT/tools/wasi-sdk-20.0/bin"
"$WASI_SDK/clang" --target=wasm32-wasi -flto -g0 -O2 \
-o speedtest1.wasm main.c \
-I"$ROOT/sqlite3" \
-mmutable-globals \
-mbulk-memory -mreference-types \
-mnontrapping-fptoint -msign-ext \
-D_HAVE_SQLITE_CONFIG_H
-Wl,--stack-first \
-Wl,--import-undefined \
-D_HAVE_SQLITE_CONFIG_H
"$BINARYEN/wasm-opt" -g -O2 speedtest1.wasm -o speedtest1.tmp \
--enable-multivalue --enable-mutable-globals \
--enable-bulk-memory --enable-reference-types \
--enable-nontrapping-float-to-int --enable-sign-ext
mv speedtest1.tmp speedtest1.wasm

View File

@@ -4,7 +4,6 @@
#include "sqlite3.c"
//
#include "os.c"
#include "qsort.c"
sqlite3_destructor_type malloc_destructor = &free;
size_t sqlite3_interrupt_offset = offsetof(sqlite3, u1.isInterrupted);

4
internal/vfs/tests/speedtest1/testdata/speedtest1.wasm vendored Executable file → Normal file
View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b3ce4ed200234ac50126a5562fd95a84843898e73e0724687153f9ae458b8a3b
size 1675943
oid sha256:8167119c344a68217b0301e2e8c288f2e75611d296d7822f841b65911da0275c
size 1520569

View File

@@ -49,14 +49,18 @@ func TestConn_new(t *testing.T) {
}
defer m.close()
testOOM := func(size uint64) {
t.Run("MaxUint32", func(t *testing.T) {
defer func() { _ = recover() }()
m.new(size)
m.new(math.MaxUint32)
t.Error("want panic")
}
})
testOOM(math.MaxUint32)
testOOM(_MAX_ALLOCATION_SIZE)
t.Run("_MAX_ALLOCATION_SIZE", func(t *testing.T) {
defer func() { _ = recover() }()
m.new(_MAX_ALLOCATION_SIZE)
m.new(_MAX_ALLOCATION_SIZE)
t.Error("want panic")
})
}
func TestConn_newArena(t *testing.T) {

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env bash
set -eo pipefail
set -euo pipefail
cd -P -- "$(dirname -- "$0")"
@@ -17,7 +17,7 @@ curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.41.2/ext/misc/regexp.c
curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.41.2/ext/misc/series.c"
cd ~-
cd ../tests/mptest/testdata/
cd ../internal/vfs/tests/mptest/testdata/
curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.41.2/mptest/mptest.c"
curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.41.2/mptest/config01.test"
curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.41.2/mptest/config02.test"
@@ -26,6 +26,6 @@ curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.41.2/mptest/crash02.su
curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.41.2/mptest/multiwrite01.test"
cd ~-
cd ../tests/speedtest1/testdata/
cd ../internal/vfs/tests/speedtest1/testdata/
curl -#OL "https://github.com/sqlite/sqlite/raw/version-3.41.2/test/speedtest1.c"
cd ~-

View File

@@ -1,4 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
cd -P -- "$(dirname -- "$0")"
shopt -s extglob

View File

@@ -4,7 +4,6 @@
#include "sqlite3.c"
//
#include "os.c"
#include "qsort.c"
//
#include "ext/base64.c"
#include "ext/decimal.c"

View File

@@ -1,14 +0,0 @@
#include <stddef.h>
void qsort_r(void *, size_t, size_t,
int (*)(const void *, const void *, void *), void *);
typedef int (*cmpfun)(const void *, const void *);
static int wrapper_cmp(const void *v1, const void *v2, void *cmp) {
return ((cmpfun)cmp)(v1, v2);
}
void qsort(void *base, size_t nel, size_t width, cmpfun cmp) {
qsort_r(base, nel, width, wrapper_cmp, cmp);
}