Is there a way to get more information from this compile error? I'm following the wasm component tutorial, my other component package this depends on compiles just fine.
[package.metadata.component]
package = "component:add"
[package.metadata.component.dependencies]
"component:ctx" = { path = "../ctx/wit" }
> cargo component build --release --target wasm32-unknown-unknown
error: failed to create a target world for package `add` (/Users/choc/code/bms-engine/add/Cargo.toml)
Caused by:
0: failed to decode component dependency `component:ctx`
1: dependency is not a WebAssembly component
Okay... the tutorial had more misleading examples.
It shows
[package.metadata.component.target.dependencies]
"docs:adder" = { path = "../adder/wit" } # directory containing the WIT package
Which does not work with the package/component generated from cargo component new
. It needs to specify the full path to the .wasm file according to https://github.com/bytecodealliance/cargo-component/issues/120#issuecomment-1684740622 which then allowed it to compile successfully
Now struggling to import the component in wit :/ everything looks fine, the bindings were updated and I can reference the imported functions in code but building the component is failing, I don't know why it can't find the package.
package component:add;
/// An example world for the component to target.
world example {
export hello-world: func() -> string;
import component:ctx/program-ctx@0.1.0;
}
> cargo component build --release --target wasm32-unknown-unknown
error: failed to create a target world for package `add` (/Users/choc/code/bms-engine/add/Cargo.toml)
Caused by:
0: failed to merge local target `/Users/choc/code/bms-engine/add/wit`
1: package 'component:ctx@0.1.0' not found. no known packages.
--> /Users/choc/code/bms-engine/add/wit/world.wit:6:12
|
6 | import component:ctx/program-ctx@0.1.0;
From
> wasm-tools component wit target/wasm32-unknown-unknown/release/ctx.wasm
package root:component;
world root {
export component:ctx/program-ctx@0.1.0;
}
package component:ctx@0.1.0 {
interface program-ctx {
read-point: func(point: s32) -> result<s32, bool>;
write-point: func(point: s32, value: s32) -> result<bool, bool>;
}
}
Because there's no
.wit
file,Cargo.toml
doesn't contain apackage.metadata.component.target
section.
This is also seemingly incorrect, no such section was generated from cargo component new foo --lib
.
Ok it took me waaaay to long to figure this out lol... had me questioning a lot of things
cargo component new --lib
generates with this section for dependencies
[package.metadata.component.dependencies]
So I was trying to put my components in there, and so nothing was working.. but when I put the full wasm path in the dependency there, the bindings started working, so I thought I had the right place. Only after re-reading more stuff and generating extra test components did I realise there's a very similar looking path with an extra target
which I still don't understand the difference of.
[package.metadata.component.target.dependencies]
Hey @Trent thanks for going through this -- it really illuminated how the tools can be hard to wokr with/it's not clear exactly where to make the changes.
Could you link to which tutorial you were looking at? I'd like to update it.
Actually even better would be (if you were up to it) if you were to contribute the updates -- I think exactly where you got stuck a LOT of newer/less determined people would get stuck and quit -- would be a huge help to have better docs around that.
Last updated: Dec 23 2024 at 13:07 UTC