Skip to content

Conversation

@geofflittle
Copy link
Contributor

@geofflittle geofflittle commented Sep 9, 2025

This PR introduces support for compiling to the wasm32-unknown-unknown target, enabling its use in WASM environments.

To achieve this, several changes were made:

  • WASM-Specific Dependencies: Cargo.toml now uses target-specific dependencies. For wasm32, tokio is configured with a single-threaded runtime and uuid to use JS-native random number generation. Non-WASM targets retain the multi-threaded tokio runtime.
  • Feature Flag Refactoring: A new sync-api private feature was introduced to gate synchronization logic that is not WASM-compatible. Existing sync features now depend on this new feature flag. This allows building the core library without the networking and filesystem dependencies required for server sync.
  • In-Memory Storage: A new storage-inmemory feature has been added. A future PR will add this functionality to provide a storage backend that is compatible with WASM environments.
  • CI Workflow: A new GitHub Action, build-wasm, has been added to continuously verify that the crate builds successfully for the wasm32 target.
  • Documentation: The README.md has been updated with a new section explaining how to build the crate for WASM, highlighting the need to disable default features and select compatible ones.

Copy link
Collaborator

@djmitche djmitche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

It will be good to update the GitHub actions to do a WASM build, too, so we don't accidentally regress the various cfg conditionals.

@@ -1,23 +1,22 @@
#![cfg(feature = "server-local")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's cool!

Cargo.toml Outdated
# use native CA roots, instead of bundled
tls-native-roots = ["ureq/native-certs"]
# Feature for wasm builds. This enables wasm-compatible storage.
wasm = ["storage-inmemory"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll need --no-default-features --features wasm here, but the WASM is implicit from the platform. It might make sense to just document that when building for WASM, only a few features are allowed (among them storage-inmemory) and --no-default-features will be required. Then users building for WASM can select the features they want from among that set (for example, some might want storage-inmemory, while others might want storage-somebrowserdbthing).

Special bonus points if using other features results in a useful error message!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! I've removed the wasm flag and added some treatment in the README.

Re: your suggestion for a better WASM error message, I found that a build.rs script can't catch a missing --no-default-features flag (i.e., a user building with defaults), because the project's WASM-incompatible dependencies fail to compile before build.rs runs.

Given this, how do you see our detecting the right situation to display an improved error message?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this, how do you see our detecting the right situation to display an improved error message?

Good idea to try to detect in build.rs -- but bummer that it doesn't work. Maybe those special bonus points aren't achievable! No need to spend more time on it.

@geofflittle geofflittle changed the title Add wasm flag feat: Add WASM Support Sep 11, 2025
@geofflittle geofflittle marked this pull request as ready for review September 11, 2025 13:51
@geofflittle geofflittle marked this pull request as draft September 11, 2025 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants