Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: --target wasm32-unknown-unknown for loro crate (getrandom dep) #681

Merged
merged 1 commit into from
Mar 6, 2025

Conversation

synoet
Copy link
Contributor

@synoet synoet commented Mar 6, 2025

Running

cd crates/loro && cargo build --target wasm32-unknown-unknown

Gives the following:

error: the wasm*-unknown-unknown targets are not supported by default, you may need to enable the "js" feature. For more information see: https://docs.rs/getrandom/#webassembly-support
   --> /Users/synoet/.cargo/registry/src/index.crates.io-6f17d22bba15001f/getrandom-0.2.15/src/lib.rs:342:9
    |
342 | /         compile_error!("the wasm*-unknown-unknown targets are not supported by \
343 | |                         default, you may need to enable the \"js\" feature. \
344 | |                         For more information see: \
345 | |                         https://docs.rs/getrandom/#webassembly-support");
    | |________________________________________________________________________^

error[E0433]: failed to resolve: use of undeclared crate or module `imp`
   --> /Users/synoet/.cargo/registry/src/index.crates.io-6f17d22bba15001f/getrandom-0.2.15/src/lib.rs:398:9
    |
398 |         imp::getrandom_inner(dest)?;
    |         ^^^ use of undeclared crate or module `imp`

Conditionally enabling the js feature for getrandom in loro-internal when target architecture is wasm-32 fixes the issue.

Allows using the loro crate in projects that compile to wasm32-unknown-unknown like cloudflare's worker-rs, which was the use case where I ran into this issue at first.

@zxch3n
Copy link
Member

zxch3n commented Mar 6, 2025

Thanks!

@zxch3n zxch3n merged commit 8db758a into loro-dev:main Mar 6, 2025
1 check passed
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