Rust/gl/webgl emscripten/wasm etc


#1

how much do you need to keep in JS (shims etc) for this to work…
is there a library where you can essentially write a native desktop program using some subset of (eg) GL and SDL2/glfw or whatever (for receiving input and window change events), and have that just compile and run within the browser.

how much of this is ‘sorted’ vs ‘work in progress’

Any recomendations for specific tutorials/examples?

I’m still googling on this and see lots of talk of ‘dropping back to JS’ , also I realise that something like SDl/glfw may have slight discrepancies in exactly how the input messages work ( and what about drag-drop file support, and triggering a download ) … and of course there’d need to be an abstraction layer for acquiring (file) resources. (when porting code from the desktop to iOS/android apps, I made abstractions that let you run the same codepath on the desktop using files from a directory, and the resource bundle that would have been compiled; I imagine something similar? … also a desktop app could have been built to grab data from URLs aswell, of course).

I’m not after complete manipulation of the DOM right now, but I can see that is also demanded… I’m more thinking about desktop/web portability right now rather than ‘rust as a web language’ (although I might come at it form the other angle aswell)


#2

emscripten is the most fully-featured solution here. It provides the JS shims to support GL and IO and people have built SDL/etc with it. It’s a bit messy to set up and afaik not really possible to adjust its output, but people are doing real things with it at this point.

The (far) future is more likely in LLVM’s WebAssembly backend. Rust recently gained support for the wasm32-unknown-unknown target which uses it and bypasses emscripten, but (as its name suggests) it doesn’t provide any sort of platform layer, so you need to do all the JS interop yourself. Until that gains similar JS shims to emscripten (potentially as a wasm32-unknown-web target, for example) it’s mostly useful for the “Rust as a web language” niche.