Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions wit/command.wit
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
package wasi:cli

world command {
import wasi:clocks/wall-clock
import wasi:clocks/monotonic-clock
import wasi:clocks/timezone
import wasi:filesystem/types
import wasi:filesystem/preopens
import wasi:sockets/instance-network
import wasi:sockets/ip-name-lookup
import wasi:sockets/network
import wasi:sockets/tcp-create-socket
import wasi:sockets/tcp
import wasi:sockets/udp-create-socket
import wasi:sockets/udp
import wasi:random/random
import wasi:random/insecure
import wasi:random/insecure-seed
import wasi:poll/poll
import wasi:io/streams
include wasi:clocks/example-world
include wasi:filesystem/example-world
include wasi:sockets/example-world
include wasi:random/example-world
include wasi:poll/example-world
include wasi:io/example-world
import environment
import exit
import stdin
Expand Down
12 changes: 6 additions & 6 deletions wit/deps.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ sha512 = "ef1e23704a8a8436fd3718593d4c4d8b6d1c64dad3595b7496c0888ca14b725046f290

[filesystem]
url = "https://github.com/WebAssembly/wasi-filesystem/archive/main.tar.gz"
sha256 = "dc170645d8aa52f2f94ab8f71093fa0c101e509ed1a07318995dc0395e9d6cf2"
sha512 = "3195a3e0f9ec52c3a91c4b4fde0547694236c7b29bceecb7f38634894fafd809c69ed1c1c9acbf225b2d5d00f5036d70371c9fed121d85028162b202035cabef"
sha256 = "bd34614a897ee5d442ab6489f46a6785a420147a2c29f572f6e1053b84b02395"
sha512 = "9a21bbb9b5a0e1dd3ebabc330e406ae3a61ec3802c97e04265248a91e0d6713172e61b3ebef3b5857bf8303740ff408452b9d787d87c8fe9fa3fd66ef68e374d"

[io]
url = "https://github.com/WebAssembly/wasi-io/archive/main.tar.gz"
sha256 = "6e18239b0e20d1a3e6343cb961ebfd2c663ba7feb4c1aa3744b756fbdd1fb5b8"
sha512 = "53169b6e4fba0b2cf5fcf808f76e7fbb7cabb6ed66ab53f77d0966e7448312ccbe8571880ef4fc2ee86fbd6ba19bc48d46e10d22dcac6c51d217e8d7127c32db"
sha256 = "a47690f7d4dba1683a42897cc65fe813409827d72cc93afe03b127ee81763e13"
sha512 = "661aa9cf9c67d7d712caccfbb3c317da01b033764892623c8902d9dcfdb67f3088889102b036d3ed19d818a5c2d151247b25d9f6fd145cdf433f325605a5a747"

[poll]
url = "https://github.com/WebAssembly/wasi-poll/archive/main.tar.gz"
Expand All @@ -25,5 +25,5 @@ sha512 = "21f03ca1e595b80d7ced522de1a47446526b49b900e2fb26fcbf410ce6aa267dbf247a

[sockets]
url = "https://github.com/WebAssembly/wasi-sockets/archive/main.tar.gz"
sha256 = "871c211b12d87a5da87c42353338b652260840897efcd37e2afba3b9290058fc"
sha512 = "e436a5ff3145ca85d702a086499c03488523483dd3addc8d71e4946e9c186355291551bb6d38b157173836fcc318182403e6dba970de4512f6cfb3374ccad6b9"
sha256 = "b4ad6e10c126b7f18ecad5cd7adc8effef456de3c7b1d22e2f9fdd8a62f65d2d"
sha512 = "3f8529705fe04a3ac2f3fdc923b0628b552a52650b99c6c99665b7c82ba80ac17ae0419e66333bffa715ae62e8ca0b0de1c93564bdfe324ed32c56a4970eb794"
22 changes: 5 additions & 17 deletions wit/deps/filesystem/types.wit
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
/// `..` and symbolic link steps, reaches a directory outside of the base
/// directory, or reaches a symlink to an absolute or rooted path in the
/// underlying filesystem, the function fails with `error-code::not-permitted`.
///
/// For more information about WASI path resolution and sandboxing, see
/// [WASI filesystem path resolution].
///
/// [WASI filesystem path resolution]: https://github.com/WebAssembly/wasi-filesystem/blob/main/path-resolution.md
interface types {
use wasi:io/streams.{input-stream, output-stream}
use wasi:clocks/wall-clock.{datetime}
Expand Down Expand Up @@ -55,14 +60,6 @@ interface types {
read,
/// Write mode: Data can be written to.
write,
/// Requests non-blocking operation.
///
/// When this flag is enabled, functions may return immediately with an
/// `error-code::would-block` error code in situations where they would
/// otherwise block. However, this non-blocking behavior is not
/// required. Implementations are permitted to ignore this flag and
/// block. This is similar to `O_NONBLOCK` in POSIX.
non-blocking,
/// Request that writes be performed according to synchronized I/O file
/// integrity completion. The data stored in the file and the file's
/// metadata are synchronized. This is similar to `O_SYNC` in POSIX.
Expand Down Expand Up @@ -378,15 +375,6 @@ interface types {
/// from `fdstat_get` in earlier versions of WASI.
get-type: func(this: descriptor) -> result<descriptor-type, error-code>

/// Set status flags associated with a descriptor.
///
/// This function may only change the `non-blocking` flag.
///
/// Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX.
///
/// Note: This was called `fd_fdstat_set_flags` in earlier versions of WASI.
set-flags: func(this: descriptor, %flags: descriptor-flags) -> result<_, error-code>

/// Adjust the size of an open file. If this increases the file's size, the
/// extra bytes are filled with zeros.
///
Expand Down
139 changes: 83 additions & 56 deletions wit/deps/io/streams.wit
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package wasi:io

/// WASI I/O is an I/O abstraction API which is currently focused on providing
/// stream types.
///
Expand All @@ -6,10 +8,6 @@
interface streams {
use wasi:poll/poll.{pollable}

/// An error type returned from a stream operation. Currently this
/// doesn't provide any additional information.
record stream-error {}

/// Streams provide a sequence of data and then end; once they end, they
/// no longer provide any further data.
///
Expand All @@ -19,62 +17,64 @@ interface streams {
enum stream-status {
/// The stream is open and may produce further data.
open,
/// The stream has ended and will not produce any further data.
/// When reading, this indicates that the stream will not produce
/// further data.
/// When writing, this indicates that the stream will no longer be read.
/// Further writes are still permitted.
ended,
}

/// An input bytestream. In the future, this will be replaced by handle
/// types.
///
/// This conceptually represents a `stream<u8, _>`. It's temporary
/// scaffolding until component-model's async features are ready.
///
/// `input-stream`s are *non-blocking* to the extent practical on underlying
/// platforms. I/O operations always return promptly; if fewer bytes are
/// promptly available than requested, they return the number of bytes promptly
/// available, which could even be zero. To wait for data to be available,
/// use the `subscribe-to-input-stream` function to obtain a `pollable` which
/// can be polled for using `wasi_poll`.
/// can be polled for using `wasi:poll/poll.poll_oneoff`.
///
/// And at present, it is a `u32` instead of being an actual handle, until
/// the wit-bindgen implementation of handles and resources is ready.
///
/// This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
type input-stream = u32

/// Read bytes from a stream.
/// Perform a non-blocking read from the stream.
///
/// This function returns a list of bytes containing the data that was
/// read, along with a `stream-status` which indicates whether the end of
/// the stream was reached. The returned list will contain up to `len`
/// bytes; it may return fewer than requested, but not more.
///
/// Once a stream has reached the end, subsequent calls to read or
/// `skip` will always report end-of-stream rather than producing more
/// read, along with a `stream-status` which, indicates whether further
/// reads are expected to produce data. The returned list will contain up to
/// `len` bytes; it may return fewer than requested, but not more. An
/// empty list and `stream-status:open` indicates no more data is
/// available at this time, and that the pollable given by
/// `subscribe-to-input-stream` will be ready when more data is available.
///
/// Once a stream has reached the end, subsequent calls to `read` or
/// `skip` will always report `stream-status:ended` rather than producing more
/// data.
///
/// If `len` is 0, it represents a request to read 0 bytes, which should
/// always succeed, assuming the stream hasn't reached its end yet, and
/// return an empty list.
/// When the caller gives a `len` of 0, it represents a request to read 0
/// bytes. This read should always succeed and return an empty list and
/// the current `stream-status`.
///
/// The len here is a `u64`, but some callees may not be able to allocate
/// a buffer as large as that would imply.
/// FIXME: describe what happens if allocation fails.
/// The `len` parameter is a `u64`, which could represent a list of u8 which
/// is not possible to allocate in wasm32, or not desirable to allocate as
/// as a return value by the callee. The callee may return a list of bytes
/// less than `len` in size while more bytes are available for reading.
read: func(
this: input-stream,
/// The maximum number of bytes to read
len: u64
) -> result<tuple<list<u8>, stream-status>, stream-error>
) -> result<tuple<list<u8>, stream-status>>

/// Read bytes from a stream, with blocking.
///
/// This is similar to `read`, except that it blocks until at least one
/// byte can be read.
/// Read bytes from a stream, after blocking until at least one byte can
/// be read. Except for blocking, identical to `read`.
blocking-read: func(
this: input-stream,
/// The maximum number of bytes to read
len: u64
) -> result<tuple<list<u8>, stream-status>, stream-error>
) -> result<tuple<list<u8>, stream-status>>

/// Skip bytes from a stream.
///
Expand All @@ -92,85 +92,100 @@ interface streams {
this: input-stream,
/// The maximum number of bytes to skip.
len: u64,
) -> result<tuple<u64, stream-status>, stream-error>
) -> result<tuple<u64, stream-status>>

/// Skip bytes from a stream, with blocking.
///
/// This is similar to `skip`, except that it blocks until at least one
/// byte can be consumed.
/// Skip bytes from a stream, after blocking until at least one byte
/// can be skipped. Except for blocking behavior, identical to `skip`.
blocking-skip: func(
this: input-stream,
/// The maximum number of bytes to skip.
len: u64,
) -> result<tuple<u64, stream-status>, stream-error>
) -> result<tuple<u64, stream-status>>

/// Create a `pollable` which will resolve once either the specified stream
/// has bytes available to read or the other end of the stream has been
/// closed.
/// The created `pollable` is a child resource of the `input-stream`.
/// Implementations may trap if the `input-stream` is dropped before
/// all derived `pollable`s created with this function are dropped.
subscribe-to-input-stream: func(this: input-stream) -> pollable

/// Dispose of the specified `input-stream`, after which it may no longer
/// be used.
/// Implementations may trap if this `input-stream` is dropped while child
/// `pollable` resources are still alive.
/// After this `input-stream` is dropped, implementations may report any
/// corresponding `output-stream` has `stream-state.closed`.
drop-input-stream: func(this: input-stream)

/// An output bytestream. In the future, this will be replaced by handle
/// types.
///
/// This conceptually represents a `stream<u8, _>`. It's temporary
/// scaffolding until component-model's async features are ready.
///
/// `output-stream`s are *non-blocking* to the extent practical on
/// underlying platforms. Except where specified otherwise, I/O operations also
/// always return promptly, after the number of bytes that can be written
/// promptly, which could even be zero. To wait for the stream to be ready to
/// accept data, the `subscribe-to-output-stream` function to obtain a
/// `pollable` which can be polled for using `wasi_poll`.
/// `pollable` which can be polled for using `wasi:poll`.
///
/// And at present, it is a `u32` instead of being an actual handle, until
/// the wit-bindgen implementation of handles and resources is ready.
///
/// This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
type output-stream = u32

/// Write bytes to a stream.
/// Perform a non-blocking write of bytes to a stream.
///
/// This function returns a `u64` and a `stream-status`. The `u64` indicates
/// the number of bytes from `buf` that were written, which may be less than
/// the length of `buf`. The `stream-status` indicates if further writes to
/// the stream are expected to be read.
///
/// This function returns a `u64` indicating the number of bytes from
/// `buf` that were written; it may be less than the full list.
/// When the returned `stream-status` is `open`, the `u64` return value may
/// be less than the length of `buf`. This indicates that no more bytes may
/// be written to the stream promptly. In that case the
/// `subscribe-to-output-stream` pollable will indicate when additional bytes
/// may be promptly written.
///
/// Writing an empty list must return a non-error result with `0` for the
/// `u64` return value, and the current `stream-status`.
write: func(
this: output-stream,
/// Data to write
buf: list<u8>
) -> result<u64, stream-error>
) -> result<tuple<u64, stream-status>>

/// Write bytes to a stream, with blocking.
/// Blocking write of bytes to a stream.
///
/// This is similar to `write`, except that it blocks until at least one
/// byte can be written.
blocking-write: func(
this: output-stream,
/// Data to write
buf: list<u8>
) -> result<u64, stream-error>
) -> result<tuple<u64, stream-status>>

