Add wasm32 support to the rust sdk#2704
Add wasm32 support to the rust sdk#2704thlsrms wants to merge 20 commits intoclockworklabs:masterfrom
Conversation
|
@thlsrms Thank you for opening this! What's the current status? Are there parts still in progress, or should we be getting a reviewer on this? |
I've been working on support for the To keep this PR focused, I'll defer the emscripten support to a separate PR if necessary. I'll make some minor adjustments and rebase onto master. I'll ping you tomorrow if that's alright. |
|
@thlsrms absolutely, thank you! and no rush. I'm going to be out of office Wed-Fri this week, but either way it might take a little while for us to get around to reviewing, since we have some other things in progress right now. |
|
@bfops When you're available, feel free to assign a reviewer. 👍 |
|
+1 |
|
In case it helps someone: I created a proof of concept integration of spacetime into Dioxus - it works™, however it does not feel very native as the interaction with the signals Dioxus uses for its state tracking does not seem very good yet (https://github.com/enaut/kommunikationszentrum/blob/7d04e04c4fede15101f995bec74e1b23adf7d68d/admin/src/main.rs). It might also be that I know neither spacetime nor Dioxus too well, so I might just have not found the clean solution. Nonetheless, I wanted to share that this PR works for Dioxus too. I did not test the updated |
|
Thanks so much @thlsrms for your work here! Your branch got a little stale, I had a go merging It compiles to wasm and native, but I have not yet tested it thoroughly. @bfops how are priorities looking on your end? It would be great if this could eventually be merged. |
|
@liamaharon Thanks, and your merge was on point. I had some time this morning to fix the conflicts and rebase. |
|
Why is it necessary for Why do we need to pass the auth token as a query parameter? If it is necessary, are we obtaining a short--lived token via |
The native version relies on tokio's
This is a limitation on the browser's websocket API which doesn't allow header manipulation. Yes, before building the connection uri we call |
gefjon
left a comment
There was a problem hiding this comment.
I can't say I love making build be async, but I see that it's necessary, so what are you gonna do.
We're discussing internally how to get this tested. Once that's figured out, we should be able to merge this.
|
When/If this merges give me a ping on this so we can move forward this ticket: #3462 |
kistz
left a comment
There was a problem hiding this comment.
I am no member of clockworklabs just a guy but thought this could be useful info :>
|
Very excited about this |
|
@gefjon Thanks for taking a look at this, I'll try tackling it over the weekend or at the start of the next week. |
gefjon
left a comment
There was a problem hiding this comment.
This is looking great! A few minor things, then if you can get this updated for latest master and passing CI, I think we'll be good to go.
| pub fn add_unique_constraint<Col>(&mut self, unique_index_name: &'static str, get_unique_col: fn(&Row) -> &Col) | ||
| where | ||
| Col: Any + Clone + std::hash::Hash + Eq + Send + Sync + std::fmt::Debug + 'static, | ||
| Col: std::any::Any + Clone + std::hash::Hash + Eq + Send + Sync + std::fmt::Debug + 'static, |
| ahash = { version = "0.8", default-features = false, features = ["std"] } | ||
| anyhow = "1.0.68" | ||
| anymap = "0.12" | ||
| anymap = { package = "anymap3", version = "1.0.1" } |
There was a problem hiding this comment.
Please update your PR description to document & justify this change.
|
@thlsrms any chance you could wrap this up in time for the next stdb release? |
Yes! I'll do my best to do it Saturday morning! |
- `DbConnectionBuilder::build` becomes async without tokio's block_in_place. Still need to add `web` feature flag.
Renamed the `run_threaded` method on `wasm32` to better reflect its behavior of spawning a background task. The generated `DbConnection` methods `run_threaded`, `run_background`, and `advance_one_message_blocking` now include runtime panics with a clear error feedback when called on unsupported targets.
Trim down repetitive `cfg` clauses by extracting common lock patterns into `get_lock_[sync|async]`.
Moves the creation of DbContextImplInner and DbContextImpl into private helper functions (`build_db_ctx_inner` and `build_db_ctx`) to reduce duplication between the web and non-web implementations of `build_impl`.
9e5dda7 to
bba3378
Compare
If the only reason to replace What I'm looking for in the PR description is: Why is it a necessity that we switch to |
|
@thlsrms do you have any capacity at the moment to adress the feedback? (gentle ping, no rush, hope it is not annoying) |
|
Any progress on this? If you need an extra pair of hands for something, I can help. I would very much like to explore SpacetimeDB+dioxus, and this is a blocking issue for me. |
|
@drdozer I already did explore spacetime+dioxus: enaut/dioxus_use_spacetime#1 (AI was used) There I'm more or less also waiting for wasm support to continue. But it already works with the git dependency on this PR |
|
@drdozer sorry the mixup I actually wrote an additional language export which had way better ergonomics than my first try: enaut#2 (branch here: https://github.com/enaut/SpacetimeDB/tree/copilot/explore-dioxus-signals-hooks ) when using... what it basically does is it hooks in the |
That looks really nice. Was there a reason you closed that pull request without merging? Sorry, I'm still trying to carve out some time where I can try this stuff out. |
@drdozer I'm not yet confident enough it is actually any good... I had the Idea and thought AI might generate something useful - It did do rather well - I think. I haven't had any time to thoroughly test anything, though. And I don't want to just open a PR here and let someone else sift through the AI stuff... the PR was mostly for copilot to have something to work with and was only as merge into my own fork... If you are interested and you don't mind that it is untested AI you are quite welcome to comment on the stuff... I also generated a proof of concept TODOmvc with it... That I only have offline... I could publish that too if you are interested... |
|
Looking forward for this one 🙌 |
|
Thank you for opening this! Closing this since #4089 is based on this and updates it for more recent versions of |
Description of Changes
Enabled the Rust SDK
wasm32compilation target for web usage.webfeature flag, incompatible with non-wasm32targets.anymapcrate withanymap3.API and ABI breaking changes
None. Most changes apply only to the
wasm32target, so there are no global breaking changes. The main differences to the native targets are:DBConnectionBuilder::buildis nowasyncon the web.DbConnection'srun_threadedandadvance_one_message_blockingunavailable for the wasm32 target.DbConnection::run_background_taskas replacement forrun_threadedon the web.Filestruct unavailable on the web.gloo_storagefor local/session storage.HttpOnlycookies).Expected complexity level and risk
Estimated at 2:
Testing
I built 2 demos to exercise the changes: