blitz icon indicating copy to clipboard operation
blitz copied to clipboard

Request: wasm support

Open pdufour opened this issue 1 year ago • 6 comments

A bit of an unusual request, but is it possible to compile this to a wasm target? Didn't see any open issues about this. Thanks for the cool library!

pdufour avatar Nov 23 '24 10:11 pdufour

Our recommendation if you're targeting web will be to target the DOM directly. Nevertheless, this is something we want to support. I have a patch which gets stylo compiling for WASM. Unfortunately that's currently causing issues with Gecko's bindings generation, so that will need to be sorted to land it, but if you wanted to try and get something working then you could use that branch.

nicoburns avatar Dec 01 '24 04:12 nicoburns

@nicoburns am I right to assume that this is also blocked by https://github.com/linebender/parley/issues/70?

KnorpelSenf avatar Jan 31 '25 12:01 KnorpelSenf

I am also interested, I tried to build https://github.com/DioxusLabs/dioxus/pull/4427 for wasm, but I get this error:

error[E0277]: `dyn anyrender::WindowHandle` cannot be shared between threads safely
   --> /.../anyrender_vello-0.4.1/src/window_renderer.rs:107:13
    |
106 |         let surface = pollster::block_on(self.wgpu_context.create_surface(
    |                                                            -------------- required by a bound introduced by this call
107 |             window_handle.clone(),
    |             ^^^^^^^^^^^^^^^^^^^^^ `dyn anyrender::WindowHandle` cannot be shared between threads safely
    |
    = help: the trait `Sync` is not implemented for `dyn anyrender::WindowHandle`
    = note: required for `std::sync::Arc<dyn anyrender::WindowHandle>` to implement `Send`
    = note: required for `std::sync::Arc<dyn anyrender::WindowHandle>` to implement `wgpu::WasmNotSend`
    = note: required for `std::sync::Arc<dyn anyrender::WindowHandle>` to implement `wgpu::WasmNotSendSync`
    = note: required for `std::sync::Arc<dyn anyrender::WindowHandle>` to implement `wgpu::WindowHandle`
    = note: required for `SurfaceTarget<'_>` to implement `From<std::sync::Arc<dyn anyrender::WindowHandle>>`
    = note: required for `std::sync::Arc<dyn anyrender::WindowHandle>` to implement `Into<SurfaceTarget<'_>>`

jerome-caucat avatar Jul 18 '25 08:07 jerome-caucat

@jerome-caucat How are you building that? My build is erroring out on the woff dependency for some reason.

@godcodehunter has previously got this working (https://github.com/DioxusLabs/blitz/issues/185#issuecomment-2973403810). Perhaps they can help?


In general, I don't think there is anything fundamentally blocking this from working. The main difficulty is that I believe WGPU is async on web (and we're currently ignoring that). So the setup code in blitz-shell and anyrender_vello may need to be adjusted to be async (either only on WASM or everywhere). The Vello with_winit example does this and may be the example to follow.

nicoburns avatar Jul 18 '25 10:07 nicoburns

How are you building that? My build is erroring out on the woff dependency for some reason.

@nicoburns I should have mentioned, I changed the blitz-dom dependency in the Cargo.toml:

blitz-dom = { workspace = true, features = ["tracing", "svg", "accessibility", "system_fonts"] }

jerome-caucat avatar Jul 18 '25 11:07 jerome-caucat

Ah, that gets me to the same error as you. You may wish to look at https://docs.rs/wgpu/latest/wgpu/#:~:text=fragile%2Dsend%2Dsync%2Dnon,to%20write%20cross%2Dplatform%20code (although enabling doesn't actually fix the error for me).

The pollster::block_on calls are what probably needs to be replaced with actual async code.

nicoburns avatar Jul 18 '25 11:07 nicoburns