Stream: git-wasmtime

Topic: wasmtime / issue #8050 Component model: `bindgen!` with m...


view this post on Zulip Wasmtime GitHub notifications bot (Mar 05 2024 at 18:22):

miguelaeh added the bug label to Issue #8050.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 05 2024 at 18:22):

miguelaeh opened issue #8050:

It does not seem to be possible to import two worlds in the same Rust file.

When the two worlds are part of the same WIT package, bindgen! allows you to select only one, and if you use the macro twice with different world names the package export gets duplicated.

If you add the two worlds to different packages in the WIT files and try to use bindgen! for each of them on the same Rust file, you get the error: the name exports is defined multiple times.

Is it possible to do this in some way that I am missing?

Test Case

Any file that defines two worlds

Steps to Reproduce

Expected Results

Being able to use both worlds in the Rust code

Actual Results

The compiler fails because of how the exports are setup. I have to place the bindgen! macro in different files, so it produces a weird way of referencing the worlds in rust as you have the same package name and my WIT files cannot share functions from the package.

Versions and Environment

Wasmtime version or commit: 15.0.1

Operating system: Ubuntu 22.04

Architecture: x86_64

view this post on Zulip Wasmtime GitHub notifications bot (Mar 06 2024 at 15:30):

alexcrichton commented on issue #8050:

Yes bindgen! works at the granularity of worlds, so if you've got two worlds your choices are:

Does either of those work for you?

view this post on Zulip Wasmtime GitHub notifications bot (Mar 08 2024 at 16:19):

miguelaeh commented on issue #8050:

Hi @alexcrichton ,

Yes. I mean, there are several ways of working around this. But is there any actual reason for that? It seems to me a bit counterintuitive. I would expect to be able to use all the worlds of a package in the same file. It would be like "importing a package in the file" instead of being able to "import a single class from each package per file".

view this post on Zulip Wasmtime GitHub notifications bot (Mar 08 2024 at 19:28):

alexcrichton commented on issue #8050:

More-or-less the answer is "this is what worlds are built for". They're the unit of work for bindings generators. WIT is designed to be used by many bindings generators and it's desirable to have the same interface (ish) across them all, and using a world is what they are all currently based on. While it's possible to refactor and update all of them to work with multiple worlds, this is also why features like include where added in addition to the inline option for Wasmtime's bindgen! macro were added (to easily make new worlds).

Basically the choice of "what is the unit of bindgen" is a cross-cutting decision. We chose "world" as the unit and so everything is built on that. Similar to how C compilers work on a single *.c file at a time while the Rust compiler works on a whole crate at a time. No fundamental reason for either choice, but so many things are built around that as a result.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 10 2024 at 11:54):

miguelaeh closed issue #8050:

It does not seem to be possible to import two worlds in the same Rust file.

When the two worlds are part of the same WIT package, bindgen! allows you to select only one, and if you use the macro twice with different world names the package export gets duplicated.

If you add the two worlds to different packages in the WIT files and try to use bindgen! for each of them on the same Rust file, you get the error: the name exports is defined multiple times.

Is it possible to do this in some way that I am missing?

Test Case

Any file that defines two worlds

Steps to Reproduce

Expected Results

Being able to use both worlds in the Rust code

Actual Results

The compiler fails because of how the exports are setup. I have to place the bindgen! macro in different files, so it produces a weird way of referencing the worlds in rust as you have the same package name and my WIT files cannot share functions from the package.

Versions and Environment

Wasmtime version or commit: 15.0.1

Operating system: Ubuntu 22.04

Architecture: x86_64

view this post on Zulip Wasmtime GitHub notifications bot (Mar 10 2024 at 11:54):

miguelaeh commented on issue #8050:

Thank you for the explanation @alexcrichton. Closing the issue since it seems it is not unexpected behavior but a design choice.


Last updated: Dec 23 2024 at 12:05 UTC