1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Setup Rust for WebAssembly

    Nik GrafNik Graf
    rustRust
    javascriptJavaScript

    In order to setup a project we need to install the nightly build of Rust and add the WebAssembly target. For an improved workflow we also install the CLI tools wasm-pack and wasm-gc.

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    Instructor: In order to get started, we need to install Rust using the installer, rustup. Introductions on how to set it up can be found on rustup.rs. If you are on OSX, you also can use brew install rustup. Then we run rustup-init.

    Once we have Rust in our system, want to set the nightly toolchain as the default. We need to do this since currently only the nightly toolchain is supporting WebAssembly. Then we add the target wasm32-unknown-unknown.

    Usually, you would add targets like x68_64-apple-darwin, specifying the target platform. Since WebAssembly is not compiled against any specific platform, these two values after the first dash are unknown and unknown.

    In addition, we use Cargo, Rust's package manager, to install wasm-pack. This tool seeks to be the one-stop shop for building and working with Rust-generated WebAssembly that you would like to interop with JavaScript in the browser or with Node.js.

    For the first couple lessons, we don't use wasm-pack. Instead, we're going to use a tool called wasm-gc. We install it. wasm-gc is a tool to remove all unneeded exports, imports, functions, and so on from a WebAssembly module.

    Last but not least, we need a web server. We use Cargo to install the HTTPS crate, shipping with the HTTP binary. It runs a web server, serving static files from the current directory, exactly what we need in our first couple lessons.

    Discuss

    Discuss