Stream: wasi

Topic: ✔ WASI dependencies fail with cargo-component and wit-deps


view this post on Zulip Eduardo Rodrigues (Jul 21 2023 at 18:38):

The code here works with wasm-tools directly with wit-deps. When trying to use cargo-component, I am getting the following error:

error: failed to merge local target /wasm-web-shell/packages/wasi-cli/wit
Caused by:
package not found

Contribute to eduardomourar/wasm-web-shell development by creating an account on GitHub.

view this post on Zulip Eduardo Rodrigues (Jul 21 2023 at 18:41):

I would appreciate any pointer on how to have a reference to any of WASI's definition locally in cargo-component. Even better if there is a public registry with those definitions compatible with wasmtime v10.

view this post on Zulip Eduardo Rodrigues (Jul 22 2023 at 12:54):

It was a typo in the Cargo.toml file: [package.metadata.component.target.dependencies]

view this post on Zulip Notification Bot (Jul 22 2023 at 12:54):

Eduardo Rodrigues has marked this topic as resolved.

view this post on Zulip DougAnderson444 | PeerPiper.io (Dec 20 2023 at 17:58):

Is this wit/deps/... naming hardwired into wasmtime somewhere?

Because when I tried to use a relative directory for my wit package elsewhere on my system, wasmtime didn't react well to it:

[package.metadata.component.target.dependencies]
"seed-keeper:wallet" = { path = "../../crates/seed-keeper-wit/wit" }

Although I am able to cargo component build with the above config, when I try to use the component from a Rust host it breaks with error log:

error: failed to find package `seed-keeper:wallet@0.1.0` in `deps` directory
            --> /home/doug/code/rust/seed-keeper/examples/edwards-wit/wit/world.wit:11:12
             |
          11 |     import seed-keeper:wallet/seed-getter@0.1.0;
             |            ^-----------------

I spotted the "deps directory"
SO I copied-and-pasted the .wit to wit/deps/seed-keeper/wallet.wit, it worked, even with no config

[package.metadata.component.target.dependencies]
# removed

That's cool, but involves copy-pasta. I'm expecting to be able to import relative wits, based on the docs here:

https://component-model.bytecodealliance.org/language-support/rust.html#importing-an-interface-into-a-command-component

Not exactly sure where to raise this issue (or maybe I'm expecting behaviour that I shouldn't be)?

Insights are most welcome!

view this post on Zulip Lann Martin (Dec 20 2023 at 18:01):

Wasmtime itself isn't really WIT-aware, but the wit-parser library that cargo-component uses does hard-code "deps"

view this post on Zulip Lann Martin (Dec 20 2023 at 18:04):

Ohh you are using wasmtime::component::bindgen, which does depend on wit-parser as well.

view this post on Zulip Lann Martin (Dec 20 2023 at 18:05):

I was thinking of the wasmtime runtime, which doesn't know anything about WIT.

view this post on Zulip DougAnderson444 | PeerPiper.io (Dec 20 2023 at 18:05):

Yes, correct using wasmtime::component::bindgen!

view this post on Zulip Lann Martin (Dec 20 2023 at 18:05):

I imagine it is the host build that is breaking then, not the component.

view this post on Zulip DougAnderson444 | PeerPiper.io (Dec 20 2023 at 18:06):

Yes that sounds right. I can cargo component build just fine. But running breaks

view this post on Zulip DougAnderson444 | PeerPiper.io (Dec 20 2023 at 18:07):

So I suppose my question becomes is there a Host mechanism to use relative wit directories?

view this post on Zulip Lann Martin (Dec 20 2023 at 18:08):

I'm more surprised that cargo-component doesn't break; it should be calling roughly the same code as wasmtime bindgen.

view this post on Zulip Peter Huene (Dec 20 2023 at 18:08):

It doesn't; deps are explicitly listed in the target dependency table and it doesn't look at deps

view this post on Zulip DougAnderson444 | PeerPiper.io (Dec 20 2023 at 18:09):

So I wonder why I'm getting the error that states the missing wit from the deps directory

view this post on Zulip Peter Huene (Dec 20 2023 at 18:09):

if you want to "share" a deps directory between a standard wit-parser impl (i.e. wit-bindgen and the macro from wasmtime) and cargo-component, it's best to keep the dependency in deps and specify the path to cargo-component such that it points to that directory inside the deps dir

view this post on Zulip DougAnderson444 | PeerPiper.io (Dec 20 2023 at 18:10):

Could you show me an example of what you mean? It's a bit mind bending

view this post on Zulip Peter Huene (Dec 20 2023 at 18:11):

"seed-keeper:wallet" = { path = "../../crates/seed-keeper-wit/wit/deps/wallet" } (or whatever it was before you moved it)

view this post on Zulip DougAnderson444 | PeerPiper.io (Dec 20 2023 at 18:11):

Ahh I see what you mean, I can give that a try

view this post on Zulip DougAnderson444 | PeerPiper.io (Dec 20 2023 at 19:15):

I can't quite get that to work Peter, but I get the idea. I'll re-try when I've got a bit more time.

I need to correct my previous statement though -- I do need the [target.dependencies] for cargo component build to work.

view this post on Zulip DougAnderson444 | PeerPiper.io (Dec 20 2023 at 23:38):

Ok, I think I figured out how to use this "wit/deps/package-name" concept. It seems to help to break up wit into separate files for interfaces and worlds, to sort of logically separate things.


Last updated: Nov 22 2024 at 16:03 UTC