Throughout our examples, we make extensive use of the rustwasmc tool. It is inspired by the wasm-pack project but is optimized for edge cloud and device applications. Specifically, it supports the WasmEdge WebAssembly virtual machine.
rustwasmc depends on the Rust cargo toolchain to compile Rust source code to WebAssembly. You must have Rust installed on your machine.
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh $ source $HOME/.cargo/env $ rustup override set 1.50.0
The easiest way to install rustwasmc is to use its installer.
$ curl https://raw.githubusercontent.com/second-state/rustwasmc/master/installer/init.sh -sSf | sh
Alternatively, you can install using the NPM if you'd like.
$ rustwasmc build
--enable-ext flag to compile Rust programs that use WASI extensions, such as WasmEdge's storage, native command and tensorflow APIs. The
rustwasmc will run the compiled WebAssembly bytecode program in the
ssvm-extensions Node.js module instead of plain
ssvm in this case.
$ rustwasmc build --enable-ext
To build Rust functions for Deno applications, use the following command. See a template application.
$ rustwasmc build --target deno
A key feature of the SSVM is its support for Ahead-of-Time (AOT) compilers. When you run WebAssembly programs in Node.js
ssvm-extensions add-ons, you typically do not need to worry about it as the add-on handles AOT compilation transparently. However, in some cases, you do want the
ssvmup to compile and generate native code for the program. An example is the Tensorflow as a Service template for Tencent Cloud.
Then, use the commands below to bring your operating system up to date with the latest developer tools. The commands here are tested on Ubuntu 20.04.
$ sudo apt-get update $ sudo apt-get -y upgrade $ sudo apt install build-essential curl wget git vim libboost-all-dev llvm-dev liblld-10-dev
Now, you can build the
.so files for the AOT native target like the following.
$ rustwasmc build --enable-aot