bytecodealliance / bytecodealliance/cargo-component
Build Failure with Inline WIT with `wit-bindgen`
- Dominant language
- Rust
- Stars
- 593
- Forks
- 68
- PR merge metrics
- No merged PRs in 30d
Description
## Description
There's an inconsistency when building a project with inline WIT definitions using `cargo component build`. It fails under `cargo component` but succeeds when manually building with `cargo` and `wasm-tools` with `wit-bindgen` given the following `lib.rs`:
```rust
wit_bindgen::generate!({
inline: r#"
package component:guest;
world example {
export example: interface {
hello-world: func() -> string;
}
}
"#,
exports: {
"example": Component
}
});
use exports::example::Guest;
struct Component;
impl Guest for Component {
fn hello_world() -> String {
"Hello, World!".to_string()
}
}
```
## Reproduction Steps
### Manual Build with Cargo and wasm-tools
1. Build for `wasm32-wasi` target:
```bash
cargo build --package guest --target wasm32-wasi
```
2. Create the component with wasm-tools:
```bash
wasm-tools component new ./target/wasm32-wasi/debug/guest.wasm -o ./target/wasm32-wasi/debug/guest.wasm --adapt ./wasi_snapshot_preview1.wasm
```
3. Run the host package and observe successful `Hello, World!` message:
```bash
cargo run --package host
```
### Build with Cargo Component
1. Clean previous builds:
```bash
cargo clean
```
2. Build with `cargo component`:
```bash
cargo component build --package guest
```
3. Observe failure when running the host package:
```bash
cargo run --package host
```
## Expected Behavior
Both build methods should successfully compile and run the project, displaying `Hello, World!` regardless if we use a `wit` directory with `cargo_component_bindings` or `wit-bindgen`.
## Actual Behavior
The build succeeds with manual steps but fails with `cargo component`.
## Additional Information
Repository Link: [GitHub Repository](https://github.com/tqwewe/cargo-component-issue)
Is this intended behaviour?
I think it would be ideal if we can just use cargo component with wit-bindgen as an easy way of building wasm components, though it seems like we need to stick to the structure of having a `wit` directory along side our `src` directory.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.