Build Failure with Inline WIT with `wit-bindgen`

オープン
#188 コメント 6 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

  • #191 @tqwewe による — マージされずにクローズ

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
rust, wasm
領域
build-system, cli

調査の方向性

リンクされた再現リポジトリと、lib.rs 内の wit_bindgen::generate! のインライン定義から始め、続いてドキュメント化された手動の cargo/wasm-tools シーケンスと、guest package に対する 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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

bytecodealliance/cargo-component のほかの issue

bytecodealliance/cargo-component の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。