-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
177 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Build SQLite3 WASM | ||
|
||
on: | ||
push: | ||
branches: ["**"] | ||
|
||
jobs: | ||
compile_sqlite3_wasm: | ||
name: Compile sqlite3 wasm | ||
runs-on: macos-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Homebrew | ||
id: set-up-homebrew | ||
uses: Homebrew/actions/setup-homebrew@master | ||
- name: Install Dart SDK | ||
uses: dart-lang/setup-dart@v1 | ||
- name: Setup macOS build dependencies | ||
run: brew install cmake llvm binaryen wasi-libc wasi-runtimes | ||
- name: Compile sqlite3.wasm on macOS | ||
if: runner.os == 'macOS' | ||
working-directory: packages/sqlite3_wasm_build | ||
run: ./build.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
pnpm-lock.yaml | ||
sqlite3.dart | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
This directory includes tools to build `sqlite3.wasm` files compatible with the | ||
PowerSync Dart SDK. | ||
|
||
This build process is adapted from [`package:sqlite3`][upstream], with patches | ||
applied to link the [PowerSync SQLite extension][core] statically. | ||
|
||
### Working on patches | ||
|
||
To adapt the patches: | ||
|
||
1. Clone `https://github.com/simolus3/sqlite3.dart.git` somewhere. | ||
2. Apply the existing patches to your clone: `git apply patches/*`. | ||
3. Rebase onto a new upstream release if necessary. | ||
4. Obtain a new patchset with `git format-patch upstreamref..HEAD`. | ||
|
||
[upstream]: https://github.com/simolus3/sqlite3.dart/tree/main/sqlite3/assets/wasm | ||
[core]: https://github.com/powersync-ja/powersync-sqlite-core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
SQLITE_VERSION="2.7.2" | ||
POWERSYNC_CORE_VERSION="0.3.9" | ||
SQLITE_PATH="sqlite3.dart" | ||
|
||
if [ -d "$SQLITE_PATH" ]; then | ||
echo "Deleting existing clone" | ||
rm -rf $SQLITE_PATH | ||
fi | ||
|
||
git clone --branch "sqlite3-$SQLITE_VERSION" --depth 1 https://github.com/simolus3/sqlite3.dart.git $SQLITE_PATH | ||
|
||
cd $SQLITE_PATH | ||
git apply ../patches/* | ||
|
||
cd "sqlite3/" | ||
dart pub get # We need the analyzer dependency resolved to extract required symbols | ||
|
||
cmake -Dwasi_sysroot=/opt/homebrew/share/wasi-sysroot \ | ||
-Dclang=/opt/homebrew/opt/llvm/bin/clang\ | ||
-DPOWERSYNC_VERSION="$POWERSYNC_CORE_VERSION" \ | ||
-S assets/wasm -B .dart_tool/sqlite3_build | ||
cmake --build .dart_tool/sqlite3_build/ -t output -j | ||
|
||
cd ../../ | ||
mkdir -p dist | ||
cp $SQLITE_PATH/sqlite3/example/web/*.wasm dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "dart_powersync_wasm", | ||
"version": "0.0.1", | ||
"description": "WebAssembly modules containing SQLite + PowerSync for Dart apps.", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/powersync-ja/powersync.dart.git", | ||
"directory": "packages/sqlite3_wasm_build" | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
packages/sqlite3_wasm_build/patches/0001-Link-PowerSync-core-extension.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
From 04fd5a3a01be7b42ec97c2d9865e4c7501b5b6a8 Mon Sep 17 00:00:00 2001 | ||
From: Simon Binder <[email protected]> | ||
Date: Mon, 27 Jan 2025 15:12:53 +0100 | ||
Subject: [PATCH] Link PowerSync core extension | ||
|
||
--- | ||
sqlite3/assets/wasm/CMakeLists.txt | 7 ++++++- | ||
sqlite3/assets/wasm/os_web.c | 11 ++++++++++- | ||
sqlite3/assets/wasm/sqlite_cfg.h | 2 +- | ||
3 files changed, 17 insertions(+), 3 deletions(-) | ||
|
||
diff --git a/sqlite3/assets/wasm/CMakeLists.txt b/sqlite3/assets/wasm/CMakeLists.txt | ||
index e4283b3..5c52593 100644 | ||
--- a/sqlite3/assets/wasm/CMakeLists.txt | ||
+++ b/sqlite3/assets/wasm/CMakeLists.txt | ||
@@ -6,6 +6,7 @@ project(${PROJECT_NAME} LANGUAGES C) | ||
set(triple wasm32-unknown-wasi) | ||
set(wasi_sysroot "/usr/share/wasi-sysroot" CACHE PATH "Path to wasi sysroot") | ||
set(clang "clang" CACHE FILEPATH "Path to wasm-capable clang executable") | ||
+set(POWERSYNC_VERSION "0.3.9" CACHE STRING "PowerSync core version to use") | ||
|
||
include(FetchContent) | ||
|
||
@@ -27,6 +28,9 @@ FetchContent_MakeAvailable(sqlite3mc) | ||
|
||
file(DOWNLOAD https://raw.githubusercontent.com/sqlite/sqlite/master/src/test_vfstrace.c "${CMAKE_BINARY_DIR}/vfstrace.c") | ||
|
||
+set(POWERSYNC_A "${CMAKE_BINARY_DIR}/libpowersync-wasm.a") | ||
+file(DOWNLOAD "https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v${POWERSYNC_VERSION}/libpowersync-wasm.a" "${POWERSYNC_A}") | ||
+ | ||
# Generate symbols we need to export from the sqlite3.wasm build | ||
add_custom_command( | ||
OUTPUT required_symbols.txt | ||
@@ -88,8 +92,9 @@ macro(base_sqlite3_target name debug crypto) | ||
-Wl,--import-memory | ||
--sysroot ${wasi_sysroot} | ||
${sources} | ||
+ ${POWERSYNC_A} | ||
@${CMAKE_CURRENT_BINARY_DIR}/required_symbols.txt | ||
- DEPENDS ${sources} required_symbols | ||
+ DEPENDS ${sources} ${POWERSYNC_A} required_symbols | ||
VERBATIM | ||
) | ||
|
||
diff --git a/sqlite3/assets/wasm/os_web.c b/sqlite3/assets/wasm/os_web.c | ||
index 04f2e97..666902d 100644 | ||
--- a/sqlite3/assets/wasm/os_web.c | ||
+++ b/sqlite3/assets/wasm/os_web.c | ||
@@ -4,6 +4,15 @@ | ||
|
||
#include "sqlite3.h" | ||
|
||
-int sqlite3_os_init(void) { return SQLITE_OK; } | ||
+extern int sqlite3_powersync_init(sqlite3 *db, char **pzErrMsg, | ||
+ const sqlite3_api_routines *pApi); | ||
+ | ||
+int sqlite3_os_init(void) { | ||
+ int rc = sqlite3_auto_extension((void (*)(void)) & sqlite3_powersync_init); | ||
+ if (rc != SQLITE_OK) { | ||
+ return rc; | ||
+ } | ||
+ return SQLITE_OK; | ||
+} | ||
|
||
int sqlite3_os_end(void) { return SQLITE_OK; } | ||
diff --git a/sqlite3/assets/wasm/sqlite_cfg.h b/sqlite3/assets/wasm/sqlite_cfg.h | ||
index 6f3e3c2..45847f8 100644 | ||
--- a/sqlite3/assets/wasm/sqlite_cfg.h | ||
+++ b/sqlite3/assets/wasm/sqlite_cfg.h | ||
@@ -43,7 +43,7 @@ | ||
// Disable things we don't need | ||
#define SQLITE_OMIT_DEPRECATED | ||
#define SQLITE_OMIT_PROGRESS_CALLBACK | ||
-#define SQLITE_OMIT_AUTHORIZATION | ||
+// #define SQLITE_OMIT_AUTHORIZATION // This breaks the powersync-core build | ||
#define SQLITE_UNTESTABLE | ||
#define SQLITE_OMIT_COMPILEOPTION_DIAGS | ||
#define SQLITE_OMIT_LOAD_EXTENSION | ||
-- | ||
2.39.5 (Apple Git-154) | ||
|