bytecodealliance / bytecodealliance/cargo-component

cargo-component cannot find exported function in a world

Open
#360 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
593
Forks
68
PR merge metrics
No merged PRs in 30d

Description

I am following https://component-model.bytecodealliance.org/language-support/rust.html#importing-an-interface-into-a-command-component to create a command component with `cargo-component`.

My adder WIT was:
```
package component:adder;

world adder {
export add: func(a: s32, b: s32) -> s32;
}
```

And my WIT for the host is

```
package component:host;

world host {
import component:adder/add;
}
```

I also added this to `Cargo.toml`
```toml
[package.metadata.component.target.dependencies]
"component:adder" = { path = "../guest-adder/wit" }
```

But when I ran `cargo component build`, I got
```shell
error: failed to create a target world for package `host-command-component` (/Users/zhiqiu/offline_code/opensource/wasi_mindmap/host-command-component/Cargo.toml)

Caused by:
0: failed to merge local target `/Users/zhiqiu/offline_code/opensource/wasi_mindmap/host-command-component/wit`
1: interface not found in package
--> /Users/zhiqiu/offline_code/opensource/wasi_mindmap/host-command-component/wit/host.wit:4:28
|
4 | import component:adder/add;
| ^--

```

This took me a while to debug, but in the end, I had to write my adder WIT like:

```
package component:adder;

interface add {
add: func(a: s32, b: s32) -> s32;
}

world adder {
export add;
}
```

So it has `add` interface exported, which has an `add` function.

I don't think the behavior of `cargo-component` is expected, as in a WIT file, a world can just simply export a function.

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.