Skip to content

Tail-Wag-Games/wasmrt

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wasmrt Build Status

Disclaimer. This is a proof of concept, use with caution.

Compile nim to wasm

import wasmrt
proc consoleLog(a: cstring) {.importwasmraw: "console.log(_nimsj($0))".}
consoleLog("Hello, world!")
nim c --out:test.wasm test.nim # Special nim config is required, see below
node tests/runwasm.js test.wasm

Prerequisites

  • clang 8.0 or later
  • Special Nim config, like this one
  • [Optional] wasm-gc - a tool to compact your wasm file

Run your wasm

The wasm file generated this way is pretty standalone, and requires only the following JavaScript code to bootstrap:

function runNimWasm(w){for(i of WebAssembly.Module.exports(w)){n=i.name;if(n[0]==';'){new Function('m',n)(w);break}}}

runNimWasm takes the output of WebAssembly.compile function. E.g. to run a wasm file in nodejs, use smth like runwasm.js

Caveats

  • Exceptions work with --exceptions:goto.
  • Orc GC should work. But default GC should be disabled on start, and should be run carefully close to the stack bottom, otherwise it can collect live references.

Why no Emscripten?

The goal of this project is to produce self-contained standalone wasm files from nim code, without any JS glue, or "desktop platform emulation".

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Nim 99.3%
  • JavaScript 0.7%