This is a simple Rust function that can be run in the browser. It takes an integer argument from JavaScript and returns an integer.
-
Turn on WASM in your browser.
-
Run:
cd examples python -m SimpleHTTPServer
-
Open
http://localhost:8000/
and then open the console. You should see something like:trying binaryen method: native-wasm binaryen method succeeded. pre-main prep time: 3 ms Emscripten boilerplate loaded. result: 55
-
Follow the instructions for installing Rust and Emscripten
-
Configure your PATH as Emscripten suggests.
-
Run:
cd examples cargo build --target=wasm32-unknown-emscripten rustc --target=wasm32-unknown-emscripten ../src/lib.rs -L ../target/wasm32-unknown-emscripten/debug/deps/