bytecodealliance / bytecodealliance/wasm-tools
"component is not compatible with import" error is returned when combining components with resources using dependencies
- Dominant language
- Rust
- Stars
- 1.8k
- Forks
- 351
- Avg merge
- 16h 57m
- Merged PRs (30d)
- 38
Description
Repository: https://github.com/andrzejressel/wasm-tools-compose-resources-bug-report
I have WIT structure that looks like this:
```mermaid
stateDiagram-v2
[*] --> main
main --> a
main --> b
a --> b
```
`b` is also implementing resource type that is used in the whole tree. Repository after compiling
```
cargo component build -p main -p aimpl -p bimpl
```
is generating `main.wasm`, `aimpl.wasm` and `bimpl.wasm`. Everything works fine when I combine them manually:
```
wasm-tools compose -o target/wasm32-wasi/debug/composed1.wasm target/wasm32-wasi/debug/main.wasm -d target/wasm32-wasi/debug/aimpl.wasm
wasm-tools compose -o target/wasm32-wasi/debug/composed2.wasm target/wasm32-wasi/debug/composed1.wasm -d target/wasm32-wasi/debug/bimpl.wasm
wasm-tools component wit target/wasm32-wasi/debug/composed2.wasm
```
Output:
```
world root {
import wasi:cli/environment@0.2.0;
import wasi:cli/exit@0.2.0;
import wasi:io/error@0.2.0;
import wasi:io/streams@0.2.0;
import wasi:cli/stdin@0.2.0;
import wasi:cli/stdout@0.2.0;
import wasi:cli/stderr@0.2.0;
import wasi:clocks/wall-clock@0.2.0;
import wasi:filesystem/types@0.2.0;
import wasi:filesystem/preopens@0.2.0;
export example:service/main-interface@0.1.0;
}
```
However in my real project the graph will be more complicated so I've decided to try using config file. For this example it looks like this
```
dependencies:
# "example:service/my-resource@0.1.0": target\wasm32-wasi\debug\bimpl.wasm
"example:service/a-interface@0.1.0": target\wasm32-wasi\debug\aimpl.wasm
"example:service/b-interface@0.1.0": target\wasm32-wasi\debug\bimpl.wasm
```
With `my-resource` commented out I would expect to get single component with `my-resource` import and with it uncommented I'd expect single component with only `wasi` import. However I'm receiving following error:
```
> wasm-tools compose -c config.yml target\wasm32-wasi\debug\main.wasm -o output.wasm
[2024-03-13T02:49:48Z WARN ] instance `example:service/my-resource@0.1.0` will be imported because a dependency named `example:service/my-resource@0.1.0` could not be found
error: component `target\wasm32-wasi\debug\bimpl.wasm` is not compatible with import `example:service/b-interface@0.1.0` of component `target\wasm32-wasi\debug\main.wasm`
```
The same config worked fine before implementing resources.
Contributor guide
Assessment
This issue has not been assessed yet.