Stream: wit-bindgen

Topic: ✔ using dependencies


view this post on Zulip alisomay (Jul 04 2023 at 14:35):

I'm having trouble to use generate! for the following wit files.
Reduced example:

wit a

package mynamespace:a

world myworld {
 use mynamespace:b/types.{my-type}
}

wit b

package mynamespace:b

interface types {
  record my-type{
    field: string,
  }
}

They're both in the wit folder.

generate!("myworld") macro errors with

       Caused by:
           package identifier `mynamespace:b` does not match previous package name of `mynamespace:a`
                --> ...
                 |
              10 | package mynamespace:b
                 |         ^------

This is a pattern which I've also seen in wasi wit files depending on eachother.
What am I doing wrong here?

Thanks :pray:

view this post on Zulip alisomay (Jul 04 2023 at 15:32):

The problem seems to be the package name.
If I change package mynamespace:b to package mynamespace:a then it resolves.
On the other hand that is the whole purpose.
Here I see that this scenario is documented as a valid test. I'm a bit confused.
https://github.com/bytecodealliance/wasm-tools/blob/main/crates/wit-parser/tests/ui/foreign-deps/root.wit

Low level tooling for WebAssembly in Rust. Contribute to bytecodealliance/wasm-tools development by creating an account on GitHub.

view this post on Zulip Guy Bedford (Jul 04 2023 at 17:02):

@alisomay wit packages are supposed to be in separate folders, otherwise you can also just use separate files in the same folder and refer to the interface by the same name.

view this post on Zulip alisomay (Jul 04 2023 at 17:29):

Guy Bedford said:

alisomay wit packages are supposed to be in separate folders, otherwise you can also just use separate files in the same folder and refer to the interface by the same name.

Thank you!
This is crucial information. I might have missed it in the documentation.
It seems that also the folder should be named deps.
Placing a.wit in the root and b.wit at deps/mynamespace/wit.b yields a different error which is rather cryptic.

error: failed to parse package: ..
       Caused by:
           no `package` header was found in any WIT file for this package

I'd be grateful if you point me to the right place in a documentation which explains the necessary structure to achieve this.

view this post on Zulip Guy Bedford (Jul 04 2023 at 17:30):

@alisomay when having separate folders, you must include the package mynamespace:a declaration at the top of at least one wit file in the folder

view this post on Zulip alisomay (Jul 04 2023 at 18:18):

Thank you.
I made it work with your suggestions.
I had also another issue since my real package name was annotated with a semver that also was creating an issue with the use statement.
What is a good way to import packages with semver annotations?

use foo:bar@0.1.0/an-interface.{a-type} does not work. (syntax error)

If we use

use foo:bar/an-interface.{a-type}
then the package can not be found.

view this post on Zulip alisomay (Jul 04 2023 at 18:36):

I think there is info here
https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md#top-level-use

Repository for design and specification of the Component Model - component-model/design/mvp/WIT.md at main · WebAssembly/component-model

view this post on Zulip Notification Bot (Jul 04 2023 at 18:37):

alisomay has marked this topic as resolved.


Last updated: Nov 22 2024 at 16:03 UTC