Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
4a57514
Replace SDK File struct with StorageEntry for web
thlsrms Apr 24, 2025
505496c
Enable web build for the SDK crate
thlsrms Apr 24, 2025
d3348bb
Enable run_threaded on the web with spawn_local
thlsrms Apr 25, 2025
5075b55
Improve Rust SDK websocket message handling on wasm32
thlsrms May 1, 2025
97563d8
Add cookie API and re-export gloo storage wrappers for the web SDK
thlsrms May 2, 2025
2612d1a
Remove some redundancies from wasm32 rust sdk
thlsrms May 5, 2025
f36cc7d
Add `web` feature flag to the rust sdk
thlsrms May 11, 2025
38a22f8
Add token verification for the wasm sdk websocket connection
thlsrms May 7, 2025
a284ebc
Rename misleading `run_threaded` to `run_background` on wasm32
thlsrms May 7, 2025
180bbfe
Reduce cfg noise by simplifying mutex handling in the sdk crate
thlsrms May 11, 2025
9936c9f
Remove tokio dependency from the rust web sdk
thlsrms May 11, 2025
0fee245
Improve error handling for the wasm sdk's Cookie builder
thlsrms May 16, 2025
87c64f6
Use conditional type aliases to reduce cfg noise on structs
thlsrms Oct 28, 2025
1dcc390
Consolidate web/non-web `build_impl` functions
thlsrms Oct 28, 2025
d97a6dd
Enforce compile error on non-portable `DbConnection` methods
thlsrms Oct 28, 2025
0c63e0e
Bump `getrandom` to 0.3.4, remove legacy `RUSTFLAGS` requirement
thlsrms Oct 28, 2025
d54722f
Minor formatting and code simplification for clippy
thlsrms Oct 28, 2025
76b3035
Rename run_background to run_background_task for clarity
thlsrms Nov 22, 2025
0aff316
Hide wasm-only DbConnection methods in native docs
thlsrms Nov 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 124 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions crates/codegen/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1383,10 +1383,11 @@ impl __sdk::InModule for RemoteTables {{
/// You must explicitly advance the connection by calling any one of:
///
/// - [`DbConnection::frame_tick`].
/// - [`DbConnection::run_threaded`].
#[cfg_attr(not(target_arch = \"wasm32\"), doc = \"- [`DbConnection::run_threaded`].\")]
#[cfg_attr(target_arch = \"wasm32\", doc = \"- [`DbConnection::run_background_task`].\")]
/// - [`DbConnection::run_async`].
/// - [`DbConnection::advance_one_message`].
/// - [`DbConnection::advance_one_message_blocking`].
#[cfg_attr(not(target_arch = \"wasm32\"), doc = \"- [`DbConnection::advance_one_message_blocking`].\")]
/// - [`DbConnection::advance_one_message_async`].
///
/// Which of these methods you should call depends on the specific needs of your application,
Expand Down Expand Up @@ -1493,6 +1494,7 @@ impl DbConnection {{
/// This is a low-level primitive exposed for power users who need significant control over scheduling.
/// Most applications should call [`Self::run_threaded`] to spawn a thread
/// which advances the connection automatically.
#[cfg(not(target_arch = \"wasm32\"))]
pub fn advance_one_message_blocking(&self) -> __sdk::Result<()> {{
self.imp.advance_one_message_blocking()
}}
Expand All @@ -1518,10 +1520,17 @@ impl DbConnection {{
}}

/// Spawn a thread which processes WebSocket messages as they are received.
#[cfg(not(target_arch = \"wasm32\"))]
pub fn run_threaded(&self) -> std::thread::JoinHandle<()> {{
self.imp.run_threaded()
}}

/// Spawn a background task which processes WebSocket messages as they are received.
#[cfg(target_arch = \"wasm32\")]
pub fn run_background_task(&self) {{
self.imp.run_background_task()
}}

/// Run an `async` loop which processes WebSocket messages when polled.
pub async fn run_async(&self) -> __sdk::Result<()> {{
self.imp.run_async().await
Expand Down
19 changes: 17 additions & 2 deletions crates/codegen/tests/snapshots/codegen__codegen_rust.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1823,10 +1823,17 @@ impl __sdk::InModule for RemoteTables {
/// You must explicitly advance the connection by calling any one of:
///
/// - [`DbConnection::frame_tick`].
/// - [`DbConnection::run_threaded`].
#[cfg_attr(not(target_arch = "wasm32"), doc = "- [`DbConnection::run_threaded`].")]
#[cfg_attr(
target_arch = "wasm32",
doc = "- [`DbConnection::run_background_task`]."
)]
/// - [`DbConnection::run_async`].
/// - [`DbConnection::advance_one_message`].
/// - [`DbConnection::advance_one_message_blocking`].
#[cfg_attr(
not(target_arch = "wasm32"),
doc = "- [`DbConnection::advance_one_message_blocking`]."
)]
/// - [`DbConnection::advance_one_message_async`].
///
/// Which of these methods you should call depends on the specific needs of your application,
Expand Down Expand Up @@ -1933,6 +1940,7 @@ impl DbConnection {
/// This is a low-level primitive exposed for power users who need significant control over scheduling.
/// Most applications should call [`Self::run_threaded`] to spawn a thread
/// which advances the connection automatically.
#[cfg(not(target_arch = "wasm32"))]
pub fn advance_one_message_blocking(&self) -> __sdk::Result<()> {
self.imp.advance_one_message_blocking()
}
Expand All @@ -1958,10 +1966,17 @@ impl DbConnection {
}

/// Spawn a thread which processes WebSocket messages as they are received.
#[cfg(not(target_arch = "wasm32"))]
pub fn run_threaded(&self) -> std::thread::JoinHandle<()> {
self.imp.run_threaded()
}

/// Spawn a background task which processes WebSocket messages as they are received.
#[cfg(target_arch = "wasm32")]
pub fn run_background_task(&self) {
self.imp.run_background_task()
}

/// Run an `async` loop which processes WebSocket messages when polled.
pub async fn run_async(&self) -> __sdk::Result<()> {
self.imp.run_async().await
Expand Down
30 changes: 29 additions & 1 deletion sdks/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ rust-version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = []
web = [
"dep:getrandom",
"dep:gloo-console",
"dep:gloo-net",
"dep:gloo-storage",
"dep:gloo-utils",
"dep:js-sys",
"dep:tokio-tungstenite-wasm",
"dep:wasm-bindgen",
"dep:wasm-bindgen-futures",
"dep:web-sys",
]

[dependencies]
spacetimedb-data-structures.workspace = true
spacetimedb-sats.workspace = true
Expand All @@ -23,12 +38,25 @@ bytes.workspace = true
flate2.workspace = true
futures.workspace = true
futures-channel.workspace = true
home.workspace = true
http.workspace = true
log.workspace = true
once_cell.workspace = true
prometheus.workspace = true
rand.workspace = true

getrandom = { version = "0.3.4", features = ["wasm_js"], optional = true }
gloo-console = { version = "0.3.0", optional = true }
gloo-net = { version = "0.6.0", optional = true }
gloo-storage = { version = "0.3.0", optional = true }
gloo-utils = { version = "0.2.0", optional = true }
js-sys = { version = "0.3", optional = true }
tokio-tungstenite-wasm = { version = "0.6.0", optional = true }
wasm-bindgen = { version = "0.2.100", optional = true }
wasm-bindgen-futures = { version = "0.4.45", optional = true }
web-sys = { version = "0.3.77", features = ["HtmlDocument"], optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
home.workspace = true
tokio.workspace = true
tokio-tungstenite.workspace = true

Expand Down
Loading