Cannot generate Rust bindings for worlds with overlapping exports in the same crate using `pub_export_macro: true`

未關閉
#1,502 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
45/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
rust, wasm
領域
tooling

研究方向

首先執行內嵌 Rust reproducer,並檢查設定 pub_export_macro: true 時 wit_bindgen::generate 的展開情況。追蹤匯出的巨集如何命名,以及它們在各模組之間的作用域;完成標準是兩個 generate! 呼叫都能在沒有重複巨集定義的情況下編譯。

由索引模型根據 Issue 內容生成。

描述

gen-rust

This input:

mod a {
    wit_bindgen::generate!({
        inline: r#"
            package a:b;

            interface foo {
                x: func();
            }

            world a {
                export foo;
            }
        "#,
        world: "a",
        pub_export_macro: true,
    });
}

mod b {
    wit_bindgen::generate!({
        inline: r#"
            package a:b;

            interface foo {
                x: func();
            }

            interface bar {
                x: func();
            }

            world b {
                export foo;
                export bar;
            }
        "#,
        world: "b",
        pub_export_macro: true,
    });
}

fn main() {}

fails with:

error[E0428]: the name `__export_a_b_foo_cabi` is defined multiple times
  --> src/main.rs:20:5
   |
 2 |     wit_bindgen::generate!({
   |     ----------------------- previous definition of the macro `__export_a_b_foo_cabi` here
...
20 |     wit_bindgen::generate!({
   |     ^^^^^^^^^^^^^^^^^^^^^^^ `__export_a_b_foo_cabi` redefined here
   |
   = note: `__export_a_b_foo_cabi` must be defined only once in the macro namespace of this module
   = note: this error originates in the macro `wit_bindgen::generate` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0428`.
error: could not compile `wat` (bin "wat") due to 1 previous error

Basically we need to do more namespacing/scoping of macros that avoids #[macro_export]. I couldn't figure it out earlier but it's probably possible nowadays.

主要語言
Rust
星號
1.5k
分支
306
平均合併
1 天 4 小時
30 天內合併 PR
21

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 沒有貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

bytecodealliance/wit-bindgen 的其他 Issue

查看 bytecodealliance/wit-bindgen 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。