/// Write multiple zero bytes to a stream.
/// Write multiple zero-bytes to a stream.
///
/// This function returns a `u64` indicating the number of zero bytes
/// that were written; it may be less than `len`.
/// This function returns a `u64` indicating the number of zero-bytes
/// that were written; it may be less than `len`. Equivelant to a call to
/// `write` with a list of zeroes of the given length.
write-zeroes: func(
this: output-stream,
/// The number of zero bytes to write
/// The number of zero-bytes to write
len: u64
) -> result<u64, stream-error>
) -> result<tuple<u64, stream-status>>

/// Write multiple zero bytes to a stream, with blocking.
///
/// This is similar to `write-zeroes`, except that it blocks until at least
/// one byte can be written.
/// one byte can be written. Equivelant to a call to `blocking-write` with
/// a list of zeroes of the given length.
blocking-write-zeroes: func(
this: output-stream,
/// The number of zero bytes to write
len: u64
) -> result<u64, stream-error>
) -> result<tuple<u64, stream-status>>

/// Read from one stream and write to another.
///
Expand All @@ -185,7 +200,7 @@ interface streams {
src: input-stream,
/// The number of bytes to splice
len: u64,
) -> result<tuple<u64, stream-status>, stream-error>
) -> result<tuple<u64, stream-status>>

