No description
Find a file
Yuriy Glukhov b855ab736e Cosmetics
2025-10-01 10:21:07 +02:00
.github/workflows CI fix (#8) 2023-11-23 12:25:29 +02:00
tests Use musl libc headers 2025-08-11 13:24:21 +02:00
wasmrt Cosmetics 2025-10-01 10:21:07 +02:00
.gitignore Some additions, CI 2022-02-23 12:12:35 +02:00
LICENSE Initial commit 2018-10-17 19:28:50 +03:00
README.md Mention wasm2html in the README 2025-08-07 15:07:31 +02:00
wasmrt.nim Use musl libc headers 2025-08-11 13:24:21 +02:00
wasmrt.nimble wasm2html added to bin 2023-11-23 11:17:24 +01:00

wasmrt CI nimble

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-opt - 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

Convert wasm to html

The generated wasm file can be "converted" to a standalone html file with wasm2html tool provided in this package.

nim c --out:test.wasm test.nim # Special nim config is required, see below
wasm2html test.wasm test.html

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".