commit 438970dc46e39cabb19d44b5cf3be2d039f951b4
parent e7ba9066e5b0f057079a9a1561b35ceed0994677
Author: triesap <tyson@radroots.org>
Date: Sun, 18 Jan 2026 22:37:50 +0000
sql-wasm: use embedded engine in wasm bindings
- split `radroots-sql-core` export lock from bridge executor and add bridge feature
- use embedded sqlite engine in tangle db/events wasm bindings
- enable `radroots-sql-wasm-core` embedded feature in wasm crates and drop bridge default
- keep export snapshot path wired to embedded db bytes
Diffstat:
7 files changed, 60 insertions(+), 51 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
@@ -42,7 +42,7 @@ radroots-log = { path = "log", version = "0.1.0", default-features = false }
radroots-net = { path = "net", version = "0.1.0", default-features = false }
radroots-net-core = { path = "net-core", version = "0.1.0", default-features = false }
radroots-sql-wasm-bridge = { path = "sql-wasm-bridge", version = "0.1.0" }
-radroots-sql-wasm-core = { path = "sql-wasm-core", version = "0.1.0" }
+radroots-sql-wasm-core = { path = "sql-wasm-core", version = "0.1.0", default-features = false }
radroots-sql-core = { path = "sql-core", version = "0.1.0" }
radroots-tangle-db-schema = { path = "tangle-db-schema", version = "0.1.0", default-features = false }
radroots-tangle-events = { path = "tangle-events", version = "0.1.0", default-features = false }
diff --git a/sql-core/Cargo.toml b/sql-core/Cargo.toml
@@ -10,7 +10,8 @@ license.workspace = true
crate-type = ["rlib"]
[features]
-web = ["dep:radroots-sql-wasm-bridge", "dep:serde-wasm-bindgen", "dep:wasm-bindgen"]
+web = []
+bridge = ["web", "dep:radroots-sql-wasm-bridge", "dep:serde-wasm-bindgen", "dep:wasm-bindgen"]
native = ["dep:rusqlite"]
embedded = []
diff --git a/sql-core/src/executor_wasm.rs b/sql-core/src/executor_wasm.rs
@@ -1,46 +1,5 @@
use crate::{ExecOutcome, SqlExecutor, error::SqlError};
-use std::cell::Cell;
-use std::sync::atomic::{AtomicBool, Ordering};
-
-const EXPORT_LOCK_ERR: &str = "tangle db export in progress";
-
-static EXPORT_LOCK_ACTIVE: AtomicBool = AtomicBool::new(false);
-
-thread_local! {
- static EXPORT_LOCK_BYPASS: Cell<bool> = Cell::new(false);
-}
-
-pub fn export_lock_begin() -> Result<(), SqlError> {
- let was_active = EXPORT_LOCK_ACTIVE.swap(true, Ordering::SeqCst);
- if was_active {
- return Err(SqlError::InvalidArgument(EXPORT_LOCK_ERR.to_string()));
- }
- Ok(())
-}
-
-pub fn export_lock_end() {
- EXPORT_LOCK_ACTIVE.store(false, Ordering::SeqCst);
-}
-
-pub fn export_lock_active() -> bool {
- EXPORT_LOCK_ACTIVE.load(Ordering::SeqCst)
-}
-
-pub fn with_export_lock_bypass<T>(f: impl FnOnce() -> T) -> T {
- EXPORT_LOCK_BYPASS.with(|flag| {
- let prev = flag.replace(true);
- let out = f();
- flag.set(prev);
- out
- })
-}
-
-fn export_lock_blocked() -> bool {
- if !EXPORT_LOCK_ACTIVE.load(Ordering::SeqCst) {
- return false;
- }
- EXPORT_LOCK_BYPASS.with(|flag| !flag.get())
-}
+use crate::export_lock::{EXPORT_LOCK_ERR, export_lock_blocked};
pub struct WasmSqlExecutor;
diff --git a/sql-core/src/export_lock.rs b/sql-core/src/export_lock.rs
@@ -0,0 +1,46 @@
+#![cfg(target_arch = "wasm32")]
+#![forbid(unsafe_code)]
+
+use crate::error::SqlError;
+use std::cell::Cell;
+use std::sync::atomic::{AtomicBool, Ordering};
+
+pub(crate) const EXPORT_LOCK_ERR: &str = "tangle db export in progress";
+
+static EXPORT_LOCK_ACTIVE: AtomicBool = AtomicBool::new(false);
+
+thread_local! {
+ static EXPORT_LOCK_BYPASS: Cell<bool> = Cell::new(false);
+}
+
+pub fn export_lock_begin() -> Result<(), SqlError> {
+ let was_active = EXPORT_LOCK_ACTIVE.swap(true, Ordering::SeqCst);
+ if was_active {
+ return Err(SqlError::InvalidArgument(EXPORT_LOCK_ERR.to_string()));
+ }
+ Ok(())
+}
+
+pub fn export_lock_end() {
+ EXPORT_LOCK_ACTIVE.store(false, Ordering::SeqCst);
+}
+
+pub fn export_lock_active() -> bool {
+ EXPORT_LOCK_ACTIVE.load(Ordering::SeqCst)
+}
+
+pub fn with_export_lock_bypass<T>(f: impl FnOnce() -> T) -> T {
+ EXPORT_LOCK_BYPASS.with(|flag| {
+ let prev = flag.replace(true);
+ let out = f();
+ flag.set(prev);
+ out
+ })
+}
+
+pub(crate) fn export_lock_blocked() -> bool {
+ if !EXPORT_LOCK_ACTIVE.load(Ordering::SeqCst) {
+ return false;
+ }
+ EXPORT_LOCK_BYPASS.with(|flag| !flag.get())
+}
diff --git a/sql-core/src/lib.rs b/sql-core/src/lib.rs
@@ -7,11 +7,14 @@ pub mod error;
pub mod migrations;
#[cfg(all(feature = "web", target_arch = "wasm32"))]
-mod executor_wasm;
+mod export_lock;
#[cfg(all(feature = "web", target_arch = "wasm32"))]
+pub use export_lock::{export_lock_active, export_lock_begin, export_lock_end, with_export_lock_bypass};
+
+#[cfg(all(feature = "bridge", target_arch = "wasm32"))]
+mod executor_wasm;
+#[cfg(all(feature = "bridge", target_arch = "wasm32"))]
pub use executor_wasm::WasmSqlExecutor;
-#[cfg(all(feature = "web", target_arch = "wasm32"))]
-pub use executor_wasm::{export_lock_active, export_lock_begin, export_lock_end, with_export_lock_bypass};
#[cfg(feature = "native")]
mod executor_sqlite;
diff --git a/tangle-db-wasm/Cargo.toml b/tangle-db-wasm/Cargo.toml
@@ -10,8 +10,8 @@ license.workspace = true
crate-type = ["cdylib", "rlib"]
[dependencies]
-radroots-sql-core = { workspace = true, features = ["web"] }
-radroots-sql-wasm-core = { workspace = true }
+radroots-sql-core = { workspace = true, features = ["bridge"] }
+radroots-sql-wasm-core = { workspace = true, default-features = false, features = ["bridge"] }
radroots-tangle-db = { workspace = true }
radroots-tangle-db-schema = { workspace = true }
radroots-tangle-events = { workspace = true }
diff --git a/tangle-events-wasm/Cargo.toml b/tangle-events-wasm/Cargo.toml
@@ -12,8 +12,8 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
base64 = { workspace = true }
radroots-events = { workspace = true, default-features = false, features = ["serde"] }
-radroots-sql-core = { workspace = true, features = ["web"] }
-radroots-sql-wasm-core = { workspace = true }
+radroots-sql-core = { workspace = true, features = ["bridge"] }
+radroots-sql-wasm-core = { workspace = true, default-features = false, features = ["bridge"] }
radroots-tangle-events = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }