Skip to content

Latest commit

 

History

History

src.rs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Rust/WASM Build

Overview

This folder defines the main necessary Rust dependencies (in Cargo.toml) with the rust-verkle dependendy in its center.

For building the WASM code and managing the interactions between JavaScript/TypeScript and WASM wasm-pack is being used and will need a separate initial installation.

Additionally wasm-bindgen-cli and (optional, for optimization) wasm-opt need to be installed.

The WASM build process follows the "Compiling from Rust to WASM" Mozilla web docs tutorial which can be used for an introduction to the topic.

Low Level API

The low level API for the interaction with the WASM code is written in Rust and located in the ./src subfolder and looks like the following:

#[wasm_bindgen]
pub fn element_sub(lhs: ElementWrapper, rhs: ElementWrapper) -> ElementWrapper {
    ElementWrapper {
        inner: lhs.inner - rhs.inner,
    }
}

These API elements are compiled during the wasm-pack build process (see below) and exposed in JavaScript/TypeScript as the final low level API.

Compile Rust to WASM

For an ESM build run:

wasm-pack build

You should see a pkg folder appear.

To build a Node.js compatible module run:

wasm-pack build --target nodejs