...

/

Converting Rust into WebAssembly via rustc

Converting Rust into WebAssembly via rustc

Learn how to convert Rust code into WebAssembly using the rustc command.

We'll cover the following...

Rust uses the LLVM compiler, which we’ll create now, in order to generate machine-native code. rustc uses LLVM’s capability to convert the native code into a WebAssembly module. Let’s start converting Rust into a WebAssembly module using rustc.

Getting started with the project

We’ll start with Hello World:

  1. Let’s create a file called hello_world.rs:

Press + to interact
touch hello_world.rs
  1. Start writing the Rust code:

Press + to interact
fn main() {
println!("Hello World!");
}

We have defined a main function. Similar to C, main is a special function that marks the entry point to a program after it has been compiled as an executable. fn ...