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

Đang mở
#1,502 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust, wasm
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu bằng cách chạy inline Rust reproducer và kiểm tra quá trình mở rộng của wit_bindgen::generate với pub_export_macro: true. Theo dõi cách các macro được export được đặt tên và xác định phạm vi giữa các module; hoàn thành khi cả hai lệnh gọi generate! đều biên dịch mà không có các định nghĩa macro trùng lặp.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Rust
Star
1.5k
Fork
306
Merge trung bình
1 ngày 4 giờ
Pull request đã merge (30 ngày)
21

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

  • Không có Dockerfile hay tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của bytecodealliance/wit-bindgen

Tất cả issue của bytecodealliance/wit-bindgen

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.