Skip to content

Commit 3a35dea

Browse files
committed
Add static build as separate target
1 parent 78a56cc commit 3a35dea

File tree

6 files changed

+77
-10
lines changed

6 files changed

+77
-10
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Builds the core extension as a static library, exposing the `powersync_init_static` function to load it.

crates/static/src/lib.rs

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

tool/build_wasm.sh

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ emcc --version
66
# target/wasm32-unknown-emscripten/wasm/powersync.wasm
77
RUSTFLAGS="-C link-arg=-sSIDE_MODULE=2" \
88
cargo build \
9-
-p powersync_loadable \
9+
-p powersync_static \
1010
--profile wasm \
11-
--no-default-features \
12-
--features "powersync_core/static powersync_core/omit_load_extension sqlite_nostd/omit_load_extension" \
1311
-Z build-std=panic_abort,core,alloc \
1412
--target wasm32-unknown-emscripten
1513

@@ -19,10 +17,8 @@ cp "target/wasm32-unknown-emscripten/wasm/powersync.wasm" "libpowersync.wasm"
1917
# target/wasm32-unknown-emscripten/wasm_asyncify/powersync.wasm
2018
RUSTFLAGS="-C link-arg=-sSIDE_MODULE=2 -C link-arg=-sASYNCIFY=1 -C link-arg=-sJSPI_IMPORTS=@wasm/asyncify_imports.json" \
2119
cargo build \
22-
-p powersync_loadable \
20+
-p powersync_static \
2321
--profile wasm_asyncify \
24-
--no-default-features \
25-
--features "powersync_core/static powersync_core/omit_load_extension sqlite_nostd/omit_load_extension" \
2622
-Z build-std=panic_abort,core,alloc \
2723
--target wasm32-unknown-emscripten
2824

@@ -34,10 +30,8 @@ cp "target/wasm32-unknown-emscripten/wasm_asyncify/powersync.wasm" "libpowersync
3430
# Works for both emscripten and wasi.
3531
# target/wasm32-wasip1/wasm/libpowersync.a
3632
cargo build \
37-
-p powersync_loadable \
33+
-p powersync_static \
3834
--profile wasm \
39-
--no-default-features \
40-
--features "powersync_core/static powersync_core/omit_load_extension sqlite_nostd/omit_load_extension" \
4135
-Z build-std=panic_abort,core,alloc \
4236
--target wasm32-wasip1
4337

tool/build_xcframework.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,16 @@ rm -rf powersync-sqlite-core.xcframework
149149

150150
for TARGET in ${TARGETS[@]}; do
151151
echo "Building PowerSync loadable extension for $TARGET"
152-
cargo build -p powersync_loadable --profile release_apple --target $TARGET -Zbuild-std
152+
153+
if [[ $TARGET == *"watchos"* ]]; then
154+
cargo build \
155+
-p powersync_static \
156+
--profile release_apple \
157+
--target $TARGET \
158+
-Zbuild-std
159+
else
160+
cargo build -p powersync_loadable --profile release_apple --target $TARGET -Zbuild-std
161+
fi
153162
done
154163

155164
createXcframework

0 commit comments

Comments
 (0)