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
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.
It was a typo in the Cargo.toml file: [package.metadata.component.target.dependencies]
Eduardo Rodrigues has marked this topic as resolved.
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:
Not exactly sure where to raise this issue (or maybe I'm expecting behaviour that I shouldn't be)?
Insights are most welcome!
Wasmtime itself isn't really WIT-aware, but the wit-parser
library that cargo-component
uses does hard-code "deps"
Ohh you are using wasmtime::component::bindgen
, which does depend on wit-parser
as well.
I was thinking of the wasmtime runtime, which doesn't know anything about WIT.
Yes, correct using wasmtime::component::bindgen!
I imagine it is the host build that is breaking then, not the component.
Yes that sounds right. I can cargo component build
just fine. But running breaks
So I suppose my question becomes is there a Host mechanism to use relative wit
directories?
I'm more surprised that cargo-component doesn't break; it should be calling roughly the same code as wasmtime bindgen.
It doesn't; deps are explicitly listed in the target dependency table and it doesn't look at deps
So I wonder why I'm getting the error that states the missing wit from the deps
directory
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
Could you show me an example of what you mean? It's a bit mind bending
"seed-keeper:wallet" = { path = "../../crates/seed-keeper-wit/wit/deps/wallet" }
(or whatever it was before you moved it)
Ahh I see what you mean, I can give that a try
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.
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: Dec 23 2024 at 12:05 UTC