DouglasDwyer/egui_wings

Minimal example for wasm32-unknown-unknown target

Closed this issue · 3 comments

Hi @DouglasDwyer,

many thanks four your work on this library. I tried to get a minimum working example for compiling both the host and a plugin to a wasm32-unknown-unknown target.

One try is under https://github.com/geolehmann/egui_wasm_plugins, and I have a completely strange issue where everything worked and the next day stopped working and since then throws "unreachable" errors .... I am still scratching my head and trying to figure this out.

grafik

Then I started all over again and tried to set up another minimum example under https://github.com/geolehmann/egui_wasm_plugins_try2, and this time no errors pop up but only the UI from the host is rendered, not from the plugin, no matter what I try.

grafik

So after two weeks of trial-and-error I wanted to reach out for help and kindly ask if you could provide a working example for this use case, or point me in the right direction - many thanks in advance!

Hey there @geolehmann, thanks for reaching out! I appreciate your interest in my library.

I cloned your egui_wasm_plugins_try2 repository and performed the following steps:

  • I needed to change the WGPU dependency from wgpu = { version = "*", features = ["webgpu"] } to wgpu = { version = "0.20.1", features = ["webgpu"] }, since another dependency (egui-winit) wants version 0.20.1. Without this change I was getting an error.
  • I ran cargo clean to make sure I didn't have any stale build files
  • I ran cd egui_wings_example
  • I ran cargo build --target wasm32-unknown-unknown
  • I did cd ..
  • I ran wasm-bindgen --out-dir build-wasm/ --web target/wasm32-unknown-unknown/debug/egui_wings_example.wasm
  • I served the contents of build-wasm on a local web server

This worked, and I saw the following screen:
image

I would recommend running cargo clean and trying again. There's one small flaw with the example repository, where if you update a dependency for the host crate and then rebuild it, it won't rebuild the guest plugin (the build script for the guest plugin doesn't detect that it should re-run). So maybe it's possible that your guest plugin build got out of date with the host?

Anyway, if a cargo clean doesn't fix it, could you please provide me with the compiler version that you are using, along with any environment variables or settings that affect rustc compilation?

Also, I want to mention that some of the libraries required for egui_wings (specifically, geese and wings) have been designed specifically for my game engine's modding system. Sharing an egui::Context between two WASM modules shouldn't require them - the end user would just need to define a way to pass a byte array (the serialized Context) between the two modules each frame.

If you want me to try and expose that functionality separately from wings/geese, let me know. That was originally the intent of my egui PR, but as you probably saw, the PR was rejected. Or maybe you're fine with using geese and wings - I think wings is actually super useful for making a dynamic plugin system if that's what you're doing :)

A thousand thanks for your quick response, indeed the combination of cargo clean and a modified build script to ensure the plugins are compiled with the same version of the libraries did the trick.

And yes, I could probably skip using wings/geese - but as you said, for my use case of a dynamic plugin system they are perfect :-)

I´ll update my repo so that others with the same problem could use it as template.