miguelaeh added the bug label to Issue #8050.
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
exportsis 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
- Create a WIT with two worlds
- Try to use
bindgen!
to use both worlds on the same Rust file.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
alexcrichton commented on issue #8050:
Yes
bindgen!
works at the granularity of worlds, so if you've got two worlds your choices are:
- Create a third world that
include
s both, and then bindgen that one.- Use
bindgen!
twice in separate modules:mod a { bindgen!(...); } mod b { bindgen!(...); }
Does either of those work for you?
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".
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 likeinclude
where added in addition to theinline
option for Wasmtime'sbindgen!
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.
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
exportsis 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
- Create a WIT with two worlds
- Try to use
bindgen!
to use both worlds on the same Rust file.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
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: Nov 22 2024 at 16:03 UTC