Build Failure with Inline WIT with `wit-bindgen`

未关闭
#188 6 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

  • #191 来自 @tqwewe —— 已关闭,未合并

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
rust, wasm
领域
build-system, cli

调研方向

从链接的复现仓库及其 lib.rs 中的 wit_bindgen::generate! 内联定义开始,然后为 guest package 运行文档中说明的手动 cargo/wasm-tools 序列和 cargo component build。比较运行 host package 时产生的行为;当两条构建路径都成功运行并显示“Hello, World!”时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

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:

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:
    cargo build --package guest --target wasm32-wasi
    
  2. Create the component with wasm-tools:
    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:
    cargo run --package host
    
Build with Cargo Component
  1. Clean previous builds:
    cargo clean
    
  2. Build with cargo component:
    cargo component build --package guest
    
  3. Observe failure when running the host package:
    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

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.

主要语言
Rust
星标
593
派生
68
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

bytecodealliance/cargo-component 的其他 Issue

查看 bytecodealliance/cargo-component 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。