wit-bindgen icon indicating copy to clipboard operation
wit-bindgen copied to clipboard

Rust-import/Wasmtime-export: Examples of using multiple modules together

Open philpax opened this issue 3 years ago • 2 comments

If I have a common.wit:

record entity-id {
    namespace: u8,
    id: u64,
    gen: s32,
}

record vec3 {
    x: float32,
    y: float32,
    z: float32,
}

and an entity.wit:

use { entity-id, vec3 } from common

entity-spawn: func(object-ref: string, position: vec3) -> option<entity-id>

What is the correct way to consume these? The naive approach of

wit_bindgen_rust::import!("src/common.wit");
wit_bindgen_rust::import!("src/entity.wit");

results in entity::EntityId being a different type to common::EntityId. Looking around, I think I have to do something with Opts, but I'm not sure how to drive that.

With that being said, I've had a look around the repository, and found these issues:

  • https://github.com/bytecodealliance/wit-bindgen/issues/214
  • https://github.com/bytecodealliance/wit-bindgen/issues/191
  • https://github.com/bytecodealliance/wit-bindgen/issues/133

which suggest that the use system is still very much a work in progress. Based on that, I've just rolled all of my definitions into a single wit and am modularising them manually within the guest. Should I continue doing that for the meantime?

philpax avatar Jul 26 '22 15:07 philpax

This is something we expect will be handled by profiles. A profile will be able to pull in multiple wit interfaces, and then once this functionality is implemented, wit-bindgen will be able to generate unified bindings. See https://github.com/bytecodealliance/wit-bindgen/issues/266, and https://github.com/bytecodealliance/wit-bindgen/issues/265.

sunfishcode avatar Jul 26 '22 15:07 sunfishcode

Aha, that makes sense, thank you! Looks like profiles are still being implemented, so I'll continue using a single wit and switch over to profiles once they're ready 🙂

philpax avatar Jul 26 '22 15:07 philpax

I think that this is a duplicate of https://github.com/bytecodealliance/wit-bindgen/issues/266 (importing/exporting things at the same time) so I'm going to close this in favor of that.

alexcrichton avatar Sep 06 '22 18:09 alexcrichton