bytecodealliance / bytecodealliance/wit-bindgen

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

Offen
#1,502 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
gen-rust
Vorherrschende Sprache
Rust
Sterne
1.5k
Forks
286
Ø Merge
6 Std. 32 Min.
Gemergte PRs (30 T.)
19

Beschreibung

This input:

```rust
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.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Start by running the inline Rust reproducer and inspecting the expansion of wit_bindgen::generate with pub_export_macro: true. Trace how the exported macros are named and scoped across modules; done means both generate! invocations compile without duplicate macro definitions.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
rust, wasm
Bereich
tooling
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Aktiv
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.