Skip to content

Commit 13a1bef

Browse files
Include WASI 0.2.3 WITs (#3358)
Signed-off-by: Brian Hardock <[email protected]>
1 parent 0d99160 commit 13a1bef

34 files changed

+3273
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package wasi:cli@0.2.3;
2+
3+
@since(version = 0.2.0)
4+
world command {
5+
@since(version = 0.2.0)
6+
include imports;
7+
8+
@since(version = 0.2.0)
9+
export run;
10+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@since(version = 0.2.0)
2+
interface environment {
3+
/// Get the POSIX-style environment variables.
4+
///
5+
/// Each environment variable is provided as a pair of string variable names
6+
/// and string value.
7+
///
8+
/// Morally, these are a value import, but until value imports are available
9+
/// in the component model, this import function should return the same
10+
/// values each time it is called.
11+
@since(version = 0.2.0)
12+
get-environment: func() -> list<tuple<string, string>>;
13+
14+
/// Get the POSIX-style arguments to the program.
15+
@since(version = 0.2.0)
16+
get-arguments: func() -> list<string>;
17+
18+
/// Return a path that programs should use as their initial current working
19+
/// directory, interpreting `.` as shorthand for this.
20+
@since(version = 0.2.0)
21+
initial-cwd: func() -> option<string>;
22+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@since(version = 0.2.0)
2+
interface exit {
3+
/// Exit the current instance and any linked instances.
4+
@since(version = 0.2.0)
5+
exit: func(status: result);
6+
7+
/// Exit the current instance and any linked instances, reporting the
8+
/// specified status code to the host.
9+
///
10+
/// The meaning of the code depends on the context, with 0 usually meaning
11+
/// "success", and other values indicating various types of failure.
12+
///
13+
/// This function does not return; the effect is analogous to a trap, but
14+
/// without the connotation that something bad has happened.
15+
@unstable(feature = cli-exit-with-code)
16+
exit-with-code: func(status-code: u8);
17+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package wasi:cli@0.2.3;
2+
3+
@since(version = 0.2.0)
4+
world imports {
5+
@since(version = 0.2.0)
6+
include wasi:clocks/imports@0.2.3;
7+
@since(version = 0.2.0)
8+
include wasi:filesystem/imports@0.2.3;
9+
@since(version = 0.2.0)
10+
include wasi:sockets/imports@0.2.3;
11+
@since(version = 0.2.0)
12+
include wasi:random/imports@0.2.3;
13+
@since(version = 0.2.0)
14+
include wasi:io/imports@0.2.3;
15+
16+
@since(version = 0.2.0)
17+
import environment;
18+
@since(version = 0.2.0)
19+
import exit;
20+
@since(version = 0.2.0)
21+
import stdin;
22+
@since(version = 0.2.0)
23+
import stdout;
24+
@since(version = 0.2.0)
25+
import stderr;
26+
@since(version = 0.2.0)
27+
import terminal-input;
28+
@since(version = 0.2.0)
29+
import terminal-output;
30+
@since(version = 0.2.0)
31+
import terminal-stdin;
32+
@since(version = 0.2.0)
33+
import terminal-stdout;
34+
@since(version = 0.2.0)
35+
import terminal-stderr;
36+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@since(version = 0.2.0)
2+
interface run {
3+
/// Run the program.
4+
@since(version = 0.2.0)
5+
run: func() -> result;
6+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@since(version = 0.2.0)
2+
interface stdin {
3+
@since(version = 0.2.0)
4+
use wasi:io/streams@0.2.3.{input-stream};
5+
6+
@since(version = 0.2.0)
7+
get-stdin: func() -> input-stream;
8+
}
9+
10+
@since(version = 0.2.0)
11+
interface stdout {
12+
@since(version = 0.2.0)
13+
use wasi:io/streams@0.2.3.{output-stream};
14+
15+
@since(version = 0.2.0)
16+
get-stdout: func() -> output-stream;
17+
}
18+
19+
@since(version = 0.2.0)
20+
interface stderr {
21+
@since(version = 0.2.0)
22+
use wasi:io/streams@0.2.3.{output-stream};
23+
24+
@since(version = 0.2.0)
25+
get-stderr: func() -> output-stream;
26+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
@since(version = 0.2.0)
7+
interface terminal-input {
8+
/// The input side of a terminal.
9+
@since(version = 0.2.0)
10+
resource terminal-input;
11+
}
12+
13+
/// Terminal output.
14+
///
15+
/// In the future, this may include functions for querying the terminal
16+
/// size, being notified of terminal size changes, querying supported
17+
/// features, and so on.
18+
@since(version = 0.2.0)
19+
interface terminal-output {
20+
/// The output side of a terminal.
21+
@since(version = 0.2.0)
22+
resource terminal-output;
23+
}
24+
25+
/// An interface providing an optional `terminal-input` for stdin as a
26+
/// link-time authority.
27+
@since(version = 0.2.0)
28+
interface terminal-stdin {
29+
@since(version = 0.2.0)
30+
use terminal-input.{terminal-input};
31+
32+
/// If stdin is connected to a terminal, return a `terminal-input` handle
33+
/// allowing further interaction with it.
34+
@since(version = 0.2.0)
35+
get-terminal-stdin: func() -> option<terminal-input>;
36+
}
37+
38+
/// An interface providing an optional `terminal-output` for stdout as a
39+
/// link-time authority.
40+
@since(version = 0.2.0)
41+
interface terminal-stdout {
42+
@since(version = 0.2.0)
43+
use terminal-output.{terminal-output};
44+
45+
/// If stdout is connected to a terminal, return a `terminal-output` handle
46+
/// allowing further interaction with it.
47+
@since(version = 0.2.0)
48+
get-terminal-stdout: func() -> option<terminal-output>;
49+
}
50+
51+
/// An interface providing an optional `terminal-output` for stderr as a
52+
/// link-time authority.
53+
@since(version = 0.2.0)
54+
interface terminal-stderr {
55+
@since(version = 0.2.0)
56+
use terminal-output.{terminal-output};
57+
58+
/// If stderr is connected to a terminal, return a `terminal-output` handle
59+
/// allowing further interaction with it.
60+
@since(version = 0.2.0)
61+
get-terminal-stderr: func() -> option<terminal-output>;
62+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package wasi:clocks@0.2.3;
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+
@since(version = 0.2.0)
11+
interface monotonic-clock {
12+
@since(version = 0.2.0)
13+
use wasi:io/poll@0.2.3.{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+
@since(version = 0.2.0)
19+
type instant = u64;
20+
21+
/// A duration of time, in nanoseconds.
22+
@since(version = 0.2.0)
23+
type duration = u64;
24+
25+
/// Read the current value of the clock.
26+
///
27+
/// The clock is monotonic, therefore calling this function repeatedly will
28+
/// produce a sequence of non-decreasing values.
29+
@since(version = 0.2.0)
30+
now: func() -> instant;
31+
32+
/// Query the resolution of the clock. Returns the duration of time
33+
/// corresponding to a clock tick.
34+
@since(version = 0.2.0)
35+
resolution: func() -> duration;
36+
37+
/// Create a `pollable` which will resolve once the specified instant
38+
/// has occurred.
39+
@since(version = 0.2.0)
40+
subscribe-instant: func(
41+
when: instant,
42+
) -> pollable;
43+
44+
/// Create a `pollable` that will resolve after the specified duration has
45+
/// elapsed from the time this function is invoked.
46+
@since(version = 0.2.0)
47+
subscribe-duration: func(
48+
when: duration,
49+
) -> pollable;
50+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package wasi:clocks@0.2.3;
2+
3+
@unstable(feature = clocks-timezone)
4+
interface timezone {
5+
@unstable(feature = clocks-timezone)
6+
use wall-clock.{datetime};
7+
8+
/// Return information needed to display the given `datetime`. This includes
9+
/// the UTC offset, the time zone name, and a flag indicating whether
10+
/// daylight saving time is active.
11+
///
12+
/// If the timezone cannot be determined for the given `datetime`, return a
13+
/// `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight
14+
/// saving time.
15+
@unstable(feature = clocks-timezone)
16+
display: func(when: datetime) -> timezone-display;
17+
18+
/// The same as `display`, but only return the UTC offset.
19+
@unstable(feature = clocks-timezone)
20+
utc-offset: func(when: datetime) -> s32;
21+
22+
/// Information useful for displaying the timezone of a specific `datetime`.
23+
///
24+
/// This information may vary within a single `timezone` to reflect daylight
25+
/// saving time adjustments.
26+
@unstable(feature = clocks-timezone)
27+
record timezone-display {
28+
/// The number of seconds difference between UTC time and the local
29+
/// time of the timezone.
30+
///
31+
/// The returned value will always be less than 86400 which is the
32+
/// number of seconds in a day (24*60*60).
33+
///
34+
/// In implementations that do not expose an actual time zone, this
35+
/// should return 0.
36+
utc-offset: s32,
37+
38+
/// The abbreviated name of the timezone to display to a user. The name
39+
/// `UTC` indicates Coordinated Universal Time. Otherwise, this should
40+
/// reference local standards for the name of the time zone.
41+
///
42+
/// In implementations that do not expose an actual time zone, this
43+
/// should be the string `UTC`.
44+
///
45+
/// In time zones that do not have an applicable name, a formatted
46+
/// representation of the UTC offset may be returned, such as `-04:00`.
47+
name: string,
48+
49+
/// Whether daylight saving time is active.
50+
///
51+
/// In implementations that do not expose an actual time zone, this
52+
/// should return false.
53+
in-daylight-saving-time: bool,
54+
}
55+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package wasi:clocks@0.2.3;
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+
@since(version = 0.2.0)
17+
interface wall-clock {
18+
/// A time and date in seconds plus nanoseconds.
19+
@since(version = 0.2.0)
20+
record datetime {
21+
seconds: u64,
22+
nanoseconds: u32,
23+
}
24+
25+
/// Read the current value of the clock.
26+
///
27+
/// This clock is not monotonic, therefore calling this function repeatedly
28+
/// will not necessarily produce a sequence of non-decreasing values.
29+
///
30+
/// The returned timestamps represent the number of seconds since
31+
/// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch],
32+
/// also known as [Unix Time].
33+
///
34+
/// The nanoseconds field of the output is always less than 1000000000.
35+
///
36+
/// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16
37+
/// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time
38+
@since(version = 0.2.0)
39+
now: func() -> datetime;
40+
41+
/// Query the resolution of the clock.
42+
///
43+
/// The nanoseconds field of the output is always less than 1000000000.
44+
@since(version = 0.2.0)
45+
resolution: func() -> datetime;
46+
}

0 commit comments

Comments
 (0)