Skip to content

WASM cannot build for wasm32-wasi #4906

Closed
@schtauffen

Description

@schtauffen

Bevy version

0.7

What you did

Cargo.toml

<snip>

[target.'cfg(target_arch="wasm32")'.dependencies]
lunatic = "0.9"
bevy = { version = "0.7", default-features = false }

.cargo/config.toml

[target.wasm32-wasi]
runner = "lunatic"

ran cargo run --bin server --target wasm32-wasi

What went wrong

I expect bevy to compile for use inside wasm. Instead, it gives errors:

error[E0463]: can't find crate for `js_sys`
 --> C:\Users\Zach and Andrea\.cargo\registry\src\github.com-1ecc6299db9ec823\cpal-0.13.5\src\host\webaudio\mod.rs:1:1
  |
1 | extern crate js_sys;
  | ^^^^^^^^^^^^^^^^^^^^ can't find crate

error[E0463]: can't find crate for `wasm_bindgen`
 --> C:\Users\Zach and Andrea\.cargo\registry\src\github.com-1ecc6299db9ec823\cpal-0.13.5\src\host\webaudio\mod.rs:2:1
  |
2 | extern crate wasm_bindgen;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error[E0463]: can't find crate for `web_sys`
 --> C:\Users\Zach and Andrea\.cargo\registry\src\github.com-1ecc6299db9ec823\cpal-0.13.5\src\host\webaudio\mod.rs:3:1
  |
3 | extern crate web_sys;
  | ^^^^^^^^^^^^^^^^^^^^^ can't find crate

   Compiling image v0.23.14
error[E0433]: failed to resolve: use of undeclared type `AudioContextOptions`
   --> C:\Users\Zach and Andrea\.cargo\registry\src\github.com-1ecc6299db9ec823\cpal-0.13.5\src\host\webaudio\mod.rs:218:31    
    |
218 |         let mut stream_opts = AudioContextOptions::new();
    |                               ^^^^^^^^^^^^^^^^^^^ use of undeclared type `AudioContextOptions`

error[E0433]: failed to resolve: use of undeclared type `AudioContext`
   --> C:\Users\Zach and Andrea\.cargo\registry\src\github.com-1ecc6299db9ec823\cpal-0.13.5\src\host\webaudio\mod.rs:221:13    
    |
221 |             AudioContext::new_with_context_options(&stream_opts).map_err(
    |             ^^^^^^^^^^^^ use of undeclared type `AudioContext`

error[E0433]: failed to resolve: use of undeclared type `Closure`
   --> C:\Users\Zach and Andrea\.cargo\registry\src\github.com-1ecc6299db9ec823\cpal-0.13.5\src\host\webaudio\mod.rs:269:26
    |
269 |                 .replace(Closure::wrap(Box::new(move || {
    |                          ^^^^^^^ use of undeclared type `Closure`

error[E0412]: cannot find type `AudioContext` in this scope
  --> C:\Users\Zach and Andrea\.cargo\registry\src\github.com-1ecc6299db9ec823\cpal-0.13.5\src\host\webaudio\mod.rs:28:14      
   |
27 | pub struct Stream {
   |                  - help: you might be missing a type parameter: `<AudioContext>`
28 |     ctx: Arc<AudioContext>,
   |              ^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `Closure` in this scope
  --> C:\Users\Zach and Andrea\.cargo\registry\src\github.com-1ecc6299db9ec823\cpal-0.13.5\src\host\webaudio\mod.rs:29:46      
   |
29 |     on_ended_closures: Vec<Arc<RwLock<Option<Closure<dyn FnMut()>>>>>,
   |                                              ^^^^^^^ not found in this scope

error[E0412]: cannot find type `Closure` in this scope
   --> C:\Users\Zach and Andrea\.cargo\registry\src\github.com-1ecc6299db9ec823\cpal-0.13.5\src\host\webaudio\mod.rs:231:58    
    |
231 |         let mut on_ended_closures: Vec<Arc<RwLock<Option<Closure<dyn FnMut()>>>>> = Vec::new();
    |                                                          ^^^^^^^ not found in this scope

error[E0412]: cannot find type `Closure` in this scope
   --> C:\Users\Zach and Andrea\.cargo\registry\src\github.com-1ecc6299db9ec823\cpal-0.13.5\src\host\webaudio\mod.rs:262:53    
    |
262 |             let on_ended_closure: Arc<RwLock<Option<Closure<dyn FnMut()>>>> =
    |                                                     ^^^^^^^ not found in this scope

error[E0425]: cannot find function `eval` in this scope
   --> C:\Users\Zach and Andrea\.cargo\registry\src\github.com-1ecc6299db9ec823\cpal-0.13.5\src\host\webaudio\mod.rs:444:43    
    |
444 |     if let Ok(audio_context_is_defined) = eval("typeof AudioContext !== 'undefined'") {
    |                                           ^^^^ not found in this scope

error[E0599]: no method named `clone` found for struct `Arc<_>` in the current scope
   --> C:\Users\Zach and Andrea\.cargo\registry\src\github.com-1ecc6299db9ec823\cpal-0.13.5\src\host\webaudio\mod.rs:241:34    
    |
241 |             let ctx_handle = ctx.clone();
    |                                  ^^^^^ method not found in `Arc<_>`

error[E0599]: no method named `create_buffer` found for struct `Arc<_>` in the current scope
   --> C:\Users\Zach and Andrea\.cargo\registry\src\github.com-1ecc6299db9ec823\cpal-0.13.5\src\host\webaudio\mod.rs:250:18    
    |
250 |                 .create_buffer(
    |                  ^^^^^^^^^^^^^ method not found in `Arc<_>`
Some errors have detailed explanations: E0412, E0425, E0433, E0463, E0599.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `cpal` due to 13 previous errors
warning: build failed, waiting for other jobs to finish...

Additional information

I would not expect javascript/browser (js-sys, web-sys) interop to be required to compile to wasm.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-BugAn unexpected or incorrect behaviorD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesO-WebSpecific to web (WASM) buildsP-Compile-FailureA failure to compile Bevy appsS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions