Skip to content

Using wasm-bindgen for games #51

Open
@17cupsofcoffee

Description

@17cupsofcoffee

I've noticed while working on the wasm-bindgen backend for Tetra that there's a few rough edges around the tooling from a game dev perspective. Since wasm-bindgen seems to be the 'blessed' tool for WASM in Rust, having a tracking issue for some of these papercuts seems like a good idea. Maybe we can work with the WASM WG on some of these?

(Also, since some of said WG have been tagged in - aside from these issues, porting to WASM has gone ridiculously smoothly, kudos for all your hard work!)

Support for binary crates

wasm-bindgen doesn't currently support main - you have to use the wasm_bindgen(start) attribute on a public function instead, and that function can't be main (rustwasm/wasm-bindgen#1630). This means that it's not possible to have a binary crate 'just work' without some glue code.

My current approach is to have a macro that automatically creates a wasm_main wrapper, but I'd be interested to hear how other libraries (e.g. Winit) are planning on approaching this.

The above info is now out of date - wasm-bindgen supports binary crates now.

Most likely as a consequence of the above, wasm-pack is also currently quite heavily focused on usage for libraries that are intended for publishing to NPM. There's an RFC for a --no-pack mode (rustwasm/wasm-pack#691) that looks like it might work better for our use cases, but it seems to have stalled a little bit.

No cargo web counterpart

The stdweb ecosystem has cargo web, which is a really nice tool that offers a HTTP server, auto-reloading, static file packaging, etc. Unfortunately, it doesn't currently support wasm-bindgen projects (koute/cargo-web#92).

There are templates for projects that call into wasm-pack from Webpack and offer similar features in that way, but I feel like this is overkill for most gamedev needs - 99% of the time, you just want a HTML page with a canvas on it that you can hook into.

EDIT: Actually, it looks like cargo web might have added wasm-bindgen support of some kind since I last tried it! Need to give that a proper try. Nope, it was stdweb that added support, my mistake!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Books/Tutorials/GuidesIssues for explanatory content that's desired.Needs ChampionWe need someone who can help drive this forward.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions