Stream: wasmtime

Topic: dependency is not a WebAssembly component


view this post on Zulip Trent (Dec 20 2024 at 06:20):

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

view this post on Zulip Trent (Dec 20 2024 at 06:27):

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

Hello developers, I'm trying to understand Component Model with cargo-component. To that end I have tried to create a simple example, but I have the following error and would like to discuss it if ...

view this post on Zulip Trent (Dec 20 2024 at 06:40):

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>;
  }
}

view this post on Zulip Trent (Dec 20 2024 at 06:45):

Because there's no .wit file, Cargo.toml doesn't contain a package.metadata.component.target section.

This is also seemingly incorrect, no such section was generated from cargo component new foo --lib.

view this post on Zulip Trent (Dec 20 2024 at 08:18):

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]

view this post on Zulip Victor Adossi (Dec 21 2024 at 03:12):

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