repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by bugabinga

feat(harness): sealed WASI shims replace wasmtime-wasi; wasmtime async off

33d04b803551d1fde44d50dfbdadbe281633fcae

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (9)

+968 / −253 text lines

Diff layout

Cargo.lock

Modified

+9 / −225 text lines

3535source = "registry+https://github.com/rust-lang/crates.io-index"
3636checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
38[[package]]
39name = "ambient-authority"
40version = "0.0.2"
41source = "registry+https://github.com/rust-lang/crates.io-index"
42checksum = "e9d4ee0d472d1cd2e28c97dfa124b3d8d992e10eb0a035f33f5d12e3a177ba3b"
4438[[package]]
4539name = "anes"
4640version = "0.1.6"
240234 "serde_core",
243[[package]]
244name = "cap-primitives"
245version = "4.0.3"
246source = "registry+https://github.com/rust-lang/crates.io-index"
247checksum = "8b5f74729fd2f44701d1a8eb47e906cdb3ccd9ec0f02baad85a744b791940b18"
248dependencies = [
249 "ambient-authority",
250 "fs-set-times",
251 "io-extras",
252 "io-lifetimes 3.0.1",
253 "ipnet",
254 "maybe-owned",
255 "rustix",
256 "rustix-linux-procfs",
257 "windows-sys 0.61.2",
258 "winx",
259]
261237[[package]]
262238name = "cargo-platform"
263239version = "0.2.0"
870846 "percent-encoding",
873[[package]]
874name = "fs-set-times"
875version = "0.20.3"
876source = "registry+https://github.com/rust-lang/crates.io-index"
877checksum = "94e7099f6313ecacbe1256e8ff9d617b75d1bcb16a6fddef94866d225a01a14a"
878dependencies = [
879 "io-lifetimes 2.0.4",
880 "rustix",
881 "windows-sys 0.59.0",
882]
884849[[package]]
885850name = "fs2"
886851version = "0.4.3"
13171282 "serde_core",
1320[[package]]
1321name = "io-extras"
1322version = "0.19.0"
1323source = "registry+https://github.com/rust-lang/crates.io-index"
1324checksum = "20fd6de4ccfcc187e38bc21cfa543cb5a302cb86a8b114eb7f0bf0dc9f8ac00f"
1325dependencies = [
1326 "io-lifetimes 3.0.1",
1327 "windows-sys 0.60.2",
1330[[package]]
1331name = "io-lifetimes"
1332version = "2.0.4"
1333source = "registry+https://github.com/rust-lang/crates.io-index"
1334checksum = "06432fb54d3be7964ecd3649233cddf80db2832f47fec34c01f65b3d9d774983"
1336[[package]]
1337name = "io-lifetimes"
1338version = "3.0.1"
1339source = "registry+https://github.com/rust-lang/crates.io-index"
1340checksum = "2f0fb0570afe1fed943c5c3d4102d5358592d8625fda6a0007fdbe65a92fba96"
13421285[[package]]
13431286name = "ipnet"
13441287version = "2.12.2"
15021445source = "registry+https://github.com/rust-lang/crates.io-index"
15031446checksum = "dae608c151f68243f2b000364e1f7b186d9c29845f7d2d85bd31b9ad77ad552b"
1505[[package]]
1506name = "maybe-owned"
1507version = "0.3.4"
1508source = "registry+https://github.com/rust-lang/crates.io-index"
1509checksum = "4facc753ae494aeb6e3c22f839b158aebd4f9270f55cd3c79906c45476c47ab4"
15111448[[package]]
15121449name = "memchr"
15131450version = "2.8.3"
20281965 "windows-sys 0.61.2",
2031[[package]]
2032name = "rustix-linux-procfs"
2033version = "0.1.1"
2034source = "registry+https://github.com/rust-lang/crates.io-index"
2035checksum = "2fc84bf7e9aa16c4f2c758f27412dc9841341e16aa682d9c7ac308fe3ee12056"
2036dependencies = [
2037 "once_cell",
2038 "rustix",
20411968[[package]]
20421969name = "rustls"
20431970version = "0.23.45"
23612288 "smith-ai",
23622289 "smith-core",
23632290 "wasmtime",
2364 "wasmtime-wasi",
23672293[[package]]
26772603checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
26782604dependencies = [
26792605 "pin-project-lite",
2680 "tracing-attributes",
26812606 "tracing-core",
2684[[package]]
2685name = "tracing-attributes"
2686version = "0.1.31"
2687source = "registry+https://github.com/rust-lang/crates.io-index"
2688checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da"
2689dependencies = [
2690 "proc-macro2",
2691 "quote",
2692 "syn 2.0.119",
26952609[[package]]
26962610name = "tracing-core"
26972611version = "0.1.36"
31643078 "wit-parser 0.258.0",
3167[[package]]
3168name = "wasmtime-wasi"
3169version = "49.0.1"
3170source = "registry+https://github.com/rust-lang/crates.io-index"
3171checksum = "ce11727cb331abeaace3681a4b072e4fe04818d7b99786d183b318671f9e4e0e"
3172dependencies = [
3173 "async-trait",
3174 "bitflags",
3175 "bytes",
3176 "cap-primitives",
3177 "futures",
3178 "rand",
3179 "rustix",
3180 "rustix-linux-procfs",
3181 "thiserror 2.0.21",
3182 "tokio",
3183 "tracing",
3184 "url",
3185 "wasmtime",
3186 "wasmtime-wasi-io",
3187 "windows-sys 0.61.2",
3188 "winx",
3191[[package]]
3192name = "wasmtime-wasi-io"
3193version = "49.0.1"
3194source = "registry+https://github.com/rust-lang/crates.io-index"
3195checksum = "35f5ed8d710d8daf71cb4742c6b90c1fd121acb62b6848556eb4e0661cbd28bd"
3196dependencies = [
3197 "async-trait",
3198 "bytes",
3199 "futures",
3200 "tracing",
3201 "wasmtime",
32043081[[package]]
32053082name = "web-sys"
32063083version = "0.3.106"
32733150source = "registry+https://github.com/rust-lang/crates.io-index"
32743151checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
32753152dependencies = [
3276 "windows-targets 0.52.6",
3279[[package]]
3280name = "windows-sys"
3281version = "0.59.0"
3282source = "registry+https://github.com/rust-lang/crates.io-index"
3283checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
3284dependencies = [
3285 "windows-targets 0.52.6",
3288[[package]]
3289name = "windows-sys"
3290version = "0.60.2"
3291source = "registry+https://github.com/rust-lang/crates.io-index"
3292checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb"
3293dependencies = [
3294 "windows-targets 0.53.5",
3153 "windows-targets",
32973156[[package]]
33093168source = "registry+https://github.com/rust-lang/crates.io-index"
33103169checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
33113170dependencies = [
3312 "windows_aarch64_gnullvm 0.52.6",
3313 "windows_aarch64_msvc 0.52.6",
3314 "windows_i686_gnu 0.52.6",
3315 "windows_i686_gnullvm 0.52.6",
3316 "windows_i686_msvc 0.52.6",
3317 "windows_x86_64_gnu 0.52.6",
3318 "windows_x86_64_gnullvm 0.52.6",
3319 "windows_x86_64_msvc 0.52.6",
3322[[package]]
3323name = "windows-targets"
3324version = "0.53.5"
3325source = "registry+https://github.com/rust-lang/crates.io-index"
3326checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3"
3327dependencies = [
3328 "windows-link",
3329 "windows_aarch64_gnullvm 0.53.1",
3330 "windows_aarch64_msvc 0.53.1",
3331 "windows_i686_gnu 0.53.1",
3332 "windows_i686_gnullvm 0.53.1",
3333 "windows_i686_msvc 0.53.1",
3334 "windows_x86_64_gnu 0.53.1",
3335 "windows_x86_64_gnullvm 0.53.1",
3336 "windows_x86_64_msvc 0.53.1",
3171 "windows_aarch64_gnullvm",
3172 "windows_aarch64_msvc",
3173 "windows_i686_gnu",
3174 "windows_i686_gnullvm",
3175 "windows_i686_msvc",
3176 "windows_x86_64_gnu",
3177 "windows_x86_64_gnullvm",
3178 "windows_x86_64_msvc",
33393181[[package]]
33423184source = "registry+https://github.com/rust-lang/crates.io-index"
33433185checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
3345[[package]]
3346name = "windows_aarch64_gnullvm"
3347version = "0.53.1"
3348source = "registry+https://github.com/rust-lang/crates.io-index"
3349checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53"
33513187[[package]]
33523188name = "windows_aarch64_msvc"
33533189version = "0.52.6"
33543190source = "registry+https://github.com/rust-lang/crates.io-index"
33553191checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
3357[[package]]
3358name = "windows_aarch64_msvc"
3359version = "0.53.1"
3360source = "registry+https://github.com/rust-lang/crates.io-index"
3361checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006"
33633193[[package]]
33643194name = "windows_i686_gnu"
33653195version = "0.52.6"
33663196source = "registry+https://github.com/rust-lang/crates.io-index"
33673197checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
3369[[package]]
3370name = "windows_i686_gnu"
3371version = "0.53.1"
3372source = "registry+https://github.com/rust-lang/crates.io-index"
3373checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3"
33753199[[package]]
33763200name = "windows_i686_gnullvm"
33773201version = "0.52.6"
33783202source = "registry+https://github.com/rust-lang/crates.io-index"
33793203checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
3381[[package]]
3382name = "windows_i686_gnullvm"
3383version = "0.53.1"
3384source = "registry+https://github.com/rust-lang/crates.io-index"
3385checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c"
33873205[[package]]
33883206name = "windows_i686_msvc"
33893207version = "0.52.6"
33903208source = "registry+https://github.com/rust-lang/crates.io-index"
33913209checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
3393[[package]]
3394name = "windows_i686_msvc"
3395version = "0.53.1"
3396source = "registry+https://github.com/rust-lang/crates.io-index"
3397checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2"
33993211[[package]]
34003212name = "windows_x86_64_gnu"
34013213version = "0.52.6"
34023214source = "registry+https://github.com/rust-lang/crates.io-index"
34033215checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
3405[[package]]
3406name = "windows_x86_64_gnu"
3407version = "0.53.1"
3408source = "registry+https://github.com/rust-lang/crates.io-index"
3409checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499"
34113217[[package]]
34123218name = "windows_x86_64_gnullvm"
34133219version = "0.52.6"
34143220source = "registry+https://github.com/rust-lang/crates.io-index"
34153221checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
3417[[package]]
3418name = "windows_x86_64_gnullvm"
3419version = "0.53.1"
3420source = "registry+https://github.com/rust-lang/crates.io-index"
3421checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1"
34233223[[package]]
34243224name = "windows_x86_64_msvc"
34253225version = "0.52.6"
34263226source = "registry+https://github.com/rust-lang/crates.io-index"
34273227checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
3429[[package]]
3430name = "windows_x86_64_msvc"
3431version = "0.53.1"
3432source = "registry+https://github.com/rust-lang/crates.io-index"
3433checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650"
34353229[[package]]
34363230name = "winnow"
34373231version = "0.7.15"
34413235 "memchr",
3444[[package]]
3445name = "winx"
3446version = "0.36.4"
3447source = "registry+https://github.com/rust-lang/crates.io-index"
3448checksum = "3f3fd376f71958b862e7afb20cfe5a22830e1963462f3a17f49d82a6c1d1f42d"
3449dependencies = [
3450 "bitflags",
3451 "windows-sys 0.59.0",
34543238[[package]]
34553239name = "wit-bindgen"
34563240version = "0.62.0"

Cargo.toml

Modified

+0 / −3 text lines

6363 "cranelift",
6464 "demangle",
6565] } # smith-harness, wasm plugin engine
66wasmtime-wasi = { version = "49", default-features = false, features = [
67 "p2",
68] } # smith-harness, scoped wasi:io/poll linking
6966tracing-subscriber = { version = "0.3", features = ["env-filter"] } # smith-cli, log output
7067similar = "2" # diff
7168ignore = "0.4" # search stack

smith-cli/tests/architecture.rs

Modified

+1 / −2 text lines

6666 .in_path("smith-core/src/**")
6767 .should_not()
6868 .depend_on_external_modules()
69 .matching("wasmtime")
70 .matching("wasmtime-wasi");
69 .matching("wasmtime");
7170 assert_passes!(rule);

smith-harness/Cargo.toml

Modified

+0 / −1 text lines

1212smith-core = { path = "../smith-core", version = "0.1.0" }
1313smith-ai = { path = "../smith-ai", version = "0.1.0" }
1414wasmtime = { workspace = true }
15wasmtime-wasi = { workspace = true }
1615futures = { workspace = true }
1716reqwest = { workspace = true }

smith-harness/src/wasm.rs

Modified

+36 / −22 text lines

77use ::smith::error::{ProviderFault, Result, SmithError};
88use std::path::Path;
99use wasmtime::component::{Component, Linker};
10use wasmtime::{Config, Engine, Store, component::ResourceTable};
10use wasmtime::{Config, Engine, Store};
12mod sealed_wasi;
1214#[allow(missing_docs, reason = "generated bindings carry no doc comments")]
1315pub mod bindings {
16 // The host world: the guest-facing plugin world plus exactly the WASI
17 // imports Rust std on wasm32-wasip2 pulls in, all served by Smith's
18 // sealed implementations in `sealed_wasi`.
1419 wasmtime::component::bindgen!({
15 path: "../wit/smith-plugin.wit",
16 world: "plugin-world",
20 path: "../wit",
21 inline: "
22 package smith:host;
23 world plugin-host {
24 include smith:plugin/plugin-world@0.1.0;
25 import wasi:io/error@0.2.12;
26 import wasi:io/poll@0.2.12;
27 import wasi:io/streams@0.2.12;
28 import wasi:clocks/monotonic-clock@0.2.12;
29 import wasi:cli/environment@0.2.12;
30 import wasi:cli/exit@0.2.12;
31 import wasi:cli/stdin@0.2.12;
32 import wasi:cli/stdout@0.2.12;
33 import wasi:cli/stderr@0.2.12;
34 import wasi:cli/terminal-stdin@0.2.12;
35 import wasi:cli/terminal-stdout@0.2.12;
36 import wasi:cli/terminal-stderr@0.2.12;
37 }
38 ",
39 imports: {
40 "wasi:cli/exit.exit": trappable,
41 "wasi:cli/exit.exit-with-code": trappable,
42 },
1743 });
20use self::bindings::PluginWorld;
46use self::bindings::PluginHost;
2147use self::bindings::exports::smith::plugin::plugin::ToolDeclaration;
2248use self::bindings::smith::plugin::tooling::Host as ToolingHost;
6490/// One instantiated plugin: pinned store, fuel budget, and bindings.
6591pub struct PluginInstance {
6692 store: Store<PluginHostState>,
67 bindings: PluginWorld,
93 bindings: PluginHost,
7096/// Per-plugin runtime ceilings.
88114struct PluginHostState {
89 table: ResourceTable,
90 wasi: wasmtime_wasi::WasiCtx,
115 /// Host-injected monotonic clock reading; the guest never sees OS time.
116 monotonic_now: u64,
91117 ceilings: PluginCeilings,
128154 let mut store = Store::new(
129155 engine.engine(),
130156 PluginHostState {
131 table: ResourceTable::new(),
132 wasi: wasmtime_wasi::WasiCtxBuilder::new().build(),
157 monotonic_now: 0,
133158 ceilings: PluginCeilings::default(),
134159 },
135160 );
138163 .set_fuel(PluginCeilings::default().fuel)
139164 .map_err(|e| plugin_fault(format!("fuel setup failed: {e}")))?;
140165 let mut linker: Linker<PluginHostState> = Linker::new(engine.engine());
141 wasmtime_wasi::p2::add_to_linker_sync::<PluginHostState>(&mut linker)
142 .map_err(|e| plugin_fault(format!("wasi linking failed: {e}")))?;
143 PluginWorld::add_to_linker::<PluginHostState, PluginHasSelf>(&mut linker, |state| state)
166 PluginHost::add_to_linker::<PluginHostState, PluginHasSelf>(&mut linker, |state| state)
144167 .map_err(|e| plugin_fault(format!("linker setup failed: {e}")))?;
145 let bindings = PluginWorld::instantiate(&mut store, &component, &linker)
168 let bindings = PluginHost::instantiate(&mut store, &component, &linker)
146169 .map_err(|e| plugin_fault(format!("instantiation failed: {e}")))?;
147170 Ok(Self { store, bindings })
148171 }
196219impl ToolingHost for PluginHostState {}
198impl wasmtime_wasi::WasiView for PluginHostState {
199 fn ctx(&mut self) -> wasmtime_wasi::WasiCtxView<'_> {
200 wasmtime_wasi::WasiCtxView {
201 ctx: &mut self.wasi,
202 table: &mut self.table,
203 }
204 }
205}

smith-harness/src/wasm/sealed_wasi.rs

Added
new file mode 100644

+313 / −0 text lines

1//! Sealed WASI: Smith's own synchronous implementations of the WASI imports
2//! that guest std runtimes pull in (`SMH-SPEC-WASM0001`, no ambient WASI).
3//!
4//! Sealed by default: empty environment and arguments, empty stdin, stdout
5//! and stderr writes discarded, no terminals, `exit` traps, the monotonic
6//! clock reads a host-injected value, and every pollable is ready.
7//!
8//! No host state backs a stream or pollable, so resources are bare handles
9//! with no table entry; dropping one is a no-op.
11use super::PluginHostState;
12use super::bindings::wasi::cli::{
13 environment, exit, stderr, stdin, stdout, terminal_input, terminal_output, terminal_stderr,
14 terminal_stdin, terminal_stdout,
15};
16use super::bindings::wasi::clocks::monotonic_clock;
17use super::bindings::wasi::io::error::{self, Error};
18use super::bindings::wasi::io::poll::{self, Pollable};
19use super::bindings::wasi::io::streams::{self, InputStream, OutputStream, StreamError};
20use wasmtime::component::Resource;
22/// The only handle value ever minted; no handle carries host state.
23const SEALED: u32 = 0;
25/// Bytes a sealed output stream accepts per write; writes are discarded.
26const WRITE_BUDGET: u64 = 4096;
28fn sealed<T: 'static>() -> Resource<T> {
29 Resource::new_own(SEALED)
30}
32impl poll::HostPollable for PluginHostState {
33 fn ready(&mut self, _pollable: Resource<Pollable>) -> bool {
34 true
35 }
37 fn block(&mut self, _pollable: Resource<Pollable>) {}
39 fn drop(&mut self, _pollable: Resource<Pollable>) -> wasmtime::Result<()> {
40 Ok(())
41 }
42}
44impl poll::Host for PluginHostState {
45 fn poll(&mut self, pollables: Vec<Resource<Pollable>>) -> Vec<u32> {
46 (0..u32::try_from(pollables.len()).unwrap_or(u32::MAX)).collect()
47 }
48}
50impl error::HostError for PluginHostState {
51 fn to_debug_string(&mut self, _error: Resource<Error>) -> String {
52 String::new()
53 }
55 fn drop(&mut self, _error: Resource<Error>) -> wasmtime::Result<()> {
56 Ok(())
57 }
58}
60impl error::Host for PluginHostState {}
62impl streams::HostInputStream for PluginHostState {
63 fn read(&mut self, _stream: Resource<InputStream>, _len: u64) -> Result<Vec<u8>, StreamError> {
64 Err(StreamError::Closed)
65 }
67 fn blocking_read(
68 &mut self,
69 _stream: Resource<InputStream>,
70 _len: u64,
71 ) -> Result<Vec<u8>, StreamError> {
72 Err(StreamError::Closed)
73 }
75 fn skip(&mut self, _stream: Resource<InputStream>, _len: u64) -> Result<u64, StreamError> {
76 Err(StreamError::Closed)
77 }
79 fn blocking_skip(
80 &mut self,
81 _stream: Resource<InputStream>,
82 _len: u64,
83 ) -> Result<u64, StreamError> {
84 Err(StreamError::Closed)
85 }
87 fn subscribe(&mut self, _stream: Resource<InputStream>) -> Resource<Pollable> {
88 sealed()
89 }
91 fn drop(&mut self, _stream: Resource<InputStream>) -> wasmtime::Result<()> {
92 Ok(())
93 }
94}
96impl streams::HostOutputStream for PluginHostState {
97 fn check_write(&mut self, _stream: Resource<OutputStream>) -> Result<u64, StreamError> {
98 Ok(WRITE_BUDGET)
99 }
101 fn write(
102 &mut self,
103 _stream: Resource<OutputStream>,
104 _contents: Vec<u8>,
105 ) -> Result<(), StreamError> {
106 Ok(())
107 }
109 fn blocking_write_and_flush(
110 &mut self,
111 _stream: Resource<OutputStream>,
112 _contents: Vec<u8>,
113 ) -> Result<(), StreamError> {
114 Ok(())
115 }
117 fn flush(&mut self, _stream: Resource<OutputStream>) -> Result<(), StreamError> {
118 Ok(())
119 }
121 fn blocking_flush(&mut self, _stream: Resource<OutputStream>) -> Result<(), StreamError> {
122 Ok(())
123 }
125 fn subscribe(&mut self, _stream: Resource<OutputStream>) -> Resource<Pollable> {
126 sealed()
127 }
129 fn write_zeroes(
130 &mut self,
131 _stream: Resource<OutputStream>,
132 _len: u64,
133 ) -> Result<(), StreamError> {
134 Ok(())
135 }
137 fn blocking_write_zeroes_and_flush(
138 &mut self,
139 _stream: Resource<OutputStream>,
140 _len: u64,
141 ) -> Result<(), StreamError> {
142 Ok(())
143 }
145 fn splice(
146 &mut self,
147 _stream: Resource<OutputStream>,
148 _source: Resource<InputStream>,
149 _len: u64,
150 ) -> Result<u64, StreamError> {
151 Err(StreamError::Closed)
152 }
154 fn blocking_splice(
155 &mut self,
156 _stream: Resource<OutputStream>,
157 _source: Resource<InputStream>,
158 _len: u64,
159 ) -> Result<u64, StreamError> {
160 Err(StreamError::Closed)
161 }
163 fn drop(&mut self, _stream: Resource<OutputStream>) -> wasmtime::Result<()> {
164 Ok(())
165 }
166}
168impl streams::Host for PluginHostState {}
170impl monotonic_clock::Host for PluginHostState {
171 fn now(&mut self) -> monotonic_clock::Instant {
172 self.monotonic_now
173 }
175 fn resolution(&mut self) -> monotonic_clock::Duration {
176 1
177 }
179 fn subscribe_instant(&mut self, _when: monotonic_clock::Instant) -> Resource<Pollable> {
180 sealed()
181 }
183 fn subscribe_duration(&mut self, _when: monotonic_clock::Duration) -> Resource<Pollable> {
184 sealed()
185 }
186}
188impl environment::Host for PluginHostState {
189 fn get_environment(&mut self) -> Vec<(String, String)> {
190 Vec::new()
191 }
193 fn get_arguments(&mut self) -> Vec<String> {
194 Vec::new()
195 }
197 fn initial_cwd(&mut self) -> Option<String> {
198 None
199 }
200}
202impl exit::Host for PluginHostState {
203 fn exit(&mut self, status: Result<(), ()>) -> wasmtime::Result<()> {
204 Err(wasmtime::format_err!("guest exited: {status:?}"))
205 }
207 fn exit_with_code(&mut self, status_code: u8) -> wasmtime::Result<()> {
208 Err(wasmtime::format_err!(
209 "guest exited with code {status_code}"
210 ))
211 }
212}
214impl stdin::Host for PluginHostState {
215 fn get_stdin(&mut self) -> Resource<InputStream> {
216 sealed()
217 }
218}
220impl stdout::Host for PluginHostState {
221 fn get_stdout(&mut self) -> Resource<OutputStream> {
222 sealed()
223 }
224}
226impl stderr::Host for PluginHostState {
227 fn get_stderr(&mut self) -> Resource<OutputStream> {
228 sealed()
229 }
230}
232impl terminal_input::HostTerminalInput for PluginHostState {
233 fn drop(&mut self, _terminal: Resource<terminal_input::TerminalInput>) -> wasmtime::Result<()> {
234 Ok(())
235 }
236}
238impl terminal_input::Host for PluginHostState {}
240impl terminal_output::HostTerminalOutput for PluginHostState {
241 fn drop(
242 &mut self,
243 _terminal: Resource<terminal_output::TerminalOutput>,
244 ) -> wasmtime::Result<()> {
245 Ok(())
246 }
247}
249impl terminal_output::Host for PluginHostState {}
251impl terminal_stdin::Host for PluginHostState {
252 fn get_terminal_stdin(&mut self) -> Option<Resource<terminal_input::TerminalInput>> {
253 None
254 }
255}
257impl terminal_stdout::Host for PluginHostState {
258 fn get_terminal_stdout(&mut self) -> Option<Resource<terminal_output::TerminalOutput>> {
259 None
260 }
261}
263impl terminal_stderr::Host for PluginHostState {
264 fn get_terminal_stderr(&mut self) -> Option<Resource<terminal_output::TerminalOutput>> {
265 None
266 }
267}
269#[cfg(test)]
270mod tests {
271 use super::*;
272 use crate::wasm::PluginCeilings;
273 use poll::Host as _;
274 use streams::{HostInputStream as _, HostOutputStream as _};
276 fn state() -> PluginHostState {
277 PluginHostState {
278 monotonic_now: 42,
279 ceilings: PluginCeilings::default(),
280 }
281 }
283 #[test]
284 fn poll_reports_every_pollable_ready() {
285 let mut host = state();
286 assert_eq!(host.poll(vec![sealed(), sealed(), sealed()]), [0, 1, 2]);
287 assert!(host.poll(Vec::new()).is_empty());
288 }
290 #[test]
291 fn stdin_is_closed_and_stdout_discards() {
292 let mut host = state();
293 assert!(matches!(host.read(sealed(), 16), Err(StreamError::Closed)));
294 assert_eq!(host.check_write(sealed()).unwrap(), WRITE_BUDGET);
295 assert!(host.write(sealed(), b"dropped".to_vec()).is_ok());
296 }
298 #[test]
299 fn clock_is_host_injected_and_exit_traps() {
300 let mut host = state();
301 assert_eq!(monotonic_clock::Host::now(&mut host), 42);
302 assert!(exit::Host::exit(&mut host, Ok(())).is_err());
303 assert!(exit::Host::exit_with_code(&mut host, 0).is_err());
304 }
306 #[test]
307 fn environment_is_empty() {
308 let mut host = state();
309 assert!(environment::Host::get_environment(&mut host).is_empty());
310 assert!(environment::Host::get_arguments(&mut host).is_empty());
311 assert!(environment::Host::initial_cwd(&mut host).is_none());
312 }
313}

wit/deps/cli.wit

Added
new file mode 100644

+144 / −0 text lines

1// Copied from wasmtime-wasi 49.0.1 `src/p2/wit/deps/cli.wit`
2// (Apache-2.0 WITH LLVM-exception).
3// Modified: the `imports` and `command` worlds are removed; they pull in
4// filesystem, sockets, and random, which Smith never grants ambiently.
5// Interfaces are unchanged.
6package wasi:cli@0.2.12;
7
8@since(version = 0.2.0)
9interface environment {
10 /// Get the POSIX-style environment variables.
11 ///
12 /// Each environment variable is provided as a pair of string variable names
13 /// and string value.
14 ///
15 /// Morally, these are a value import, but until value imports are available
16 /// in the component model, this import function should return the same
17 /// values each time it is called.
18 @since(version = 0.2.0)
19 get-environment: func() -> list<tuple<string, string>>;
21 /// Get the POSIX-style arguments to the program.
22 @since(version = 0.2.0)
23 get-arguments: func() -> list<string>;
25 /// Return a path that programs should use as their initial current working
26 /// directory, interpreting `.` as shorthand for this.
27 @since(version = 0.2.0)
28 initial-cwd: func() -> option<string>;
29}
31@since(version = 0.2.0)
32interface exit {
33 /// Exit the current instance and any linked instances.
34 @since(version = 0.2.0)
35 exit: func(status: result);
37 /// Exit the current instance and any linked instances, reporting the
38 /// specified status code to the host.
39 ///
40 /// The meaning of the code depends on the context, with 0 usually meaning
41 /// "success", and other values indicating various types of failure.
42 ///
43 /// This function does not return; the effect is analogous to a trap, but
44 /// without the connotation that something bad has happened.
45 @since(version = 0.2.12)
46 exit-with-code: func(status-code: u8);
47}
49@since(version = 0.2.0)
50interface run {
51 /// Run the program.
52 @since(version = 0.2.0)
53 run: func() -> result;
54}
56@since(version = 0.2.0)
57interface stdin {
58 @since(version = 0.2.0)
59 use wasi:io/streams@0.2.12.{input-stream};
61 @since(version = 0.2.0)
62 get-stdin: func() -> input-stream;
63}
65@since(version = 0.2.0)
66interface stdout {
67 @since(version = 0.2.0)
68 use wasi:io/streams@0.2.12.{output-stream};
70 @since(version = 0.2.0)
71 get-stdout: func() -> output-stream;
72}
74@since(version = 0.2.0)
75interface stderr {
76 @since(version = 0.2.0)
77 use wasi:io/streams@0.2.12.{output-stream};
79 @since(version = 0.2.0)
80 get-stderr: func() -> output-stream;
81}
83/// Terminal input.
84///
85/// In the future, this may include functions for disabling echoing,
86/// disabling input buffering so that keyboard events are sent through
87/// immediately, querying supported features, and so on.
88@since(version = 0.2.0)
89interface terminal-input {
90 /// The input side of a terminal.
91 @since(version = 0.2.0)
92 resource terminal-input;
93}
95/// Terminal output.
96///
97/// In the future, this may include functions for querying the terminal
98/// size, being notified of terminal size changes, querying supported
99/// features, and so on.
100@since(version = 0.2.0)
101interface terminal-output {
102 /// The output side of a terminal.
103 @since(version = 0.2.0)
104 resource terminal-output;
105}
107/// An interface providing an optional `terminal-input` for stdin as a
108/// link-time authority.
109@since(version = 0.2.0)
110interface terminal-stdin {
111 @since(version = 0.2.0)
112 use terminal-input.{terminal-input};
114 /// If stdin is connected to a terminal, return a `terminal-input` handle
115 /// allowing further interaction with it.
116 @since(version = 0.2.0)
117 get-terminal-stdin: func() -> option<terminal-input>;
118}
120/// An interface providing an optional `terminal-output` for stdout as a
121/// link-time authority.
122@since(version = 0.2.0)
123interface terminal-stdout {
124 @since(version = 0.2.0)
125 use terminal-output.{terminal-output};
127 /// If stdout is connected to a terminal, return a `terminal-output` handle
128 /// allowing further interaction with it.
129 @since(version = 0.2.0)
130 get-terminal-stdout: func() -> option<terminal-output>;
131}
133/// An interface providing an optional `terminal-output` for stderr as a
134/// link-time authority.
135@since(version = 0.2.0)
136interface terminal-stderr {
137 @since(version = 0.2.0)
138 use terminal-output.{terminal-output};
140 /// If stderr is connected to a terminal, return a `terminal-output` handle
141 /// allowing further interaction with it.
142 @since(version = 0.2.0)
143 get-terminal-stderr: func() -> option<terminal-output>;
144}

wit/deps/clocks.wit

Added
new file mode 100644

+164 / −0 text lines

1// Copied verbatim from wasmtime-wasi 49.0.1 `src/p2/wit/deps/clocks.wit`
2// (Apache-2.0 WITH LLVM-exception).
3package wasi:clocks@0.2.12;
4
5/// WASI Monotonic Clock is a clock API intended to let users measure elapsed
6/// time.
7///
8/// It is intended to be portable at least between Unix-family platforms and
9/// Windows.
10///
11/// A monotonic clock is a clock which has an unspecified initial value, and
12/// successive reads of the clock will produce non-decreasing values.
13@since(version = 0.2.0)
14interface monotonic-clock {
15 @since(version = 0.2.0)
16 use wasi:io/poll@0.2.12.{pollable};
18 /// An instant in time, in nanoseconds. An instant is relative to an
19 /// unspecified initial value, and can only be compared to instances from
20 /// the same monotonic-clock.
21 @since(version = 0.2.0)
22 type instant = u64;
24 /// A duration of time, in nanoseconds.
25 @since(version = 0.2.0)
26 type duration = u64;
28 /// Read the current value of the clock.
29 ///
30 /// The clock is monotonic, therefore calling this function repeatedly will
31 /// produce a sequence of non-decreasing values.
32 ///
33 /// For completeness, this function traps if it's not possible to represent
34 /// the value of the clock in an `instant`. Consequently, implementations
35 /// should ensure that the starting time is low enough to avoid the
36 /// possibility of overflow in practice.
37 @since(version = 0.2.0)
38 now: func() -> instant;
40 /// Query the resolution of the clock. Returns the duration of time
41 /// corresponding to a clock tick.
42 @since(version = 0.2.0)
43 resolution: func() -> duration;
45 /// Create a `pollable` which will resolve once the specified instant
46 /// has occurred.
47 @since(version = 0.2.0)
48 subscribe-instant: func(when: instant) -> pollable;
50 /// Create a `pollable` that will resolve after the specified duration has
51 /// elapsed from the time this function is invoked.
52 @since(version = 0.2.0)
53 subscribe-duration: func(when: duration) -> pollable;
54}
56/// WASI Wall Clock is a clock API intended to let users query the current
57/// time. The name "wall" makes an analogy to a "clock on the wall", which
58/// is not necessarily monotonic as it may be reset.
59///
60/// It is intended to be portable at least between Unix-family platforms and
61/// Windows.
62///
63/// A wall clock is a clock which measures the date and time according to
64/// some external reference.
65///
66/// External references may be reset, so this clock is not necessarily
67/// monotonic, making it unsuitable for measuring elapsed time.
68///
69/// It is intended for reporting the current date and time for humans.
70@since(version = 0.2.0)
71interface wall-clock {
72 /// A time and date in seconds plus nanoseconds.
73 @since(version = 0.2.0)
74 record datetime {
75 seconds: u64,
76 nanoseconds: u32,
77 }
79 /// Read the current value of the clock.
80 ///
81 /// This clock is not monotonic, therefore calling this function repeatedly
82 /// will not necessarily produce a sequence of non-decreasing values.
83 ///
84 /// The returned timestamps represent the number of seconds since
85 /// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch],
86 /// also known as [Unix Time].
87 ///
88 /// The nanoseconds field of the output is always less than 1000000000.
89 ///
90 /// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16
91 /// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time
92 @since(version = 0.2.0)
93 now: func() -> datetime;
95 /// Query the resolution of the clock.
96 ///
97 /// The nanoseconds field of the output is always less than 1000000000.
98 @since(version = 0.2.0)
99 resolution: func() -> datetime;
100}
102@unstable(feature = clocks-timezone)
103interface timezone {
104 @unstable(feature = clocks-timezone)
105 use wall-clock.{datetime};
107 /// Information useful for displaying the timezone of a specific `datetime`.
108 ///
109 /// This information may vary within a single `timezone` to reflect daylight
110 /// saving time adjustments.
111 @unstable(feature = clocks-timezone)
112 record timezone-display {
113 /// The number of seconds difference between UTC time and the local
114 /// time of the timezone.
115 ///
116 /// The returned value will always be less than 86400 which is the
117 /// number of seconds in a day (24*60*60).
118 ///
119 /// In implementations that do not expose an actual time zone, this
120 /// should return 0.
121 utc-offset: s32,
122 /// The abbreviated name of the timezone to display to a user. The name
123 /// `UTC` indicates Coordinated Universal Time. Otherwise, this should
124 /// reference local standards for the name of the time zone.
125 ///
126 /// In implementations that do not expose an actual time zone, this
127 /// should be the string `UTC`.
128 ///
129 /// In time zones that do not have an applicable name, a formatted
130 /// representation of the UTC offset may be returned, such as `-04:00`.
131 name: string,
132 /// Whether daylight saving time is active.
133 ///
134 /// In implementations that do not expose an actual time zone, this
135 /// should return false.
136 in-daylight-saving-time: bool,
137 }
139 /// Return information needed to display the given `datetime`. This includes
140 /// the UTC offset, the time zone name, and a flag indicating whether
141 /// daylight saving time is active.
142 ///
143 /// If the timezone cannot be determined for the given `datetime`, return a
144 /// `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight
145 /// saving time.
146 @unstable(feature = clocks-timezone)
147 display: func(when: datetime) -> timezone-display;
149 /// The same as `display`, but only return the UTC offset.
150 @unstable(feature = clocks-timezone)
151 utc-offset: func(when: datetime) -> s32;
152}
154@since(version = 0.2.0)
155world imports {
156 @since(version = 0.2.0)
157 import wasi:io/poll@0.2.12;
158 @since(version = 0.2.0)
159 import monotonic-clock;
160 @since(version = 0.2.0)
161 import wall-clock;
162 @unstable(feature = clocks-timezone)
163 import timezone;
164}

wit/deps/io.wit

Added
new file mode 100644

+301 / −0 text lines

1// Copied verbatim from wasmtime-wasi 49.0.1 `src/p2/wit/deps/io.wit`
2// (Apache-2.0 WITH LLVM-exception).
3package wasi:io@0.2.12;
4
5@since(version = 0.2.0)
6interface error {
7 /// A resource which represents some error information.
8 ///
9 /// The only method provided by this resource is `to-debug-string`,
10 /// which provides some human-readable information about the error.
11 ///
12 /// In the `wasi:io` package, this resource is returned through the
13 /// `wasi:io/streams.stream-error` type.
14 ///
15 /// To provide more specific error information, other interfaces may
16 /// offer functions to "downcast" this error into more specific types. For example,
17 /// errors returned from streams derived from filesystem types can be described using
18 /// the filesystem's own error-code type. This is done using the function
19 /// `wasi:filesystem/types.filesystem-error-code`, which takes a `borrow<error>`
20 /// parameter and returns an `option<wasi:filesystem/types.error-code>`.
21 ///
22 /// The set of functions which can "downcast" an `error` into a more
23 /// concrete type is open.
24 @since(version = 0.2.0)
25 resource error {
26 /// Returns a string that is suitable to assist humans in debugging
27 /// this error.
28 ///
29 /// WARNING: The returned string should not be consumed mechanically!
30 /// It may change across platforms, hosts, or other implementation
31 /// details. Parsing this string is a major platform-compatibility
32 /// hazard.
33 @since(version = 0.2.0)
34 to-debug-string: func() -> string;
35 }
36}
38/// A poll API intended to let users wait for I/O events on multiple handles
39/// at once.
40@since(version = 0.2.0)
41interface poll {
42 /// `pollable` represents a single I/O event which may be ready, or not.
43 @since(version = 0.2.0)
44 resource pollable {
45 /// Return the readiness of a pollable. This function never blocks.
46 ///
47 /// Returns `true` when the pollable is ready, and `false` otherwise.
48 @since(version = 0.2.0)
49 ready: func() -> bool;
50 /// `block` returns immediately if the pollable is ready, and otherwise
51 /// blocks until ready.
52 ///
53 /// This function is equivalent to calling `poll.poll` on a list
54 /// containing only this pollable.
55 @since(version = 0.2.0)
56 block: func();
57 }
59 /// Poll for completion on a set of pollables.
60 ///
61 /// This function takes a list of pollables, which identify I/O sources of
62 /// interest, and waits until one or more of the events is ready for I/O.
63 ///
64 /// The result `list<u32>` contains one or more indices of handles in the
65 /// argument list that is ready for I/O.
66 ///
67 /// This function traps if either:
68 /// - the list is empty, or:
69 /// - the list contains more elements than can be indexed with a `u32` value.
70 ///
71 /// A timeout can be implemented by adding a pollable from the
72 /// wasi-clocks API to the list.
73 ///
74 /// This function does not return a `result`; polling in itself does not
75 /// do any I/O so it doesn't fail. If any of the I/O sources identified by
76 /// the pollables has an error, it is indicated by marking the source as
77 /// being ready for I/O.
78 @since(version = 0.2.0)
79 poll: func(in: list<borrow<pollable>>) -> list<u32>;
80}
82/// WASI I/O is an I/O abstraction API which is currently focused on providing
83/// stream types.
84///
85/// In the future, the component model is expected to add built-in stream types;
86/// when it does, they are expected to subsume this API.
87@since(version = 0.2.0)
88interface streams {
89 @since(version = 0.2.0)
90 use error.{error};
91 @since(version = 0.2.0)
92 use poll.{pollable};
94 /// An error for input-stream and output-stream operations.
95 @since(version = 0.2.0)
96 variant stream-error {
97 /// The last operation (a write or flush) failed before completion.
98 ///
99 /// More information is available in the `error` payload.
100 ///
101 /// After this, the stream will be closed. All future operations return
102 /// `stream-error::closed`.
103 last-operation-failed(error),
104 /// The stream is closed: no more input will be accepted by the
105 /// stream. A closed output-stream will return this error on all
106 /// future operations.
107 closed,
108 }
110 /// An input bytestream.
111 ///
112 /// `input-stream`s are *non-blocking* to the extent practical on underlying
113 /// platforms. I/O operations always return promptly; if fewer bytes are
114 /// promptly available than requested, they return the number of bytes promptly
115 /// available, which could even be zero. To wait for data to be available,
116 /// use the `subscribe` function to obtain a `pollable` which can be polled
117 /// for using `wasi:io/poll`.
118 @since(version = 0.2.0)
119 resource input-stream {
120 /// Perform a non-blocking read from the stream.
121 ///
122 /// When the source of a `read` is binary data, the bytes from the source
123 /// are returned verbatim. When the source of a `read` is known to the
124 /// implementation to be text, bytes containing the UTF-8 encoding of the
125 /// text are returned.
126 ///
127 /// This function returns a list of bytes containing the read data,
128 /// when successful. The returned list will contain up to `len` bytes;
129 /// it may return fewer than requested, but not more. The list is
130 /// empty when no bytes are available for reading at this time. The
131 /// pollable given by `subscribe` will be ready when more bytes are
132 /// available.
133 ///
134 /// This function fails with a `stream-error` when the operation
135 /// encounters an error, giving `last-operation-failed`, or when the
136 /// stream is closed, giving `closed`.
137 ///
138 /// When the caller gives a `len` of 0, it represents a request to
139 /// read 0 bytes. If the stream is still open, this call should
140 /// succeed and return an empty list, or otherwise fail with `closed`.
141 ///
142 /// The `len` parameter is a `u64`, which could represent a list of u8 which
143 /// is not possible to allocate in wasm32, or not desirable to allocate as
144 /// as a return value by the callee. The callee may return a list of bytes
145 /// less than `len` in size while more bytes are available for reading.
146 @since(version = 0.2.0)
147 read: func(len: u64) -> result<list<u8>, stream-error>;
148 /// Read bytes from a stream, after blocking until at least one byte can
149 /// be read. Except for blocking, behavior is identical to `read`.
150 @since(version = 0.2.0)
151 blocking-read: func(len: u64) -> result<list<u8>, stream-error>;
152 /// Skip bytes from a stream. Returns number of bytes skipped.
153 ///
154 /// Behaves identical to `read`, except instead of returning a list
155 /// of bytes, returns the number of bytes consumed from the stream.
156 @since(version = 0.2.0)
157 skip: func(len: u64) -> result<u64, stream-error>;
158 /// Skip bytes from a stream, after blocking until at least one byte
159 /// can be skipped. Except for blocking behavior, identical to `skip`.
160 @since(version = 0.2.0)
161 blocking-skip: func(len: u64) -> result<u64, stream-error>;
162 /// Create a `pollable` which will resolve once either the specified stream
163 /// has bytes available to read or the other end of the stream has been
164 /// closed.
165 /// The created `pollable` is a child resource of the `input-stream`.
166 /// Implementations may trap if the `input-stream` is dropped before
167 /// all derived `pollable`s created with this function are dropped.
168 @since(version = 0.2.0)
169 subscribe: func() -> pollable;
170 }
172 /// An output bytestream.
173 ///
174 /// `output-stream`s are *non-blocking* to the extent practical on
175 /// underlying platforms. Except where specified otherwise, I/O operations also
176 /// always return promptly, after the number of bytes that can be written
177 /// promptly, which could even be zero. To wait for the stream to be ready to
178 /// accept data, the `subscribe` function to obtain a `pollable` which can be
179 /// polled for using `wasi:io/poll`.
180 ///
181 /// Dropping an `output-stream` while there's still an active write in
182 /// progress may result in the data being lost. Before dropping the stream,
183 /// be sure to fully flush your writes.
184 @since(version = 0.2.0)
185 resource output-stream {
186 /// Check readiness for writing. This function never blocks.
187 ///
188 /// Returns the number of bytes permitted for the next call to `write`,
189 /// or an error. Calling `write` with more bytes than this function has
190 /// permitted will trap.
191 ///
192 /// When this function returns 0 bytes, the `subscribe` pollable will
193 /// become ready when this function will report at least 1 byte, or an
194 /// error.
195 @since(version = 0.2.0)
196 check-write: func() -> result<u64, stream-error>;
197 /// Perform a write. This function never blocks.
198 ///
199 /// When the destination of a `write` is binary data, the bytes from
200 /// `contents` are written verbatim. When the destination of a `write` is
201 /// known to the implementation to be text, the bytes of `contents` are
202 /// transcoded from UTF-8 into the encoding of the destination and then
203 /// written.
204 ///
205 /// Precondition: check-write gave permit of Ok(n) and contents has a
206 /// length of less than or equal to n. Otherwise, this function will trap.
207 ///
208 /// returns Err(closed) without writing if the stream has closed since
209 /// the last call to check-write provided a permit.
210 @since(version = 0.2.0)
211 write: func(contents: list<u8>) -> result<_, stream-error>;
212 /// Perform a write of up to 4096 bytes, and then flush the stream. Block
213 /// until all of these operations are complete, or an error occurs.
214 ///
215 /// Returns success when all of the contents written are successfully
216 /// flushed to output. If an error occurs at any point before all
217 /// contents are successfully flushed, that error is returned as soon as
218 /// possible. If writing and flushing the complete contents causes the
219 /// stream to become closed, this call should return success, and
220 /// subsequent calls to check-write or other interfaces should return
221 /// stream-error::closed.
222 @since(version = 0.2.0)
223 blocking-write-and-flush: func(contents: list<u8>) -> result<_, stream-error>;
224 /// Request to flush buffered output. This function never blocks.
225 ///
226 /// This tells the output-stream that the caller intends any buffered
227 /// output to be flushed. the output which is expected to be flushed
228 /// is all that has been passed to `write` prior to this call.
229 ///
230 /// Upon calling this function, the `output-stream` will not accept any
231 /// writes (`check-write` will return `ok(0)`) until the flush has
232 /// completed. The `subscribe` pollable will become ready when the
233 /// flush has completed and the stream can accept more writes.
234 @since(version = 0.2.0)
235 flush: func() -> result<_, stream-error>;
236 /// Request to flush buffered output, and block until flush completes
237 /// and stream is ready for writing again.
238 @since(version = 0.2.0)
239 blocking-flush: func() -> result<_, stream-error>;
240 /// Create a `pollable` which will resolve once the output-stream
241 /// is ready for more writing, or an error has occurred. When this
242 /// pollable is ready, `check-write` will return `ok(n)` with n>0, or an
243 /// error.
244 ///
245 /// If the stream is closed, this pollable is always ready immediately.
246 ///
247 /// The created `pollable` is a child resource of the `output-stream`.
248 /// Implementations may trap if the `output-stream` is dropped before
249 /// all derived `pollable`s created with this function are dropped.
250 @since(version = 0.2.0)
251 subscribe: func() -> pollable;
252 /// Write zeroes to a stream.
253 ///
254 /// This should be used precisely like `write` with the exact same
255 /// preconditions (must use check-write first), but instead of
256 /// passing a list of bytes, you simply pass the number of zero-bytes
257 /// that should be written.
258 @since(version = 0.2.0)
259 write-zeroes: func(len: u64) -> result<_, stream-error>;
260 /// Perform a write of up to 4096 zeroes, and then flush the stream.
261 /// Block until all of these operations are complete, or an error
262 /// occurs.
263 ///
264 /// Functionality is equivelant to `blocking-write-and-flush` with
265 /// contents given as a list of len containing only zeroes.
266 @since(version = 0.2.0)
267 blocking-write-zeroes-and-flush: func(len: u64) -> result<_, stream-error>;
268 /// Read from one stream and write to another.
269 ///
270 /// The behavior of splice is equivalent to:
271 /// 1. calling `check-write` on the `output-stream`
272 /// 2. calling `read` on the `input-stream` with the smaller of the
273 /// `check-write` permitted length and the `len` provided to `splice`
274 /// 3. calling `write` on the `output-stream` with that read data.
275 ///
276 /// Any error reported by the call to `check-write`, `read`, or
277 /// `write` ends the splice and reports that error.
278 ///
279 /// This function returns the number of bytes transferred; it may be less
280 /// than `len`.
281 @since(version = 0.2.0)
282 splice: func(src: borrow<input-stream>, len: u64) -> result<u64, stream-error>;
283 /// Read from one stream and write to another, with blocking.
284 ///
285 /// This is similar to `splice`, except that it blocks until the
286 /// `output-stream` is ready for writing, and the `input-stream`
287 /// is ready for reading, before performing the `splice`.
288 @since(version = 0.2.0)
289 blocking-splice: func(src: borrow<input-stream>, len: u64) -> result<u64, stream-error>;
290 }
291}
293@since(version = 0.2.0)
294world imports {
295 @since(version = 0.2.0)
296 import error;
297 @since(version = 0.2.0)
298 import poll;
299 @since(version = 0.2.0)
300 import streams;
301}