/// Read from one stream and write to another, with blocking.
///
Expand All @@ -197,7 +212,7 @@ interface streams {
src: input-stream,
/// The number of bytes to splice
len: u64,
) -> result<tuple<u64, stream-status>, stream-error>
) -> result<tuple<u64, stream-status>>

/// Forward the entire contents of an input stream to an output stream.
///
Expand All @@ -209,18 +224,30 @@ interface streams {
/// of the input stream is seen and all the data has been written to
/// the output stream.
///
/// This function returns the number of bytes transferred.
/// This function returns the number of bytes transferred, and the status of
/// the output stream.
forward: func(
this: output-stream,
/// The stream to read from
src: input-stream
) -> result<u64, stream-error>
) -> result<tuple<u64, stream-status>>

/// Create a `pollable` which will resolve once either the specified stream
/// is ready to accept bytes or the other end of the stream has been closed.
/// is ready to accept bytes or the `stream-state` has become closed.
///
/// Once the stream-state is closed, this pollable is always ready
/// immediately.
///
/// The created `pollable` is a child resource of the `output-stream`.
/// Implementations may trap if the `output-stream` is dropped before
/// all derived `pollable`s created with this function are dropped.
subscribe-to-output-stream: func(this: output-stream) -> pollable

/// Dispose of the specified `output-stream`, after which it may no longer
/// be used.
/// Implementations may trap if this `output-stream` is dropped while
/// child `pollable` resources are still alive.
/// After this `output-stream` is dropped, implementations may report any
/// corresponding `input-stream` has `stream-state.closed`.
drop-output-stream: func(this: output-stream)
}
2 changes: 0 additions & 2 deletions wit/deps/sockets/udp.wit
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ interface udp {
/// actual data to be sent/received by the application, because the kernel might also use the buffer space
/// for internal metadata structures.
///
/// Fails when this socket is in the Listening state.
///
/// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options.
///
/// # Typical errors
Expand Down