|
| 1 | +From 04fd5a3a01be7b42ec97c2d9865e4c7501b5b6a8 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Simon Binder <simon@journeyapps.com> |
| 3 | +Date: Mon, 27 Jan 2025 15:12:53 +0100 |
| 4 | +Subject: [PATCH] Link PowerSync core extension |
| 5 | + |
| 6 | +--- |
| 7 | + sqlite3/assets/wasm/CMakeLists.txt | 7 ++++++- |
| 8 | + sqlite3/assets/wasm/os_web.c | 11 ++++++++++- |
| 9 | + sqlite3/assets/wasm/sqlite_cfg.h | 2 +- |
| 10 | + 3 files changed, 17 insertions(+), 3 deletions(-) |
| 11 | + |
| 12 | +diff --git a/sqlite3/assets/wasm/CMakeLists.txt b/sqlite3/assets/wasm/CMakeLists.txt |
| 13 | +index e4283b3..5c52593 100644 |
| 14 | +--- a/sqlite3/assets/wasm/CMakeLists.txt |
| 15 | ++++ b/sqlite3/assets/wasm/CMakeLists.txt |
| 16 | +@@ -6,6 +6,7 @@ project(${PROJECT_NAME} LANGUAGES C) |
| 17 | + set(triple wasm32-unknown-wasi) |
| 18 | + set(wasi_sysroot "/usr/share/wasi-sysroot" CACHE PATH "Path to wasi sysroot") |
| 19 | + set(clang "clang" CACHE FILEPATH "Path to wasm-capable clang executable") |
| 20 | ++set(POWERSYNC_VERSION "0.3.9" CACHE STRING "PowerSync core version to use") |
| 21 | + |
| 22 | + include(FetchContent) |
| 23 | + |
| 24 | +@@ -27,6 +28,9 @@ FetchContent_MakeAvailable(sqlite3mc) |
| 25 | + |
| 26 | + file(DOWNLOAD https://raw.githubusercontent.com/sqlite/sqlite/master/src/test_vfstrace.c "${CMAKE_BINARY_DIR}/vfstrace.c") |
| 27 | + |
| 28 | ++set(POWERSYNC_A "${CMAKE_BINARY_DIR}/libpowersync-wasm.a") |
| 29 | ++file(DOWNLOAD "https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v${POWERSYNC_VERSION}/libpowersync-wasm.a" "${POWERSYNC_A}") |
| 30 | ++ |
| 31 | + # Generate symbols we need to export from the sqlite3.wasm build |
| 32 | + add_custom_command( |
| 33 | + OUTPUT required_symbols.txt |
| 34 | +@@ -88,8 +92,9 @@ macro(base_sqlite3_target name debug crypto) |
| 35 | + -Wl,--import-memory |
| 36 | + --sysroot ${wasi_sysroot} |
| 37 | + ${sources} |
| 38 | ++ ${POWERSYNC_A} |
| 39 | + @${CMAKE_CURRENT_BINARY_DIR}/required_symbols.txt |
| 40 | +- DEPENDS ${sources} required_symbols |
| 41 | ++ DEPENDS ${sources} ${POWERSYNC_A} required_symbols |
| 42 | + VERBATIM |
| 43 | + ) |
| 44 | + |
| 45 | +diff --git a/sqlite3/assets/wasm/os_web.c b/sqlite3/assets/wasm/os_web.c |
| 46 | +index 04f2e97..666902d 100644 |
| 47 | +--- a/sqlite3/assets/wasm/os_web.c |
| 48 | ++++ b/sqlite3/assets/wasm/os_web.c |
| 49 | +@@ -4,6 +4,15 @@ |
| 50 | + |
| 51 | + #include "sqlite3.h" |
| 52 | + |
| 53 | +-int sqlite3_os_init(void) { return SQLITE_OK; } |
| 54 | ++extern int sqlite3_powersync_init(sqlite3 *db, char **pzErrMsg, |
| 55 | ++ const sqlite3_api_routines *pApi); |
| 56 | ++ |
| 57 | ++int sqlite3_os_init(void) { |
| 58 | ++ int rc = sqlite3_auto_extension((void (*)(void)) & sqlite3_powersync_init); |
| 59 | ++ if (rc != SQLITE_OK) { |
| 60 | ++ return rc; |
| 61 | ++ } |
| 62 | ++ return SQLITE_OK; |
| 63 | ++} |
| 64 | + |
| 65 | + int sqlite3_os_end(void) { return SQLITE_OK; } |
| 66 | +diff --git a/sqlite3/assets/wasm/sqlite_cfg.h b/sqlite3/assets/wasm/sqlite_cfg.h |
| 67 | +index 6f3e3c2..45847f8 100644 |
| 68 | +--- a/sqlite3/assets/wasm/sqlite_cfg.h |
| 69 | ++++ b/sqlite3/assets/wasm/sqlite_cfg.h |
| 70 | +@@ -43,7 +43,7 @@ |
| 71 | + // Disable things we don't need |
| 72 | + #define SQLITE_OMIT_DEPRECATED |
| 73 | + #define SQLITE_OMIT_PROGRESS_CALLBACK |
| 74 | +-#define SQLITE_OMIT_AUTHORIZATION |
| 75 | ++// #define SQLITE_OMIT_AUTHORIZATION // This breaks the powersync-core build |
| 76 | + #define SQLITE_UNTESTABLE |
| 77 | + #define SQLITE_OMIT_COMPILEOPTION_DIAGS |
| 78 | + #define SQLITE_OMIT_LOAD_EXTENSION |
| 79 | +-- |
| 80 | +2.39.5 (Apple Git-154) |
| 81 | + |
0 commit comments