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:
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
@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.
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.
@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
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.
I think there is info here
https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md#top-level-use
alisomay has marked this topic as resolved.
Last updated: Nov 22 2024 at 16:03 UTC