WebAssembly / WASI

WebAssembly System Interface
Other
4.72k stars 240 forks source link

A command World proposal #509

Closed sunfishcode closed 11 months ago

sunfishcode commented 1 year ago

We should create a CLI command World proposal.

As has been discussed at various WASI Subgroup meetings, the idea is to have a command entrypoint function which has arguments for things like command-line arguments, environment variables, preopens, and stdio, and to have it include wasi-filesystem, wasi-sockets, wasi-clocks, wasi-random, and others that make up a typical CLI command environment.

sunfishcode commented 1 year ago

We should make sure that it supports preopened files, as well as preopened directories, as discussed here.

sunfishcode commented 1 year ago

(I originally opened this in wasi-filesystem by mistake; I've now transferred it to the WASI repo.)

codefromthecrypt commented 1 year ago

what does "World proposal" imply? this is a top-level proposal like wasi-filesystem? would it be called wasi-command?Besides what has been mentioned, would this be the thing that defines in fact memory is required for everything? or would each proposal (e.g. filesystem) have in their WIT that the guest needs to export that?

sunfishcode commented 1 year ago

Wit defines a World construct, which is a way to collect sets of interfaces. For additional background I also have a blog post about Worlds.

This command World would be the first WASI proposal that contains a World rather than just being an interface. We'll likely need to do some administrative work to set this up, including updating to a newer version of the wit tooling to support this.

The spec that defines how linear memory used in wit APIs is the Canonical ABI.

sunfishcode commented 1 year ago

This proposal should specify the meaning of the first argument, to fix https://github.com/WebAssembly/wasi-classic-command/issues/7, which is also being fixed for preview1 in https://github.com/WebAssembly/WASI/pull/510.

sunfishcode commented 1 year ago

Here's a rough sketch of what the world might look like:

default world wasi-command {
  import wasi-clocks: pkg.wasi-clocks
  import wasi-default-clocks: pkg.wasi-clocks.wasi-default-clocks
  import wasi-stderr: pkg.wasi-stderr
  import wasi-filesystem: pkg.wasi-filesystem
  import wasi-random: pkg.wasi-random
  import wasi-poll: pkg.wasi-poll
  import wasi-io: pkg.wasi-io
  import wasi-sockets: pkg.wasi-sockets
  import wasi-exit: pkg.wasi-exit

  variant preopen {
     file(descriptor),
     directory(descriptor),
     socket(socket)
  }

  export command: func(
    stdin: tuple<input-stream, input-terminal>,
    stdout: tuple<output-stream, output-terminal>,
    args: list<string>,
    env-vars: list<tuple<string, string>>,
    preopens: list<tuple<preopen, string>>,
    timezone: timezone,
  ) -> result
}
sunfishcode commented 11 months ago

The command world proposal is now in active development at https://github.com/WebAssembly/wasi-cli !