Skip to content

Language reference: Update WebAssembly example on how to export a function to the host #14818

@jameshfisher

Description

@jameshfisher

Zig Version

0.11.0-dev.1862+e7f128c20

Steps to Reproduce and Observed Behavior

Install above version of zig, and follow the exact steps in the WebAssembly documentation.

You will get:

$ node test.js
/Users/jim/dev/tmp/test-wasm-bug/test.js:10
  add(1, 2);
  ^

TypeError: add is not a function
    at /Users/jim/dev/tmp/test-wasm-bug/test.js:10:3

Node.js v19.5.0

This is because the built math.wasm is basically empty:

$ npm i wabt
$ npx wasm2wat math.wasm
(module
  (memory (;0;) 16)
  (global $__stack_pointer (mut i32) (i32.const 1048576))
  (export "memory" (memory 0)))

I know this worked on a zig 0.10.x build.

Expected Behavior

The output shown in the documentation:

$ node test.js
The result is 3

Metadata

Metadata

Assignees

No one assigned

    Labels

    contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.docsregressionIt worked in a previous version of Zig, but stopped working.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions