I'm working on a sound library. This library shall be used as native compilation and as WASM running in a browser.
I provided an example (runnable with cargo run --example=name) which works fine.
Is there a way to modify that example to work in an WASM environment as well?
When targeting WASM the required packages are completely different and I don't know how to integrate that in my Cargo.toml (see cpal/Cargo.toml at master · RustAudio/cpal · GitHub for an example)
Where would I have to place the html and js files for those examples?
If there's no (easy) solution I'll fall back to using some dedicated example crates.
Put all examples separate $repository/examples/example_name/ directories
Each example has its own Cargo.toml as though it's a regular crate
Declare the top level crate as a workspace, and include the examples as members:
# Cargo.toml
[workspace]
members = ["examples/*"]
I've got a project that does this -- examples run natively with non-wasm dependencies, and on WASM with those dependencies, and the wasm dependencies aren't part of the library.
Thanks, that project is already part of a workspace. I could add those examples as prefixed package. Like "example-beep". That could be a useful work-around.