It's just too complex to make Rust+WASM work on macOS, but all the other guides online target macOS. This guide targets only Arch Linux. If your favorate distro is great, you should be able to do the same thing.
Install rustup and emscripten with the distro's native package manager. Then install stable Rust and wasm target with Rustup.
# pacman -S rustup emscripten
$ rustup update stable
$ rustup target add wasm32-unknown-emscripten
Now, logout and re-login to make /etc/profile.d/emscripten.sh
in effect.
$ cargo init --bin hello
$ cd hello
$ rustc --target=wasm32-unknown-emscripten src/main.rs -o main.html
$ emrun main.html # Spin up a server and open your default browser
The rustc
step may fail, if you are using Emscripten Port version 37.
This will be fixed in future releases of Emscripten Port,
which means, you may need to follow the error messages and
patch the code yourself according to WebAssembly/binaryen#1196.
After trying out these steps (and failing), I found that there is an official rustwasm team that maintains a tool called wasm-pack which works quite well out of the box on Arch Linux.
Moreover, as of 2020 Emscripten is on version 2 and latest Rust only plays well with version 1.39.0 of Emscripten. Due to this it is not a viable option on Arch Linux, as pacman only lists latest Emscripten versions and getting the older version is non-trivial to the point of being virtually impossible to implement in any sane dev environment.