Skip to content

Commit 1f1c4ac

Browse files
committed
Emscripten SIDE_MODULE config and scripts.
1 parent aa09d5d commit 1f1c4ac

File tree

4 files changed

+42
-21
lines changed

4 files changed

+42
-21
lines changed

Cargo.toml

+3-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ lto = true
1919

2020
[profile.wasm]
2121
inherits = "release"
22-
# Enabling LTO in WASM build gives:
23-
# warning: Linking globals named '__rust_alloc_error_handler': symbol multiply defined!
24-
# error: failed to load bitcode of module "sgnxivc9sns8d6t":
25-
lto = false
22+
23+
[profile.wasm_asyncify]
24+
inherits = "wasm"
2625

2726
[workspace.package]
2827
version = "0.3.0"

crates/loadable/src/lib.rs

-17
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,10 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
3131
#[lang = "eh_personality"]
3232
extern "C" fn eh_personality() {}
3333

34-
#[cfg(target_family = "wasm")]
35-
#[no_mangle]
36-
pub fn __rust_alloc_error_handler(_: core::alloc::Layout) -> ! {
37-
core::intrinsics::abort()
38-
}
39-
40-
#[cfg(target_family = "wasm")]
41-
#[no_mangle]
42-
static __rust_alloc_error_handler_should_panic: u8 = 0;
43-
4434
#[cfg(target_family = "wasm")]
4535
#[no_mangle]
4636
static _CLOCK_PROCESS_CPUTIME_ID: i32 = 1;
4737

4838
#[cfg(target_family = "wasm")]
4939
#[no_mangle]
5040
static _CLOCK_THREAD_CPUTIME_ID: i32 = 1;
51-
52-
// Not used, but must be defined in some cases. Most notably when using native sqlite3 and loading
53-
// the extension.
54-
// #[allow(non_upper_case_globals)]
55-
// #[no_mangle]
56-
// pub static mut _Unwind_Resume: *mut core::ffi::c_void = core::ptr::null_mut();
57-

tool/build_wasm.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Normal build
5+
# target/wasm32-unknown-emscripten/wasm/powersync.wasm
6+
RUSTFLAGS="-C link-arg=-sSIDE_MODULE=2" \
7+
cargo build \
8+
-p powersync_loadable \
9+
--profile wasm \
10+
--no-default-features \
11+
--features "powersync_core/static powersync_core/omit_load_extension sqlite_nostd/omit_load_extension" \
12+
-Z build-std=panic_abort,core,alloc \
13+
--target wasm32-unknown-emscripten
14+
15+
16+
# Asyncify
17+
# target/wasm32-unknown-emscripten/wasm_asyncify/powersync.wasm
18+
RUSTFLAGS="-C link-arg=-sSIDE_MODULE=2 -C link-arg=-sASYNCIFY=1 -C link-arg=-sJSPI_IMPORTS=@wasm/asyncify_imports.json" \
19+
cargo build \
20+
-p powersync_loadable \
21+
--profile wasm_asyncify \
22+
--no-default-features \
23+
--features "powersync_core/static powersync_core/omit_load_extension sqlite_nostd/omit_load_extension" \
24+
-Z build-std=panic_abort,core,alloc \
25+
--target wasm32-unknown-emscripten

wasm/asyncify_imports.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
"sqlite3_close",
3+
"sqlite3_finalize",
4+
"sqlite3_open_v2",
5+
"sqlite3_prepare",
6+
"sqlite3_prepare16",
7+
"sqlite3_prepare_v2",
8+
"sqlite3_prepare16_v2",
9+
"sqlite3_prepare_v3",
10+
"sqlite3_prepare16_v3",
11+
"sqlite3_reset",
12+
"sqlite3_step",
13+
"sqlite3_exec"
14+
]

0 commit comments

Comments
 (0)