Skip to content

Commit

Permalink
Put versions in all WASI WIT files (#7272)
Browse files Browse the repository at this point in the history
* Put versions in all WASI WIT files

This commit starts exercising the versioning feature of WIT by ensuring
that all WASI descriptions have a version associated with them. The
version chosen is 0.2.0 which reflects the upcoming "preview 2" release
where in theory 0.1.0 was claimed by preview1. This is intended to stay
as 0.2.0 for now and we'll determine how best to update these numbers in
the future once preview2 is released.

Closes #7171

* Allow omitting versions in `with` keys

As a convenience for now this enables omitting the version of an
interface from a `with` key. This has a risk of not working well if two
packages are present and one has a version and one doesn't, but that's
left as a PR to fix in the future as the benefit of avoiding repetition
seems good for now.

* Allow omitting versions in trappable_error_types

* Use 0.2.0-rc-2023-10-18 as a version number

* More test fixes

* Fix another test
  • Loading branch information
alexcrichton authored Oct 18, 2023
1 parent b95382e commit 4258dd9
Show file tree
Hide file tree
Showing 49 changed files with 292 additions and 218 deletions.
2 changes: 1 addition & 1 deletion crates/test-programs/src/bin/api_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod bindings {

wit_bindgen::generate!({
path: "../wasi-http/wit",
world: "wasi:http/proxy",
world: "wasi:http/proxy@0.2.0-rc-2023-10-18",
exports: {
"wasi:http/incoming-handler": T,
},
Expand Down
6 changes: 3 additions & 3 deletions crates/wasi-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ pub mod bindings {
wasmtime::component::bindgen!({
path: "wit",
interfaces: "
import wasi:http/incoming-handler;
import wasi:http/outgoing-handler;
import wasi:http/types;
import wasi:http/incoming-handler@0.2.0-rc-2023-10-18;
import wasi:http/outgoing-handler@0.2.0-rc-2023-10-18;
import wasi:http/types@0.2.0-rc-2023-10-18;
",
tracing: true,
async: false,
Expand Down
4 changes: 2 additions & 2 deletions crates/wasi-http/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{bindings, WasiHttpView};
use wasmtime_wasi::preview2;

wasmtime::component::bindgen!({
world: "wasi:http/proxy",
world: "wasi:http/proxy@0.2.0-rc-2023-10-18",
tracing: true,
async: true,
with: {
Expand Down Expand Up @@ -40,7 +40,7 @@ pub mod sync {
use wasmtime_wasi::preview2;

wasmtime::component::bindgen!({
world: "wasi:http/proxy",
world: "wasi:http/proxy@0.2.0-rc-2023-10-18",
tracing: true,
async: false,
with: {
Expand Down
4 changes: 2 additions & 2 deletions crates/wasi-http/wit/command-extended.wit
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// All of the same imports and exports available in the wasi:cli/command world
// with addition of HTTP proxy related imports:
world command-extended {
include wasi:cli/command;
import wasi:http/outgoing-handler;
include wasi:cli/command@0.2.0-rc-2023-10-18;
import wasi:http/outgoing-handler@0.2.0-rc-2023-10-18;
}
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:cli;
package wasi:cli@0.2.0-rc-2023-10-18;

world command {
include reactor;
Expand Down
36 changes: 18 additions & 18 deletions crates/wasi-http/wit/deps/cli/reactor.wit
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package wasi:cli;
package wasi:cli@0.2.0-rc-2023-10-18;

world reactor {
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:io/poll;
import wasi:io/streams;
import wasi:clocks/wall-clock@0.2.0-rc-2023-10-18;
import wasi:clocks/monotonic-clock@0.2.0-rc-2023-10-18;
import wasi:clocks/timezone@0.2.0-rc-2023-10-18;
import wasi:filesystem/types@0.2.0-rc-2023-10-18;
import wasi:filesystem/preopens@0.2.0-rc-2023-10-18;
import wasi:sockets/instance-network@0.2.0-rc-2023-10-18;
import wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18;
import wasi:sockets/network@0.2.0-rc-2023-10-18;
import wasi:sockets/tcp-create-socket@0.2.0-rc-2023-10-18;
import wasi:sockets/tcp@0.2.0-rc-2023-10-18;
import wasi:sockets/udp-create-socket@0.2.0-rc-2023-10-18;
import wasi:sockets/udp@0.2.0-rc-2023-10-18;
import wasi:random/random@0.2.0-rc-2023-10-18;
import wasi:random/insecure@0.2.0-rc-2023-10-18;
import wasi:random/insecure-seed@0.2.0-rc-2023-10-18;
import wasi:io/poll@0.2.0-rc-2023-10-18;
import wasi:io/streams@0.2.0-rc-2023-10-18;

import environment;
import exit;
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,17 +1,17 @@
interface stdin {
use wasi:io/streams.{input-stream};
use wasi:io/streams@0.2.0-rc-2023-10-18.{input-stream};

get-stdin: func() -> input-stream;
}

interface stdout {
use wasi:io/streams.{output-stream};
use wasi:io/streams@0.2.0-rc-2023-10-18.{output-stream};

get-stdout: func() -> output-stream;
}

interface stderr {
use wasi:io/streams.{output-stream};
use wasi:io/streams@0.2.0-rc-2023-10-18.{output-stream};

get-stderr: func() -> output-stream;
}
2 changes: 1 addition & 1 deletion crates/wasi-http/wit/deps/clocks/monotonic-clock.wit
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
///
/// It is intended for measuring elapsed time.
interface monotonic-clock {
use wasi:io/poll.{pollable};
use wasi:io/poll@0.2.0-rc-2023-10-18.{pollable};

/// A timestamp in nanoseconds.
type instant = u64;
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:clocks;
package wasi:clocks@0.2.0-rc-2023-10-18;

world imports {
import monotonic-clock;
Expand Down
4 changes: 2 additions & 2 deletions crates/wasi-http/wit/deps/filesystem/types.wit
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
///
/// [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, error};
use wasi:clocks/wall-clock.{datetime};
use wasi:io/streams@0.2.0-rc-2023-10-18.{input-stream, output-stream, error};
use wasi:clocks/wall-clock@0.2.0-rc-2023-10-18.{datetime};

/// File size or length of a region within a file.
type filesize = u64;
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:filesystem;
package wasi:filesystem@0.2.0-rc-2023-10-18;

world imports {
import types;
Expand Down
16 changes: 8 additions & 8 deletions crates/wasi-http/wit/deps/http/proxy.wit
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package wasi:http;
package wasi:http@0.2.0-rc-2023-10-18;

// The `wasi:http/proxy` world captures a widely-implementable intersection of
// hosts that includes HTTP forward and reverse proxies. Components targeting
// this world may concurrently stream in and out any number of incoming and
// outgoing HTTP requests.
world proxy {
// HTTP proxies have access to time and randomness.
import wasi:clocks/wall-clock;
import wasi:clocks/monotonic-clock;
import wasi:clocks/timezone;
import wasi:random/random;
import wasi:clocks/wall-clock@0.2.0-rc-2023-10-18;
import wasi:clocks/monotonic-clock@0.2.0-rc-2023-10-18;
import wasi:clocks/timezone@0.2.0-rc-2023-10-18;
import wasi:random/random@0.2.0-rc-2023-10-18;

// Proxies have standard output and error streams which are expected to
// terminate in a developer-facing console provided by the host.
import wasi:cli/stdout;
import wasi:cli/stderr;
import wasi:cli/stdout@0.2.0-rc-2023-10-18;
import wasi:cli/stderr@0.2.0-rc-2023-10-18;

// 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.
import wasi:cli/stdin;
import wasi:cli/stdin@0.2.0-rc-2023-10-18;

// This is the default handler to use when user code simply wants to make an
// HTTP request (e.g., via `fetch()`).
Expand Down
4 changes: 2 additions & 2 deletions crates/wasi-http/wit/deps/http/types.wit
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// define the HTTP resource types and operations used by the component's
// imported and exported interfaces.
interface types {
use wasi:io/streams.{input-stream, output-stream};
use wasi:io/poll.{pollable};
use wasi:io/streams@0.2.0-rc-2023-10-18.{input-stream, output-stream};
use wasi:io/poll@0.2.0-rc-2023-10-18.{pollable};

// This type corresponds to HTTP standard Methods.
variant method {
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:io;
package wasi:io@0.2.0-rc-2023-10-18;

/// A poll API intended to let users wait for I/O events on multiple handles
/// at once.
Expand Down
2 changes: 1 addition & 1 deletion crates/wasi-http/wit/deps/io/streams.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasi:io;
package wasi:io@0.2.0-rc-2023-10-18;

/// WASI I/O is an I/O abstraction API which is currently focused on providing
/// stream types.
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:io;
package wasi:io@0.2.0-rc-2023-10-18;

world imports {
import streams;
Expand Down
2 changes: 1 addition & 1 deletion crates/wasi-http/wit/deps/random/world.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasi:random;
package wasi:random@0.2.0-rc-2023-10-18;

world imports {
import random;
Expand Down
2 changes: 1 addition & 1 deletion crates/wasi-http/wit/deps/sockets/ip-name-lookup.wit
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

interface ip-name-lookup {
use wasi:io/poll.{pollable};
use wasi:io/poll@0.2.0-rc-2023-10-18.{pollable};
use network.{network, error-code, ip-address, ip-address-family};


Expand Down
10 changes: 5 additions & 5 deletions crates/wasi-http/wit/deps/sockets/tcp.wit
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

interface tcp {
use wasi:io/streams.{input-stream, output-stream};
use wasi:io/poll.{pollable};
use wasi:io/streams@0.2.0-rc-2023-10-18.{input-stream, output-stream};
use wasi:io/poll@0.2.0-rc-2023-10-18.{pollable};
use network.{network, error-code, ip-socket-address, ip-address-family};

enum shutdown-type {
Expand Down Expand Up @@ -59,12 +59,12 @@ interface tcp {
/// POSIX mentions:
/// > If connect() fails, the state of the socket is unspecified. Conforming applications should
/// > close the file descriptor and create a new socket before attempting to reconnect.
///
///
/// WASI prescribes the following behavior:
/// - If `connect` fails because an input/state validation error, the socket should remain usable.
/// - If a connection was actually attempted but failed, the socket should become unusable for further network communication.
/// Besides `drop`, any method after such a failure may return an error.
///
///
/// # Typical `start` errors
/// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT)
/// - `invalid-argument`: `remote-address` is not a unicast address. (EINVAL, ENETUNREACH on Linux, EAFNOSUPPORT on MacOS)
Expand Down Expand Up @@ -154,7 +154,7 @@ interface tcp {
/// > stored in the object pointed to by `address` is unspecified.
///
/// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet.
///
///
/// # Typical errors
/// - `invalid-state`: The socket is not bound to any local address.
///
Expand Down
4 changes: 2 additions & 2 deletions crates/wasi-http/wit/deps/sockets/udp.wit
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

interface udp {
use wasi:io/poll.{pollable};
use wasi:io/poll@0.2.0-rc-2023-10-18.{pollable};
use network.{network, error-code, ip-socket-address, ip-address-family};


Expand Down Expand Up @@ -146,7 +146,7 @@ interface udp {
/// > stored in the object pointed to by `address` is unspecified.
///
/// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet.
///
///
/// # Typical errors
/// - `invalid-state`: The socket is not bound to any local address.
///
Expand Down
2 changes: 1 addition & 1 deletion crates/wasi-http/wit/deps/sockets/world.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasi:sockets;
package wasi:sockets@0.2.0-rc-2023-10-18;

world imports {
import instance-network;
Expand Down
54 changes: 27 additions & 27 deletions crates/wasi-http/wit/main.wit
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@ package wasmtime:wasi;
// All of the same imports available in the wasi:cli/command world, but no
// export required:
world preview1-adapter-reactor {
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:io/poll;
import wasi:io/streams;
import wasi:cli/environment;
import wasi:cli/exit;
import wasi:cli/stdin;
import wasi:cli/stdout;
import wasi:cli/stderr;
import wasi:cli/terminal-input;
import wasi:cli/terminal-output;
import wasi:cli/terminal-stdin;
import wasi:cli/terminal-stdout;
import wasi:cli/terminal-stderr;
import wasi:clocks/wall-clock@0.2.0-rc-2023-10-18;
import wasi:clocks/monotonic-clock@0.2.0-rc-2023-10-18;
import wasi:clocks/timezone@0.2.0-rc-2023-10-18;
import wasi:filesystem/types@0.2.0-rc-2023-10-18;
import wasi:filesystem/preopens@0.2.0-rc-2023-10-18;
import wasi:sockets/instance-network@0.2.0-rc-2023-10-18;
import wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18;
import wasi:sockets/network@0.2.0-rc-2023-10-18;
import wasi:sockets/tcp-create-socket@0.2.0-rc-2023-10-18;
import wasi:sockets/tcp@0.2.0-rc-2023-10-18;
import wasi:sockets/udp-create-socket@0.2.0-rc-2023-10-18;
import wasi:sockets/udp@0.2.0-rc-2023-10-18;
import wasi:random/random@0.2.0-rc-2023-10-18;
import wasi:random/insecure@0.2.0-rc-2023-10-18;
import wasi:random/insecure-seed@0.2.0-rc-2023-10-18;
import wasi:io/poll@0.2.0-rc-2023-10-18;
import wasi:io/streams@0.2.0-rc-2023-10-18;
import wasi:cli/environment@0.2.0-rc-2023-10-18;
import wasi:cli/exit@0.2.0-rc-2023-10-18;
import wasi:cli/stdin@0.2.0-rc-2023-10-18;
import wasi:cli/stdout@0.2.0-rc-2023-10-18;
import wasi:cli/stderr@0.2.0-rc-2023-10-18;
import wasi:cli/terminal-input@0.2.0-rc-2023-10-18;
import wasi:cli/terminal-output@0.2.0-rc-2023-10-18;
import wasi:cli/terminal-stdin@0.2.0-rc-2023-10-18;
import wasi:cli/terminal-stdout@0.2.0-rc-2023-10-18;
import wasi:cli/terminal-stderr@0.2.0-rc-2023-10-18;
}
12 changes: 6 additions & 6 deletions crates/wasi-http/wit/test.wit
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// only used as part of `test-programs`
world test-reactor {
include wasi:cli/reactor;
include wasi:cli/reactor@0.2.0-rc-2023-10-18;

export add-strings: func(s: list<string>) -> u32;
export get-strings: func() -> list<string>;

use wasi:io/streams.{output-stream};
use wasi:io/streams@0.2.0-rc-2023-10-18.{output-stream};

export write-strings-to: func(o: output-stream) -> result;

use wasi:filesystem/types.{descriptor-stat};
use wasi:filesystem/types@0.2.0-rc-2023-10-18.{descriptor-stat};
export pass-an-imported-record: func(d: descriptor-stat) -> string;
}

world test-command {
include wasi:cli/reactor;
import wasi:http/types;
import wasi:http/outgoing-handler;
include wasi:cli/reactor@0.2.0-rc-2023-10-18;
import wasi:http/types@0.2.0-rc-2023-10-18;
import wasi:http/outgoing-handler@0.2.0-rc-2023-10-18;
}
2 changes: 1 addition & 1 deletion crates/wasi-preview1-component-adapter/src/descriptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl Descriptors {
}))
.trapping_unwrap();

#[link(wasm_import_module = "wasi:filesystem/preopens")]
#[link(wasm_import_module = "wasi:filesystem/preopens@0.2.0-rc-2023-10-18")]
#[allow(improper_ctypes)] // FIXME(bytecodealliance/wit-bindgen#684)
extern "C" {
#[link_name = "get-directories"]
Expand Down
Loading

0 comments on commit 4258dd9

Please sign in to comment.