Transforming Modules
Setup Instructions
JavaScript Coding
const loweredWasmBytes = await lowerI64Imports(wasmBytes)const fs = require("fs")
const { WASI } = require("@wasmer/wasi")
const nodeBindings = require("@wasmer/wasi/lib/bindings/node");
const { lowerI64Imports } = require("@wasmer/wasm-transformer")
const wasmFilePath = "./clocktimeget.wasm"
// Instantiate a new WASI Instance
let wasi = new WASI({
args: [wasmFilePath],
env: {},
bindings: {
...(nodeBindings.default || nodeBindings),
fs: fs
}
})
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Async function to run our Wasm module/instance
const startWasiTask =
async pathToWasmFile => {
// Fetch the Wasm module and transform its interface
let wasmBytes = new Uint8Array(fs.readFileSync(pathToWasmFile))
let loweredWasmBytes = lowerI64Imports(wasmBytes)
// Instantiate the WebAssembly file
let wasmModule = await WebAssembly.compile(wasmBytes);
let instance = await WebAssembly.instantiate(wasmModule, {
...wasi.getImports(wasmModule)
});
// Start the WASI instance
wasi.start(instance)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Everything starts here
startWasiTask(wasmFilePath)Last updated