Skip to content

Commit 2fa276d

Browse files
committed
Add staticlib crate.
1 parent 372d046 commit 2fa276d

File tree

5 files changed

+75
-0
lines changed

5 files changed

+75
-0
lines changed

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/static/Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "powersync_static"
3+
edition.workspace = true
4+
version.workspace = true
5+
homepage.workspace = true
6+
repository.workspace = true
7+
license.workspace = true
8+
authors.workspace = true
9+
keywords.workspace = true
10+
11+
[lib]
12+
name = "powersync"
13+
crate-type = ["staticlib"]
14+
15+
[dependencies]
16+
sqlite_nostd = { workspace=true }
17+
18+
[dependencies.powersync_core]
19+
path = "../core"
20+
default-features = false
21+
features = []
22+
23+
[features]
24+
default = ["powersync_core/static", "powersync_core/omit_load_extension", "sqlite_nostd/omit_load_extension"]

crates/static/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# powersync_loadable
2+
3+
Builds the loadable extension as a static library, for environments where dynamic loading is not practical.

crates/static/src/lib.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#![no_std]
2+
#![feature(vec_into_raw_parts)]
3+
#![feature(core_intrinsics)]
4+
#![allow(internal_features)]
5+
#![feature(lang_items)]
6+
#![feature(error_in_core)]
7+
8+
extern crate alloc;
9+
10+
// Defines sqlite3_powersync_init
11+
#[allow(unused_imports)]
12+
use powersync_core;
13+
14+
// Use the SQLite allocator, allowing us to freely transfer memory between SQLite and Rust.
15+
#[cfg(not(test))]
16+
use sqlite_nostd::SQLite3Allocator;
17+
18+
#[cfg(not(test))]
19+
#[global_allocator]
20+
static ALLOCATOR: SQLite3Allocator = SQLite3Allocator {};
21+
22+
// Custom Panic handler for WASM and other no_std builds
23+
#[cfg(not(test))]
24+
#[panic_handler]
25+
fn panic(_info: &core::panic::PanicInfo) -> ! {
26+
core::intrinsics::abort()
27+
}
28+
29+
#[cfg(not(target_family = "wasm"))]
30+
#[cfg(not(test))]
31+
#[lang = "eh_personality"]
32+
extern "C" fn eh_personality() {}

tool/build_wasm.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,11 @@ RUSTFLAGS="-C link-arg=-sSIDE_MODULE=2 -C link-arg=-sASYNCIFY=1 -C link-arg=-sJS
2323
--features "powersync_core/static powersync_core/omit_load_extension sqlite_nostd/omit_load_extension" \
2424
-Z build-std=panic_abort,core,alloc \
2525
--target wasm32-unknown-emscripten
26+
27+
# Static lib (works for both sync and asyncify builds)
28+
# target/wasm32-unknown-emscripten/wasm/libpowersync.a
29+
cargo build \
30+
-p powersync_static \
31+
--profile wasm \
32+
-Z build-std=panic_abort,core,alloc \
33+
--target wasm32-unknown-emscripten

0 commit comments

Comments
 (0)