Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@ EXTENSION_FUNCTIONS = extension-functions.c
EXTENSION_FUNCTIONS_URL = https://www.sqlite.org/contrib/download/extension-functions.c?get=25
EXTENSION_FUNCTIONS_SHA3 = ee39ddf5eaa21e1d0ebcbceeab42822dd0c4f82d8039ce173fd4814807faabfa

# sqlite-better-trigram extension
# https://github.com/streetwriters/sqlite-better-trigram
EXTENSION_BETTER_TRIGRAM=better-trigram.c
EXTENSION_BETTER_TRIGRAM_VERSION=0.0.3
EXTENSION_BETTER_TRIGRAM_DIR=sqlite-better-trigram-v${EXTENSION_BETTER_TRIGRAM_VERSION}
EXTENSION_BETTER_TRIGRAM_URL=https://github.com/streetwriters/sqlite-better-trigram/archive/refs/tags/v${EXTENSION_BETTER_TRIGRAM_VERSION}.tar.gz

# source files
CFILES = \
sqlite3.c \
extension-functions.c \
main.c \
libauthorizer.c \
libfunction.c \
libhook.c \
libprogress.c \
libvfs.c \
${EXTENSION_FUNCTIONS} \
${EXTENSION_BETTER_TRIGRAM} \
$(CFILES_EXTRA)

JSFILES = \
Expand All @@ -28,6 +36,7 @@ JSFILES = \
vpath %.c src
vpath %.c deps
vpath %.c deps/$(SQLITE_VERSION)
vpath %.c deps/$(EXTENSION_BETTER_TRIGRAM_DIR)

EXPORTED_FUNCTIONS = src/exported_functions.json
EXPORTED_RUNTIME_METHODS = src/extra_exported_runtime_methods.json
Expand All @@ -43,6 +52,7 @@ EMCC ?= emcc

CFLAGS_COMMON = \
-I'deps/$(SQLITE_VERSION)' \
-I'cache/$(SQLITE_VERSION)/ext/fts5' \
-Wno-non-literal-null-conversion \
$(CFLAGS_EXTRA)
CFLAGS_DEBUG = -g $(CFLAGS_COMMON)
Expand Down Expand Up @@ -152,6 +162,10 @@ deps/$(EXTENSION_FUNCTIONS): cache/$(EXTENSION_FUNCTIONS)
rm -rf deps/sha3 $@
cp 'cache/$(EXTENSION_FUNCTIONS)' $@

deps/${EXTENSION_BETTER_TRIGRAM_DIR}/better-trigram.h deps/${EXTENSION_BETTER_TRIGRAM_DIR}/better-trigram.c:
mkdir -p deps/${EXTENSION_BETTER_TRIGRAM_DIR}
curl -LsS ${EXTENSION_BETTER_TRIGRAM_URL} | tar -xzf - -C deps/${EXTENSION_BETTER_TRIGRAM_DIR}/ --strip-components=1

## tmp
.PHONY: clean-tmp
clean-tmp:
Expand All @@ -165,6 +179,13 @@ tmp/obj/dist/%.o: %.c
mkdir -p tmp/obj/dist
$(EMCC) $(CFLAGS_DIST) $(WASQLITE_DEFINES) $^ -c -o $@

tmp/obj/debug/better-trigram.o: deps/${EXTENSION_BETTER_TRIGRAM_DIR}/better-trigram.c
mkdir -p tmp/obj/debug
$(EMCC) $(CFLAGS_DEBUG) $(WASQLITE_DEFINES) $^ -c -o $@

tmp/obj/dist/better-trigram.o: deps/${EXTENSION_BETTER_TRIGRAM_DIR}/better-trigram.c
mkdir -p tmp/obj/dist
$(EMCC) $(CFLAGS_DIST) $(WASQLITE_DEFINES) $^ -c -o $@

## debug
.PHONY: clean-debug
Expand Down
2 changes: 1 addition & 1 deletion dist/wa-sqlite-async.mjs

Large diffs are not rendered by default.

Binary file modified dist/wa-sqlite-async.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/wa-sqlite-jspi.mjs

Large diffs are not rendered by default.

Binary file modified dist/wa-sqlite-jspi.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/wa-sqlite.mjs

Large diffs are not rendered by default.

Binary file modified dist/wa-sqlite.wasm
Binary file not shown.
3 changes: 3 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <emscripten.h>
#include <sqlite3.h>

extern void sqlite3_bettertrigram_init();

// Some SQLite API functions take a pointer to a function that frees
// memory. Although we could add a C binding to a JavaScript function
// that calls sqlite3_free(), it is more efficient to pass the sqlite3_free
Expand All @@ -13,5 +15,6 @@ void* EMSCRIPTEN_KEEPALIVE getSqliteFree() {

int main() {
sqlite3_initialize();
sqlite3_auto_extension(&sqlite3_bettertrigram_init);
return 0;
}
Loading