WebAssembly is, supported by 40 high-level programming languages including C and C++, Python, Go, Rust, Java, and PHP.
But Rust with wasm amalgamation is considered the deadly one.
You can check out his Blog: WebAssembly x Rust, a Deadly Combination! by @aryank21 for interesting facts about rust.
So let's move towards the coding part before starting you have to install the following:
Environment setup
1. Install Rust
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
For more details or manual download visit the official site.
2. Install Wasmtime
Runtime for webAssembly and WASI
$ curl https://wasmtime.dev/install.sh -sSf | bash
3. Install the WebAssembly Rust toolchain:
rustup target install wasm32-wasi
4. Code Snippets
Create a new project with cargo new <project_name>
and switch to the hello-rust
directory using the command below:
# Here my file name is hello-rust
cargo new hello-rust
cd hello-rust
Inside main.rs
file paste the bellow code:
// Program to print Hello, world!
fn main() {
println!("Hello, Rust!");
}
5. Compiling Rust Code
- Compile using cargo
cargo build
cargo run
- Compile to wasm
cargo build --target=wasm32-was --release
- Wasm runtime
wasmtime target/wasm32-wasi/release/hello-rust.wasm
So it was that easy isn't it in just 5 simple steps!!
Oldest comments (0)