Skip to content

building wasm - zig build-lib file.c produces no result while zig translate-c file.c and zig build-lib file.zig does #13509

Description

@kfessel

Zig Version

0.10.0

Steps to Reproduce and Observed Behavior

have a c-file
try to create a wasm using:

zig build-lib --stack 4096 -target wasm32-freestanding -O ReleaseFast -dynamic -fstrip hello.c

the resulting wasm will not contain much

wasm2wat hello.wasm
(module
  (memory (;0;) 1)
  (global (;0;) (mut i32) (i32.const 4096))
  (export "memory" (memory 0)))

do the same in two steps:

zig translate-c --stack 4096 -target wasm32-freestanding -O ReleaseFast -dynamic -fstrip hello.c > hello.zig
zig build-lib --stack 4096 -target wasm32-freestanding -O ReleaseFast -dynamic -fstrip hello.zig

will succeed

$ wasm2wat hello.wasm
(module
  (type (;0;) (func (param i32 i32) (result i32)))
  (import "env" "printf" (func (;0;) (type 0)))
  (func (;1;) (type 0) (param i32 i32) (result i32)
    (local i32)
    global.get 0
    i32.const 32
    i32.sub
    local.tee 2
    global.set 0
    block  ;; label = @1
      block  ;; label = @2
        local.get 0
        i32.const 2
        i32.lt_s
        br_if 0 (;@2;)
        local.get 2
        local.get 1
        i32.load offset=4
        i32.store
        i32.const 4102
        local.get 2
        call 0
        drop
        br 1 (;@1;)
      end
      local.get 2
      i32.const 4096
      i32.store offset=16
      i32.const 4102
      local.get 2
      i32.const 16
      i32.add
      call 0
      drop
    end
    local.get 2
    i32.const 32
    i32.add
    global.set 0
    i32.const 0)
  (memory (;0;) 1)
  (global (;0;) (mut i32) (i32.const 4096))
  (export "memory" (memory 0))
  (export "main" (func 1))
  (data (;0;) (i32.const 4096) "World\00Hello %s\0a\00"))

if i do similar with without setting a target (->native or -> machine target) the result is a libhello.a containing the function

Expected Behavior

both ways of building have the same result
hello.c.txt

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-wasm32-bit and 64-bit WebAssemblybugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions