Skip to content
Draft
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
25 changes: 12 additions & 13 deletions crates/test-programs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ wit_bindgen::generate!({
package wasmtime:test;

world test {
include wasi:cli/[email protected].6;
include wasi:http/[email protected].6;
include wasi:cli/[email protected].9;
include wasi:http/[email protected].9;
include wasi:config/[email protected];
include wasi:keyvalue/[email protected];
include wasi:tls/[email protected];
Expand All @@ -36,17 +36,16 @@ pub mod proxy {
default_bindings_module: "test_programs::proxy",
pub_export_macro: true,
with: {
"wasi:http/[email protected]": crate::wasi::http::types,
"wasi:http/[email protected]": crate::wasi::http::outgoing_handler,
"wasi:random/[email protected]": crate::wasi::random::random,
"wasi:io/[email protected]": crate::wasi::io::error,
"wasi:io/[email protected]": crate::wasi::io::poll,
"wasi:io/[email protected]": crate::wasi::io::streams,
"wasi:cli/[email protected]": crate::wasi::cli::stdout,
"wasi:cli/[email protected]": crate::wasi::cli::stderr,
"wasi:cli/[email protected]": crate::wasi::cli::stdin,
"wasi:clocks/[email protected]": crate::wasi::clocks::monotonic_clock,
"wasi:clocks/[email protected]": crate::wasi::clocks::wall_clock,
"wasi:http/[email protected]": crate::wasi::http::types,
"wasi:random/[email protected]": crate::wasi::random::random,
"wasi:io/[email protected]": crate::wasi::io::error,
"wasi:io/[email protected]": crate::wasi::io::poll,
"wasi:io/[email protected]": crate::wasi::io::streams,
"wasi:cli/[email protected]": crate::wasi::cli::stdout,
"wasi:cli/[email protected]": crate::wasi::cli::stderr,
"wasi:cli/[email protected]": crate::wasi::cli::stdin,
"wasi:clocks/[email protected]": crate::wasi::clocks::monotonic_clock,
"wasi:clocks/[email protected]": crate::wasi::clocks::wall_clock,
},
});
}
Expand Down
51 changes: 51 additions & 0 deletions crates/wasi-http/src/p3/wit/deps/clocks/system-clock.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package wasi:[email protected];
/// WASI System Clock is a clock API intended to let users query the current
/// time. The clock is not necessarily monotonic as it may be reset.
///
/// It is intended to be portable at least between Unix-family platforms and
/// Windows.
///
/// External references may be reset, so this clock is not necessarily
/// monotonic, making it unsuitable for measuring elapsed time.
///
/// It is intended for reporting the current date and time for humans.
@since(version = 0.3.0-rc-2025-09-16)
interface system-clock {
use types.{duration};

/// An "instant", or "exact time", is a point in time without regard to any
/// time zone: just the time since a particular external reference point,
/// often called an "epoch".
///
/// Here, the epoch is 1970-01-01T00:00:00Z, also known as
/// [POSIX's Seconds Since the Epoch], also known as [Unix Time].
///
/// Note that even if the seconds field is negative, incrementing
/// nanoseconds always represents moving forwards in time.
/// For example, `{ -1 seconds, 999999999 nanoseconds }` represents the
/// instant one nanosecond before the epoch.
/// For more on various different ways to represent time, see
/// https://tc39.es/proposal-temporal/docs/timezone.html
///
/// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16
/// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time
@since(version = 0.3.0-rc-2025-09-16)
record instant {
seconds: s64,
nanoseconds: u32,
}

/// Read the current value of the clock.
///
/// This clock is not monotonic, therefore calling this function repeatedly
/// will not necessarily produce a sequence of non-decreasing values.
///
/// The nanoseconds field of the output is always less than 1000000000.
@since(version = 0.3.0-rc-2025-09-16)
now: func() -> instant;

/// Query the resolution of the clock. Returns the smallest duration of time
/// that the implementation permits distinguishing.
@since(version = 0.3.0-rc-2025-09-16)
get-resolution: func() -> duration;
}
2 changes: 1 addition & 1 deletion crates/wasi-http/wit/deps/cli/command.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasi:[email protected].6;
package wasi:[email protected].9;

@since(version = 0.2.0)
world command {
Expand Down
12 changes: 6 additions & 6 deletions crates/wasi-http/wit/deps/cli/imports.wit
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package wasi:[email protected].6;
package wasi:[email protected].9;

@since(version = 0.2.0)
world imports {
@since(version = 0.2.0)
include wasi:clocks/[email protected].6;
include wasi:clocks/[email protected].9;
@since(version = 0.2.0)
include wasi:filesystem/[email protected].6;
include wasi:filesystem/[email protected].9;
@since(version = 0.2.0)
include wasi:sockets/[email protected].6;
include wasi:sockets/[email protected].9;
@since(version = 0.2.0)
include wasi:random/[email protected].6;
include wasi:random/[email protected].9;
@since(version = 0.2.0)
include wasi:io/[email protected].6;
include wasi:io/[email protected].9;

@since(version = 0.2.0)
import environment;
Expand Down
6 changes: 3 additions & 3 deletions crates/wasi-http/wit/deps/cli/stdio.wit
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@since(version = 0.2.0)
interface stdin {
@since(version = 0.2.0)
use wasi:io/[email protected].6.{input-stream};
use wasi:io/[email protected].9.{input-stream};

@since(version = 0.2.0)
get-stdin: func() -> input-stream;
Expand All @@ -10,7 +10,7 @@ interface stdin {
@since(version = 0.2.0)
interface stdout {
@since(version = 0.2.0)
use wasi:io/[email protected].6.{output-stream};
use wasi:io/[email protected].9.{output-stream};

@since(version = 0.2.0)
get-stdout: func() -> output-stream;
Expand All @@ -19,7 +19,7 @@ interface stdout {
@since(version = 0.2.0)
interface stderr {
@since(version = 0.2.0)
use wasi:io/[email protected].6.{output-stream};
use wasi:io/[email protected].9.{output-stream};

@since(version = 0.2.0)
get-stderr: func() -> output-stream;
Expand Down
9 changes: 7 additions & 2 deletions crates/wasi-http/wit/deps/clocks/monotonic-clock.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasi:[email protected].6;
package wasi:[email protected].9;
/// WASI Monotonic Clock is a clock API intended to let users measure elapsed
/// time.
///
Expand All @@ -10,7 +10,7 @@ package wasi:[email protected];
@since(version = 0.2.0)
interface monotonic-clock {
@since(version = 0.2.0)
use wasi:io/[email protected].6.{pollable};
use wasi:io/[email protected].9.{pollable};

/// An instant in time, in nanoseconds. An instant is relative to an
/// unspecified initial value, and can only be compared to instances from
Expand All @@ -26,6 +26,11 @@ interface monotonic-clock {
///
/// The clock is monotonic, therefore calling this function repeatedly will
/// produce a sequence of non-decreasing values.
///
/// For completeness, this function traps if it's not possible to represent
/// the value of the clock in an `instant`. Consequently, implementations
/// should ensure that the starting time is low enough to avoid the
/// possibility of overflow in practice.
@since(version = 0.2.0)
now: func() -> instant;

Expand Down
2 changes: 1 addition & 1 deletion crates/wasi-http/wit/deps/clocks/timezone.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasi:[email protected].6;
package wasi:[email protected].9;

@unstable(feature = clocks-timezone)
interface timezone {
Expand Down
2 changes: 1 addition & 1 deletion crates/wasi-http/wit/deps/clocks/wall-clock.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasi:[email protected].6;
package wasi:[email protected].9;
/// WASI Wall Clock is a clock API intended to let users query the current
/// time. The name "wall" makes an analogy to a "clock on the wall", which
/// is not necessarily monotonic as it may be reset.
Expand Down
2 changes: 1 addition & 1 deletion crates/wasi-http/wit/deps/clocks/world.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasi:[email protected].6;
package wasi:[email protected].9;

@since(version = 0.2.0)
world imports {
Expand Down
2 changes: 1 addition & 1 deletion crates/wasi-http/wit/deps/filesystem/preopens.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasi:[email protected].6;
package wasi:[email protected].9;

@since(version = 0.2.0)
interface preopens {
Expand Down
6 changes: 3 additions & 3 deletions crates/wasi-http/wit/deps/filesystem/types.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasi:[email protected].6;
package wasi:[email protected].9;
/// WASI filesystem is a filesystem API primarily intended to let users run WASI
/// programs that access their files on their existing filesystems, without
/// significant overhead.
Expand Down Expand Up @@ -26,9 +26,9 @@ package wasi:[email protected];
@since(version = 0.2.0)
interface types {
@since(version = 0.2.0)
use wasi:io/[email protected].6.{input-stream, output-stream, error};
use wasi:io/[email protected].9.{input-stream, output-stream, error};
@since(version = 0.2.0)
use wasi:clocks/[email protected].6.{datetime};
use wasi:clocks/[email protected].9.{datetime};

/// File size or length of a region within a file.
@since(version = 0.2.0)
Expand Down
2 changes: 1 addition & 1 deletion crates/wasi-http/wit/deps/filesystem/world.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasi:[email protected].6;
package wasi:[email protected].9;

@since(version = 0.2.0)
world imports {
Expand Down
14 changes: 7 additions & 7 deletions crates/wasi-http/wit/deps/http/proxy.wit
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
package wasi:[email protected].6;
package wasi:[email protected].9;

/// The `wasi:http/imports` world imports all the APIs for HTTP proxies.
/// It is intended to be `include`d in other worlds.
@since(version = 0.2.0)
world imports {
/// HTTP proxies have access to time and randomness.
@since(version = 0.2.0)
import wasi:clocks/[email protected].6;
import wasi:clocks/[email protected].9;
@since(version = 0.2.0)
import wasi:clocks/[email protected].6;
import wasi:clocks/[email protected].9;
@since(version = 0.2.0)
import wasi:random/[email protected].6;
import wasi:random/[email protected].9;

/// Proxies have standard output and error streams which are expected to
/// terminate in a developer-facing console provided by the host.
@since(version = 0.2.0)
import wasi:cli/[email protected].6;
import wasi:cli/[email protected].9;
@since(version = 0.2.0)
import wasi:cli/[email protected].6;
import wasi:cli/[email protected].9;

/// TODO: this is a temporary workaround until component tooling is able to
/// gracefully handle the absence of stdin. Hosts must return an eof stream
/// for this import, which is what wasi-libc + tooling will do automatically
/// when this import is properly removed.
@since(version = 0.2.0)
import wasi:cli/[email protected].6;
import wasi:cli/[email protected].9;

/// This is the default handler to use when user code simply wants to make an
/// HTTP request (e.g., via `fetch()`).
Expand Down
12 changes: 6 additions & 6 deletions crates/wasi-http/wit/deps/http/types.wit
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
@since(version = 0.2.0)
interface types {
@since(version = 0.2.0)
use wasi:clocks/[email protected].6.{duration};
use wasi:clocks/[email protected].9.{duration};
@since(version = 0.2.0)
use wasi:io/[email protected].6.{input-stream, output-stream};
use wasi:io/[email protected].9.{input-stream, output-stream};
@since(version = 0.2.0)
use wasi:io/[email protected].6.{error as io-error};
use wasi:io/[email protected].9.{error as io-error};
@since(version = 0.2.0)
use wasi:io/[email protected].6.{pollable};
use wasi:io/[email protected].9.{pollable};

/// This type corresponds to HTTP standard Methods.
@since(version = 0.2.0)
Expand Down Expand Up @@ -110,8 +110,8 @@ interface types {
/// provided.
///
/// Stream operations which return
/// `wasi:io/stream/stream-error::last-operation-failed` have a payload of
/// type `wasi:io/error/error` with more information about the operation
/// `wasi:io/stream.stream-error.last-operation-failed` have a payload of
/// type `wasi:io/error.error` with more information about the operation
/// that failed. This payload can be passed through to this function to see
/// if there's http-related information about the error to return.
///
Expand Down
8 changes: 4 additions & 4 deletions crates/wasi-http/wit/deps/io/error.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasi:[email protected].6;
package wasi:[email protected].9;

@since(version = 0.2.0)
interface error {
Expand All @@ -8,14 +8,14 @@ interface error {
/// which provides some human-readable information about the error.
///
/// In the `wasi:io` package, this resource is returned through the
/// `wasi:io/streams/stream-error` type.
/// `wasi:io/streams.stream-error` type.
///
/// To provide more specific error information, other interfaces may
/// offer functions to "downcast" this error into more specific types. For example,
/// errors returned from streams derived from filesystem types can be described using
/// the filesystem's own error-code type. This is done using the function
/// `wasi:filesystem/types/filesystem-error-code`, which takes a `borrow<error>`
/// parameter and returns an `option<wasi:filesystem/types/error-code>`.
/// `wasi:filesystem/types.filesystem-error-code`, which takes a `borrow<error>`
/// parameter and returns an `option<wasi:filesystem/types.error-code>`.
///
/// The set of functions which can "downcast" an `error` into a more
/// concrete type is open.
Expand Down
2 changes: 1 addition & 1 deletion crates/wasi-http/wit/deps/io/poll.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasi:[email protected].6;
package wasi:[email protected].9;

/// A poll API intended to let users wait for I/O events on multiple handles
/// at once.
Expand Down
52 changes: 10 additions & 42 deletions crates/wasi-http/wit/deps/io/streams.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasi:[email protected].6;
package wasi:[email protected].9;

/// WASI I/O is an I/O abstraction API which is currently focused on providing
/// stream types.
Expand Down Expand Up @@ -154,27 +154,13 @@ interface streams {
/// Perform a write of up to 4096 bytes, and then flush the stream. Block
/// until all of these operations are complete, or an error occurs.
///
/// This is a convenience wrapper around the use of `check-write`,
/// `subscribe`, `write`, and `flush`, and is implemented with the
/// following pseudo-code:
///
/// ```text
/// let pollable = this.subscribe();
/// while !contents.is_empty() {
/// // Wait for the stream to become writable
/// pollable.block();
/// let Ok(n) = this.check-write(); // eliding error handling
/// let len = min(n, contents.len());
/// let (chunk, rest) = contents.split_at(len);
/// this.write(chunk ); // eliding error handling
/// contents = rest;
/// }
/// this.flush();
/// // Wait for completion of `flush`
/// pollable.block();
/// // Check for any errors that arose during `flush`
/// let _ = this.check-write(); // eliding error handling
/// ```
/// Returns success when all of the contents written are successfully
/// flushed to output. If an error occurs at any point before all
/// contents are successfully flushed, that error is returned as soon as
/// possible. If writing and flushing the complete contents causes the
/// stream to become closed, this call should return success, and
/// subsequent calls to check-write or other interfaces should return
/// stream-error::closed.
@since(version = 0.2.0)
blocking-write-and-flush: func(
contents: list<u8>
Expand Down Expand Up @@ -227,26 +213,8 @@ interface streams {
/// Block until all of these operations are complete, or an error
/// occurs.
///
/// This is a convenience wrapper around the use of `check-write`,
/// `subscribe`, `write-zeroes`, and `flush`, and is implemented with
/// the following pseudo-code:
///
/// ```text
/// let pollable = this.subscribe();
/// while num_zeroes != 0 {
/// // Wait for the stream to become writable
/// pollable.block();
/// let Ok(n) = this.check-write(); // eliding error handling
/// let len = min(n, num_zeroes);
/// this.write-zeroes(len); // eliding error handling
/// num_zeroes -= len;
/// }
/// this.flush();
/// // Wait for completion of `flush`
/// pollable.block();
/// // Check for any errors that arose during `flush`
/// let _ = this.check-write(); // eliding error handling
/// ```
/// Functionality is equivelant to `blocking-write-and-flush` with
/// contents given as a list of len containing only zeroes.
@since(version = 0.2.0)
blocking-write-zeroes-and-flush: func(
/// The number of zero-bytes to write
Expand Down
2 changes: 1 addition & 1 deletion crates/wasi-http/wit/deps/io/world.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasi:[email protected].6;
package wasi:[email protected].9;

@since(version = 0.2.0)
world imports {
Expand Down
Loading
Loading