Skip to content

Commit 256b651

Browse files
author
Pat Hickey
authored
Launch Preview 2 (#577)
* preview2 README: describe launched Preview 2 * preview2: add contents of each proposal wit
1 parent a7be582 commit 256b651

33 files changed

+2852
-13
lines changed

preview2/README.md

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
# WASI Preview 2
22

3-
At this time, Preview 2 is in development and has not yet launched.
4-
5-
## Launch criteria
6-
7-
WASI Preview 2 will be considered launched when at least two independent
8-
proposals which define worlds, and all their dependencies, have met the
9-
requirements for inclusion listed below, and the WASI Subgroup has voted
10-
to launch it.
11-
123
## Introduction
134

14-
*The following is a draft of an introduction for WASI Preview 2 when it launches.*
15-
165
WASI Preview 2 represents a major milestone for WASI. It marks the moment
176
when WASI has fully rebased on the [Wit IDL] and the [component model]
187
type system and semantics, making it modular, fully virtualizable, and
@@ -25,8 +14,41 @@ accessible to a wide variety of source languages.
2514

2615
WASI Preview 2 contains the following APIs:
2716

28-
| Proposal | Versions |
29-
| ------------------------------------------------------------------------------ | -------- |
17+
| Proposal | Versions |
18+
| ------------------ | -------- |
19+
| [wasi-io] | 0.2.0 |
20+
| [wasi-clocks] | 0.2.0 |
21+
| [wasi-random] | 0.2.0 |
22+
| [wasi-filesystem] | 0.2.0 |
23+
| [wasi-sockets] | 0.2.0 |
24+
| [wasi-cli] | 0.2.0 |
25+
| [wasi-http] | 0.2.0 |
26+
27+
[wasi-io]: https://github.com/WebAssembly/wasi-io
28+
[wasi-clocks]: https://github.com/WebAssembly/wasi-clocks
29+
[wasi-random]: https://github.com/WebAssembly/wasi-random
30+
[wasi-filesystem]: https://github.com/WebAssembly/wasi-filesystem
31+
[wasi-sockets]: https://github.com/WebAssembly/wasi-sockets
32+
[wasi-cli]: https://github.com/WebAssembly/wasi-cli
33+
[wasi-http]: https://github.com/WebAssembly/wasi-http
34+
35+
## WASI Preview 2 Implementations
36+
37+
The portability criteria of the WASI Preview 2 proposals were met by the
38+
following implementations, which were demonstrated to be interoperable by
39+
each passing [Wasmtime's WASI Preview 2 test suite][test-suite].
40+
41+
* [Wasmtime]
42+
* [JCO]
43+
44+
[Wasmtime]: https://github.com/BytecodeAlliance/wasmtime
45+
[JCO]: https://github.com/BytecodeAlliance/jco
46+
47+
We plan to promote the Preview 2 test suite to live in the [wasi-testsuite]
48+
project soon, and add more interoperable implementations to this list when
49+
they are complete.
50+
51+
[wasi-testsuite]: https://github.com/WebAssembly/wasi-testsuite
3052

3153
## Proposal requirements for inclusion in WASI Preview 2.
3254

preview2/cli/command.wit

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package wasi:cli@0.2.0;
2+
3+
world command {
4+
include imports;
5+
6+
export run;
7+
}

preview2/cli/environment.wit

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
interface environment {
2+
/// Get the POSIX-style environment variables.
3+
///
4+
/// Each environment variable is provided as a pair of string variable names
5+
/// and string value.
6+
///
7+
/// Morally, these are a value import, but until value imports are available
8+
/// in the component model, this import function should return the same
9+
/// values each time it is called.
10+
get-environment: func() -> list<tuple<string, string>>;
11+
12+
/// Get the POSIX-style arguments to the program.
13+
get-arguments: func() -> list<string>;
14+
15+
/// Return a path that programs should use as their initial current working
16+
/// directory, interpreting `.` as shorthand for this.
17+
initial-cwd: func() -> option<string>;
18+
}

preview2/cli/exit.wit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
interface exit {
2+
/// Exit the current instance and any linked instances.
3+
exit: func(status: result);
4+
}

preview2/cli/imports.wit

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package wasi:cli@0.2.0;
2+
3+
world imports {
4+
include wasi:clocks/imports@0.2.0;
5+
include wasi:filesystem/imports@0.2.0;
6+
include wasi:sockets/imports@0.2.0;
7+
include wasi:random/imports@0.2.0;
8+
include wasi:io/imports@0.2.0;
9+
10+
import environment;
11+
import exit;
12+
import stdin;
13+
import stdout;
14+
import stderr;
15+
import terminal-input;
16+
import terminal-output;
17+
import terminal-stdin;
18+
import terminal-stdout;
19+
import terminal-stderr;
20+
}

preview2/cli/run.wit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
interface run {
2+
/// Run the program.
3+
run: func() -> result;
4+
}

preview2/cli/stdio.wit

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
interface stdin {
2+
use wasi:io/streams@0.2.0.{input-stream};
3+
4+
get-stdin: func() -> input-stream;
5+
}
6+
7+
interface stdout {
8+
use wasi:io/streams@0.2.0.{output-stream};
9+
10+
get-stdout: func() -> output-stream;
11+
}
12+
13+
interface stderr {
14+
use wasi:io/streams@0.2.0.{output-stream};
15+
16+
get-stderr: func() -> output-stream;
17+
}

preview2/cli/terminal.wit

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/// Terminal input.
2+
///
3+
/// In the future, this may include functions for disabling echoing,
4+
/// disabling input buffering so that keyboard events are sent through
5+
/// immediately, querying supported features, and so on.
6+
interface terminal-input {
7+
/// The input side of a terminal.
8+
resource terminal-input;
9+
}
10+
11+
/// Terminal output.
12+
///
13+
/// In the future, this may include functions for querying the terminal
14+
/// size, being notified of terminal size changes, querying supported
15+
/// features, and so on.
16+
interface terminal-output {
17+
/// The output side of a terminal.
18+
resource terminal-output;
19+
}
20+
21+
/// An interface providing an optional `terminal-input` for stdin as a
22+
/// link-time authority.
23+
interface terminal-stdin {
24+
use terminal-input.{terminal-input};
25+
26+
/// If stdin is connected to a terminal, return a `terminal-input` handle
27+
/// allowing further interaction with it.
28+
get-terminal-stdin: func() -> option<terminal-input>;
29+
}
30+
31+
/// An interface providing an optional `terminal-output` for stdout as a
32+
/// link-time authority.
33+
interface terminal-stdout {
34+
use terminal-output.{terminal-output};
35+
36+
/// If stdout is connected to a terminal, return a `terminal-output` handle
37+
/// allowing further interaction with it.
38+
get-terminal-stdout: func() -> option<terminal-output>;
39+
}
40+
41+
/// An interface providing an optional `terminal-output` for stderr as a
42+
/// link-time authority.
43+
interface terminal-stderr {
44+
use terminal-output.{terminal-output};
45+
46+
/// If stderr is connected to a terminal, return a `terminal-output` handle
47+
/// allowing further interaction with it.
48+
get-terminal-stderr: func() -> option<terminal-output>;
49+
}

preview2/clocks/monotonic-clock.wit

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package wasi:clocks@0.2.0;
2+
/// WASI Monotonic Clock is a clock API intended to let users measure elapsed
3+
/// time.
4+
///
5+
/// It is intended to be portable at least between Unix-family platforms and
6+
/// Windows.
7+
///
8+
/// A monotonic clock is a clock which has an unspecified initial value, and
9+
/// successive reads of the clock will produce non-decreasing values.
10+
///
11+
/// It is intended for measuring elapsed time.
12+
interface monotonic-clock {
13+
use wasi:io/poll@0.2.0.{pollable};
14+
15+
/// An instant in time, in nanoseconds. An instant is relative to an
16+
/// unspecified initial value, and can only be compared to instances from
17+
/// the same monotonic-clock.
18+
type instant = u64;
19+
20+
/// A duration of time, in nanoseconds.
21+
type duration = u64;
22+
23+
/// Read the current value of the clock.
24+
///
25+
/// The clock is monotonic, therefore calling this function repeatedly will
26+
/// produce a sequence of non-decreasing values.
27+
now: func() -> instant;
28+
29+
/// Query the resolution of the clock. Returns the duration of time
30+
/// corresponding to a clock tick.
31+
resolution: func() -> duration;
32+
33+
/// Create a `pollable` which will resolve once the specified instant
34+
/// occured.
35+
subscribe-instant: func(
36+
when: instant,
37+
) -> pollable;
38+
39+
/// Create a `pollable` which will resolve once the given duration has
40+
/// elapsed, starting at the time at which this function was called.
41+
/// occured.
42+
subscribe-duration: func(
43+
when: duration,
44+
) -> pollable;
45+
}

preview2/clocks/wall-clock.wit

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package wasi:clocks@0.2.0;
2+
/// WASI Wall Clock is a clock API intended to let users query the current
3+
/// time. The name "wall" makes an analogy to a "clock on the wall", which
4+
/// is not necessarily monotonic as it may be reset.
5+
///
6+
/// It is intended to be portable at least between Unix-family platforms and
7+
/// Windows.
8+
///
9+
/// A wall clock is a clock which measures the date and time according to
10+
/// some external reference.
11+
///
12+
/// External references may be reset, so this clock is not necessarily
13+
/// monotonic, making it unsuitable for measuring elapsed time.
14+
///
15+
/// It is intended for reporting the current date and time for humans.
16+
interface wall-clock {
17+
/// A time and date in seconds plus nanoseconds.
18+
record datetime {
19+
seconds: u64,
20+
nanoseconds: u32,
21+
}
22+
23+
/// Read the current value of the clock.
24+
///
25+
/// This clock is not monotonic, therefore calling this function repeatedly
26+
/// will not necessarily produce a sequence of non-decreasing values.
27+
///
28+
/// The returned timestamps represent the number of seconds since
29+
/// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch],
30+
/// also known as [Unix Time].
31+
///
32+
/// The nanoseconds field of the output is always less than 1000000000.
33+
///
34+
/// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16
35+
/// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time
36+
now: func() -> datetime;
37+
38+
/// Query the resolution of the clock.
39+
///
40+
/// The nanoseconds field of the output is always less than 1000000000.
41+
resolution: func() -> datetime;
42+
}

0 commit comments

Comments
 (0)