Skip to content

beef331/wasm3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wasm3

Nim bindings of the lovely wasm3 Wasm runtime.

How to use?

add this to your project's .nimble file:

requires "https://github.com/beef331/wasm3 >= 0.1.1"

then run nimble install -d

Then a basic program with can be written as follows:

import unittest
import wasm3
let
  env = loadWasmEnv(readFile"maths.wasm")
  addFunc = env.findFunction("add")
  multiplyFunc = env.findFunction("multiply")
check addFunc.call(int32, 3i32, 4i32) == 7i32
check multiplyFunc.call(int32, 3i32, 4i32) == 12i32

If your Wasm file or application requires Wasi you can compile with -d:wasm3HasWasi and then use any of the Wasi procedures.

These bindings have some high level wrappings done inside wasm3 If one wants low level control one can always import wasm3/wasm3c and use the bindings directly.

How to compile Nim code to work with the runtime?

Emscripten

Install emscripten then use this config. For emscripten you can use wasm3/exporter utillities to export code to the runtime.

Nlvm

You can follow the instructions here though the Nlvm stdlib does not support WASI at the time of writing.

example wasm

You can build the example maths.wasm (if you have emscripten installed) with this command:

nim c wasmsources/maths.nim

How Wasm3 is compiled?

Wasm3 is a git submodule and compiled directly using Nim's {.compile.}. There are no dynamic or static libraries as it is included directly as C source code. Wasm3 is licensed under the MIT license as are these bindings.

About

Yet another wasm runtime to toy with

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages