It would be nice if we could break up spin-test-virt into several different components which could be swapped out or reused by other projects. One of the most central pieces of spin-test-virt is wasi:io which powers a lot of different interfaces in wasi (e.g., wasi:filesystem and wasi:http).
The approach one would imagine to take would be to create a component with the following wit:
package fermyon:wasi-io-virt;
/// Configurable virtualized implementation of `wasi:io`.
world io {
export wasi:io/streams@0.2.0;
export wasi:io/error@0.2.0;
export wasi:io/poll@0.2.0;
import wasi:io/streams@0.2.0;
import wasi:io/error@0.2.0;
import wasi:io/poll@0.2.0;
export config;
}
interface config {
use wasi:io/poll@0.2.0.{pollable};
/// Create a new pollable.
new-poll: func(config: pollable-config) -> pollable;
variant pollable-config {
/// The pollable comes from the host.
host(pollable),
/// The pollable is virtualized.
virtualized
}
// Imagine similar interfaces for `input-stream` and `output-stream`
}
This component both imports and exports wasi:io as well as an additional config interface. The component can virtualize all io interfaces in terms of the imported interfaces (either be implementing them within the component or by delegating to the imported interfaces. The config interface allows users of the component to create new io resources that are either virtualized or backed by some imported resource.
This, however, won't work as imagined as the pollable used in config refers to the exported pollable resource where we would need for it to refer to the imported pollable resource. Unfortunately WIT doesn't allow you to refer to imported items in an exported interface. While this is possible in the component model, it is not possible in WIT today.
It would be nice if we could break up
spin-test-virtinto several different components which could be swapped out or reused by other projects. One of the most central pieces ofspin-test-virtiswasi:iowhich powers a lot of different interfaces in wasi (e.g.,wasi:filesystemandwasi:http).The approach one would imagine to take would be to create a component with the following wit:
This component both imports and exports
wasi:ioas well as an additionalconfiginterface. The component can virtualize all io interfaces in terms of the imported interfaces (either be implementing them within the component or by delegating to the imported interfaces. Theconfiginterface allows users of the component to create newioresources that are either virtualized or backed by some imported resource.This, however, won't work as imagined as the
pollableused inconfigrefers to the exportedpollableresource where we would need for it to refer to the importedpollableresource. Unfortunately WIT doesn't allow you to refer to imported items in an exported interface. While this is possible in the component model, it is not possible in WIT today.