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

Export multiple worlds

Open Fristi opened this issue 2 years ago • 4 comments

I have a wit directory with multiple worlds defined in it. Each world consists of a composition of import statements, which import interfaces. Now in my host code (Rust) I would like to implement all the imports only once. Is there a option to output multiple worlds and the imports only once?

Would this work with either the cli generator or the macro?

Fristi avatar Mar 28 '23 16:03 Fristi

All build tooling is designed around compiling for a single target world. There is some interest in a way to define a world as the union of other worlds which would apply here, but that's far from ready.

Can you give an example of what kinds of interfaces/worlds you have? It's likely there's a way to factor what you're doing as targeting a single a world which shares a set of common interfaces with any other worlds that represent other unique targets.

esoterra avatar Mar 28 '23 17:03 esoterra

When you say Rust host code, do you mean Wasmtime as well? If so the Wasmtime generator doesn't actually live in this repository but lives inside of Wasmtime instead. Regardless though as @Kylebrown9 mentioned there's no option to output multiple worlds at this time.

What I would recommend for the time being is, while first class support is being worked on, to write your own world which manually includes the imports of the others, e.g. copy/pasting between them.

alexcrichton avatar Mar 28 '23 19:03 alexcrichton

I've defined 3 worlds now and as suggested a world which manually includes imports of others. But it throws me an error when I import only universe

Error: exported instance enricher not present

default world plugin-container-runtime {
  import http: pkg.http
  import config: pkg.config
  import log: pkg.log
  import cache: pkg.cache

  export container-runtime: pkg.container-runtime
}
default world plugin-enricher {
  import http: pkg.http
  import config: pkg.config
  import log: pkg.log
  import cache: pkg.cache

  export enricher: pkg.enricher
}
default world universe {
  import http: pkg.http
  import config: pkg.config
  import log: pkg.log

  export enricher: pkg.enricher
  export container-runtime: pkg.container-runtime
}

This is because the host codes loads universe but the WASM file only implements one of the two plugins plugin-container-runtime or plugin-enricher. In case of the error the WASM file only implemented the plugin-container-runtime

Fristi avatar Mar 29 '23 17:03 Fristi

Ah ok yes union-of-worlds is not the feature that you want here. Instead what I think you want is the ability to generate one set of traits between these two worlds for the host bindings (e.g. pkg.http would correspond to the same trait for both plugin-container-runtime and plugin-enricher). That doesn't exist yet but is something we're working on for the host-side with Wasmtime in the near future.

alexcrichton avatar Mar 29 '23 19:03 alexcrichton