parasyte added the bug label to Issue #9294.
parasyte opened issue #9294:
Test Case
use wasmtime::component::bindgen; bindgen!({ // WIT from https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md#package-format // Amendment: added the `world local` section to make bindgen happy. inline: " package local:demo; interface types { resource file { read: func(off: u32, n: u32) -> list<u8>; write: func(off: u32, bytes: list<u8>); } } interface namespace { use types.{file}; open: func(name: string) -> file; } world local { export namespace; } ", include_generated_code_from_file: true, }); fn main() {}
Steps to Reproduce
bindgen!
generates a zero-variant enum for each resource in a WIT. I.e. the type is impossible to instantiate. To verify I'm not insane, I tried using a WIT from documentation, which is shown above, and the source of the WIT is the linked documentation.The Rust code output by
bindgen
includes:pub enum File {}
A
File
cannot be instantiated, so how is thenamespace.open()
function supposed to return one? And for that matter, how are theFile.read()
andFile.write()
implementations supposed to accept a reference to aFile
that can't be created?This never type is created here:
Expected Results
I would like the ability to construct the resources I'm defining in WIT.
Actual Results
File
cannot be constructed.Versions and Environment
Wasmtime version or commit:
25.0.0
Operating system: Windows 11
Architecture: x86_64
Extra Info
Shouldn't this be a compile time error instead of an unusable type?
alexcrichton commented on issue #9294:
Thanks for the report! This example in the documentation might help you here, the key thing being the
with
key indicating your own type to use instead of the empty enum type.This is something where the defaults of
bindgen!
aren't great where we should probably requirewith: { ... }
by default rather than generating this empty enum which is more-or-less unusable.
parasyte commented on issue #9294:
That could be exactly what I'm missing! I saw the other code path in
bindgen!
that imports an existing type by path but had no idea how to trigger it.
Last updated: Nov 22 2024 at 16:03 UTC