WebAssembly support
for emscripten
for wasm32-unknown-unknown
Rust has gained support for WebAssembly, meaningthat you can run Rust code in your browser, client-side.
In Rust 1.14, we gained support throughemscripten. With itinstalled, you can write Rust code and have it produceasm.js (the precusor to wasm) and/or WebAssembly.
Here's an example of using this support:
$ rustup target add wasm32-unknown-emscripten
$ echo 'fn main() { println!("Hello, Emscripten!"); }' > hello.rs
$ rustc --target=wasm32-unknown-emscripten hello.rs
$ node hello.js
However, in the meantime, Rust has also grown its own support, independentfrom Emscripten. This is known as "the unknown target", because instead ofwasm32-unknown-emscripten
, it's wasm32-unknown-unknown
. This will bethe preferred target to use once it's ready, but for now, it's reallyonly well-supported in nightly.