Stream: wit-bindgen

Topic: export parameter required


view this post on Zulip James (Jul 31 2023 at 04:56):

Hi, I'm using the latest main branch of wit-bindgen to try the new resource type. I created the wit file:

package foo:bar

world plugin {
  record x {
    y: u32
  }

  export foo: func(bar: x)
}

But when I used wit_bindgen::generate! to generate the bindings, it gave the error:

export parameter required for `world` ...

The error does not happen on 0.9. Is there anything changed in the syntax? (I've checked the component-model proposal but didn't find changes related to this).

view this post on Zulip Ramon Klass (Jul 31 2023 at 07:46):

https://bytecodealliance.zulipchat.com/#narrow/stream/223391-wasm/topic/wit-bindgen.20and.20wizer.20mapdir/near/378970179

view this post on Zulip Ramon Klass (Jul 31 2023 at 07:48):

the bindgen macro has changed on main, you now have to specify the struct that will impl the trait in the macro call so that more boilerplate can be generated, this is needed for resources

view this post on Zulip Ramon Klass (Jul 31 2023 at 07:51):

but that message confused me too, "export required" could be more verbose to tell you that the bindgen macro call is missing info, not the wit file

view this post on Zulip James (Aug 02 2023 at 07:33):

Thanks for the info. So I think all the types exported must have a struct specified in the macro. But how does wit-bindgen decide which types/resources are exported?

If I have

package foo:bar

interface callback-types {
  resource callback {
    call: func() -> u32
  }
}

world plugin {
  export callback-types
}

Then wit-bindgen generates callback as a trait which I can implement. But
when I change it to

package foo:bar

interface callback-types {
  resource callback {
    call: func() -> u32
  }
}

world plugin {
  use callback-types.{callback}
  export callback-types

  import register-callback: func(callback: callback)
  export run: func()
}

Then wit-bindgen somehow assumes that callback is a type import from the host. Is this intended?


Last updated: Nov 22 2024 at 16:03 UTC