bytecodealliance / wit-bindgen

A language binding generator for WebAssembly interface types

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ERROR produced when parsing resource in `generate!`

segeljakt opened this issue · comments

Hi, I tried to run this:

wit_bindgen::generate!({
    inline: "package mypkg:mylib;

    interface myintf {
        resource image;
        load-image: func(bytes: list<u8>) -> image;
        resize-image: func(self: borrow<image>, width:u32, height:u32) -> image;
        image-to-bytes: func(self: borrow<image>) -> list<u8>;
    }

    world mylib {
        export myintf;
    }",
    exports: {"mypkg:mylib/myintf": Component},
});

But I get the error:

unresolved import `super::super::super::super::ERROR`
no `ERROR` in the root [E0432]

When inspecting the generated code, it appears to generate:

pub mod exports {
  pub mod mypkg {
    pub mod mylib {
      #[allow(clippy::all)]
      pub mod myintf {
        #[used]
        #[doc(hidden)]
        #[cfg(target_arch = "wasm32")]
        static __FORCE_SECTION_REF:fn() = super::super::super::super::__link_section;
        pub use super::super::super::super::ERROR as Image;
        // ...
      }
    }
  }
}

Am I doing something wrong? It works well when using cargo component build

Oh, nevermind. I see now that I forgot to export Image:

wit_bindgen::generate!({
    inline: "package mypkg:mylib;
 
    // ...

    exports: {
        "mypkg:mylib/myintf": Component,
        "mypkg:mylib/myintf/image": Image
    },
});