Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
/ rustwasmc Public archive

Tool for building Rust functions for Node.js. Combine the performance of Rust, safety and portability of WebAssembly, and ease of use of JavaScript.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

second-state/rustwasmc

rustwasmc

Rust compiler toolkit for WebAssembly apps in the WasmEdge Runtime

npm npm GitHub language count GitHub top language

Developers: Getting started with the Second State Functions (a serverless FaaS service), Tencent Serverless Functions for AI inference, or your own Node.js server.

About

A one-stop tool for building Rust functions into WebAssembly for deployment on the WasmEdge Runtime.

Prerequisite

You will need to install the Rust compiler in order to use rustwasmc. Currently, we support up to Rust 1.50.0.

$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
$ source $HOME/.cargo/env

Install

From Linux command line

$ curl https://raw.githubusercontent.com/second-state/rustwasmc/master/installer/init.sh -sSf | sh

From NPM and Node.js

$ npm install -g rustwasmc # Append --unsafe-perm if permission denied

Usage

To build Rust functions for Node.js applications, use the following command. See a template application. The rustwasmc compiles and generates the wasm file, and the corresponding JavaScript file to call wasm functions from JavaScript. If the rust package contains only binary crate(s) and there are no library crate, the build command will only generate a wasm-wasi file for running as a standalone command program in the WasmEdge VM.

$ rustwasmc build

In most cases, you will want to enable AOT optimization in order to improve performance.

$ rustwasmc build --enable-aot

If you would like to use WasmEdge's extended APIs including Tensorflow, enable the extensions. Make sure that you install the wasmedge-extensions NPM module in this case.

$ rustwasmc build --enable-aot --enable-ext

To build Rust functions for Deno applications, use the following command. See a template application.

$ rustwasmc build --target deno

By default, rustwasmc will generate a directory for it's build output called pkg. If you'd like to customize this you can use the --out-dir flag.

$ rustwasmc build --out-dir out

Use clean subcommand to remove pkg and target directories.

$ rustwasmc clean

Logging

rustwasmc uses env_logger to produce logs when rustwasmc runs.

To configure your log level, use the RUST_LOG environment variable. For example:

$ RUST_LOG=info rustwasmc build

Known issues

For Rust version 1.51 and above, rustwasmc generates bytecode without WASI support. That means programs that access the file system, date and time, environment variables, and command line arguments would fail on Rust 1.50+. This should not affect most application use cases. We are working on a solution.

Acknowledgment

This project is derived from the open source wasm-pack.