-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
Zig Version
0.11.0-dev.1017+d86685ac9
Steps to Reproduce and Observed Behavior
I'm running a MacBook Pro 16-inch from 2019 with macOS Ventura 13.1.
-
Install the latest version of Zig for macOS using Homebrew:
$ brew install zig --HEAD
-
Create an
add.zigfile having this code:export fn add(x: i32, y: i32) i32 { return x + y; }
-
Compile it to Wasm:
$ zig build-lib add.zig -target wasm32-freestanding -dynamic
-
Inspect the generated Wasm file with
wasm2wat:$ wasm2wat add.wasm (module (memory (;0;) 16) (global $__stack_pointer (mut i32) (i32.const 1048576)) (export "memory" (memory 0)))
Notice the
add()function is missing ! -
However, if we recompile while forcing the export with
--export=addit will work. For brevity of output, let's also use-O ReleaseSmall:$ zig build-lib add.zig -target wasm32-freestanding -dynamic -O ReleaseSmall --export=add
-
Again, inspect the generated Wasm with
wasm2wat:$ wasm2wat add.wasm (module (type (;0;) (func (param i32 i32) (result i32))) (func (;0;) (type 0) (param i32 i32) (result i32) local.get 1 local.get 0 i32.add) (memory (;0;) 16) (global (;0;) (mut i32) (i32.const 1048576)) (export "memory" (memory 0)) (export "add" (func 0)))
Finally a good result but we were forced to export explicitly on the command line. This would be a pain if we had many things to export.
Expected Behavior
My expectation is that running:
$ zig build-lib add.zig -target wasm32-freestanding -dynamicwill produce a Wasm file that includes the add() function.
To put it in general terms, all exports should actually be exported by default.