World specifier not working in Rust
allurefx opened this issue · comments
I have a WIT with two worlds (say foo and bar), and generate!("foo") is failing saying multiple worlds were found in package, apparently ignoring the world specifier. It works fine when there is only one world. I also tried the long form (world: "foo"). What could be going on?
Could you perhaps upload an example? I tried this locally and was unable to reproduce. One guess might be that the directory for WIT may be mis-configured perhaps?
Sure,, please see attached. If you remove the second world, it works.
guest.zip
Oh, I'm using cargo-component:
[sekhar@aurora guest]$ cargo component build
error: failed to create a target world for package guest
(/home/sekhar/Temp/guest/Cargo.toml)
Caused by:
0: failed to select the default world to use for local target /home/sekhar/Temp/guest/wit
1: multiple worlds found in package component:guest
: one must be explicitly chosen
Ah I believe you're running into a cargo-component-specific issue. That error message is coming from cargo-component, not wit-bindgen. Unfortunately though I don't know enough about cargo-component to know how to fix it.
You'll need the following in Cargo.toml
to select a world:
[package.metadata.component.target]
world = "example2"
Additionally, you probably don't want to mix wit_bindgen::generate!
with cargo-component
projects as cargo- component
will generate bindings for you automatically (you won't need the wit-bindgen
dependency either).
If your intention is to wrap the bindings using wit_bindgen::generate!
to provide a higher-level abstraction on top of the raw bindings, then I suggest creating a normal Rust lib project for that and adding a normal crate dependency on it from a cargo-component
project.
Thanks, yeah making it a regular lib project did it.
Thanks for confirming!
I'm going to close this issue then. If you run into additional problems, please feel free to reopen this issue or open a new issue either here or in cargo-component
's repository.