bytecodealliance / bytecodealliance/wit-bindgen

Document semantics of `use` in `deps/`

Open
#1,046 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.5k
Forks
286
Avg merge
6h 32m
Merged PRs (30d)
19

Description

I'd like to use `wit-bindgen` to generate Rust bindings for `wasi:cli/run@0.2.1`, but I'm confused about the semantics of the `use` statement from within a dependency, and would like to at least clarify the documentation.

Here's what I did:

1. Start by copying all the WIT files in [this directory](https://github.com/WebAssembly/WASI/tree/v0.2.1/wasip2/cli) to a local directory called `wit/`, and try to generate the bindings with `wit-bindgen rust wit/ --world command`. This fails with `package not found` ... `wasi:io/imports@0.2.1` (imported [here](https://github.com/WebAssembly/WASI/blob/v0.2.1/wasip2/cli/imports.wit#L14)).
2. Try creating a subdirectory in `wit/` called `deps/`, and copy the WIT file contents of [the IO directory](https://github.com/WebAssembly/WASI/tree/v0.2.1/wasip2/io) there. Running the same `wit-bindgen` command, now I get a new error: ``interface or world `error` not found in package`` (referring to [this line](https://github.com/WebAssembly/WASI/blob/v0.2.1/wasip2/io/streams.wit#L11)).

Here's the directory structure for reference. File 1 (imports.wit) references file 2 (deps/world.wit), which references file 3, which should reference 4, but `wit-bingen` if failing to resolve that last one.

```
.
└── wit
├── command.wit
├── deps
│   ├── error.wit # 4. Contains definition of error type
│   ├── poll.wit
│   ├── streams.wit # 3. use error.{error}
│   └── world.wit # 2. import streams
├── environment.wit
├── exit.wit
├── imports.wit # 1. include wasi:io/imports@0.2.1 (from deps/world.wit)
├── run.wit
├── stdio.wit
└── terminal.wit
```

I'm not sure how to proceed since the structure of the `deps/` subfolder is under-documented, especially how it relates to the 3 different types of external references in WIT: `include`, `import`, and `use`. The world called `error` is found in the same package as `streams.wit`, yet `wit-bindgen` cannot find it. I also tried moving it to the top-level `wit/` directory (and changing the package name), but that didn't work either.

What am I doing wrong?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.