Skip to content

Rust: two generate! macros in same module gives compilation error #1395

@itowlson

Description

@itowlson

Consider a Rust file with two generate! macros:

wit_bindgen::generate!({
    inline: r#"
    package test:test-useful;
    world t {
        import useful:thingy/[email protected];
    }
    "#,
    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/[email protected];
    }
    "#,
    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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    gen-rustRelated to bindings for Rust-compiled-to-WebAssembly

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions