bytecodealliance / bytecodealliance/wit-bindgen
Rust: two `generate!` macros in same module gives compilation error
- Dominant language
- Rust
- Stars
- 1.5k
- Forks
- 286
- Avg merge
- 6h 32m
- Merged PRs (30d)
- 19
Description
Consider a Rust file with two `generate!` macros:
```rust
wit_bindgen::generate!({
inline: r#"
package test:test-useful;
world t {
import useful:thingy/this-is-terribly-exciting@0.0.1;
}
"#,
path: "useful_thingy_0_0_1.wasm",
world: "test:test-useful/t",
generate_all
});
wit_bindgen::generate!({
inline: r#"
package test:test-useless;
world t {
import useless:feature/the-useless-thing@0.0.1;
}
"#,
path: "useless_feature_0_0_1.wasm",
world: "test:test-useless/t",
generate_all
});
```
When I build this, I get redefinition errors:
```
error[E0428]: the name `__WIT_BINDGEN_COMPONENT_TYPE` is defined multiple times
--> /home/ivan/testing/composy-build-script-madness/comp-consumer-build-rs-test/target/wasm32-wasip2/release/build/comp-consumer-build-rs-test-ad279f1832015f79/out/biscuits.rs:18:1
|
3 | wit_bindgen::generate!({
| ----------------------- previous definition of the value `__WIT_BINDGEN_COMPONENT_TYPE` here
...
18 | wit_bindgen::generate!({
| ^^^^^^^^^^^^^^^^^^^^^^^ `__WIT_BINDGEN_COMPONENT_TYPE` redefined here
|
= note: `__WIT_BINDGEN_COMPONENT_TYPE` must be defined only once in the value 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)
error[E0428]: the name `__link_custom_section_describing_imports` is defined multiple times
--> /home/ivan/testing/composy-build-script-madness/comp-consumer-build-rs-test/target/wasm32-wasip2/release/build/comp-consumer-build-rs-test-ad279f1832015f79/out/biscuits.rs:18:1
|
3 | wit_bindgen::generate!({
| ----------------------- previous definition of the value `__link_custom_section_describing_imports` here
...
18 | wit_bindgen::generate!({
| ^^^^^^^^^^^^^^^^^^^^^^^ `__link_custom_section_describing_imports` redefined here
|
= note: `__link_custom_section_describing_imports` must be defined only once in the value 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)
```
I can work around this by putting the `generate!` macros in different modules, but this adds to the already very lengthy prefixes for the functions and types in the imported interfaces.
It would be nice if I could have multiple `generate!` macros in the same module.
Please let me know if you need more details or a full repro!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.