forked from rhashimoto/wa-sqlite
-
Notifications
You must be signed in to change notification settings - Fork 4
[POC] Dynamic Extension Loading #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Conversation
This file contains hidden or 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
I got asyncify builds working using this command: rm -f "target/wasm32-unknown-emscripten/wasm/deps/*" && RUSTFLAGS="--emit=llvm-bc -C linker=/usr/bin/true" cargo build -p powersync_loadable --profile wasm --no-default-features --features "powersync_core/static powersync_core/omit_load_extension sqlite_nostd/omit_load_extension" -Z build-std=panic_abort,core,alloc --target wasm32-unknown-emscripten && sh -c "cd target/wasm32-unknown-emscripten/wasm/deps && emcc -g *.bc ../../../../shim.bc -o ~/src/wa-sqlite/debug/side_module_async.wasm -sSIDE_MODULE -sASYNCIFY -sJSPI_IMPORTS=@../../../../asyncify_imports.json" asyncify_imports.json: [
"sqlite3_close",
"sqlite3_finalize",
"sqlite3_open_v2",
"sqlite3_prepare",
"sqlite3_prepare16",
"sqlite3_prepare_v2",
"sqlite3_prepare16_v2",
"sqlite3_prepare_v3",
"sqlite3_prepare16_v3",
"sqlite3_reset",
"sqlite3_step",
"sqlite3_exec"
] |
Superseded by #19 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This is a (rough) POC for loading our Rust SQLite extension dynamically instead of statically linking via a Git submodule.
This compiles WA-SQLite as a
MAIN_MODULE
which can dynamically link toSIDE_MODULE
s. JS functions to enable loading of extensions and load extension binaries are added. Currently this modifies the main dist exports to support side modules. It should be possible to add an additional dist export, along side the existing exports, which enables modules.This has been tested with the in synchronous build and in-memory filesystem. Currently the async build fails to bind to the
sqlite_load_extension
call. This needs additional investigation.The call to
sqlite3_load_extension
currently makes a network request for the extension binary. This binary has been placed in thedist
folder where it can be served for demos. This behaviour might change when other VFS's are used.Our Rust SQLite extension was compiled by running
Then in the
/target/wasm32-unknown-emscripten/release/deps
directory the bytecode was linked to a binary withemcc *.bc [path_to_shim].o -o side_module.wasm -s SIDE_MODULE
A shim was included to introduce functionality for
Since this seems to not be resolveable. Improving this requires additional investigation.
The demo can be started with

yarn start
. See the screenshot below for results: