1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
//! Auto-generated bindings for WASI interfaces.
//!
//! This module contains the output of the [`bindgen!`] macro when run over
//! the `wasi:cli/imports` world.
//!
//! [`bindgen!`]: https://docs.rs/wasmtime/latest/wasmtime/component/macro.bindgen.html
//!
//! # Examples
//!
//! If you have a WIT world which refers to WASI interfaces you probably want to
//! use this modules's bindings rather than generate fresh bindings. That can be
//! done using the `with` option to [`bindgen!`]:
//!
//! ```rust
//! use wasmtime_wasi::{WasiCtx, WasiCtxView, WasiView};
//! use wasmtime::{Result, Engine, Config};
//! use wasmtime::component::{Linker, HasSelf, ResourceTable};
//!
//! wasmtime::component::bindgen!({
//! inline: "
//! package example:wasi;
//!
//! // An example of extending the `wasi:cli/command` world with a
//! // custom host interface.
//! world my-world {
//! include wasi:cli/command@0.3.0-rc-2026-01-06;
//!
//! import custom-host;
//! }
//!
//! interface custom-host {
//! my-custom-function: func();
//! }
//! ",
//! path: "src/p3/wit",
//! with: {
//! "wasi": wasmtime_wasi::p3::bindings,
//! },
//! require_store_data_send: true,
//! });
//!
//! struct MyState {
//! ctx: WasiCtx,
//! table: ResourceTable,
//! }
//!
//! impl example::wasi::custom_host::Host for MyState {
//! fn my_custom_function(&mut self) {
//! // ..
//! }
//! }
//!
//! impl WasiView for MyState {
//! fn ctx(&mut self) -> WasiCtxView<'_> {
//! WasiCtxView{
//! ctx: &mut self.ctx,
//! table: &mut self.table,
//! }
//! }
//! }
//!
//! fn main() -> Result<()> {
//! let mut config = Config::default();
//! config.wasm_component_model_async(true);
//! let engine = Engine::new(&config)?;
//! let mut linker: Linker<MyState> = Linker::new(&engine);
//! wasmtime_wasi::p3::add_to_linker(&mut linker)?;
//! example::wasi::custom_host::add_to_linker::<_, HasSelf<_>>(&mut linker, |state| state)?;
//!
//! // .. use `Linker` to instantiate component ...
//!
//! Ok(())
//! }
//! ```
pub use LinkOptions;
pub use exports;
pub use *;
/// Bindings to execute and run a `wasi:cli/command`.
///
/// This structure is automatically generated by `bindgen!`.
///
/// This can be used for a more "typed" view of executing a command component
/// through the [`Command::wasi_cli_run`] method plus
/// [`Guest::call_run`](exports::wasi::cli::run::Guest::call_run).
///
/// # Examples
///
/// ```no_run
/// use wasmtime::{Engine, Result, Store, Config};
/// use wasmtime::component::{Component, Linker, ResourceTable};
/// use wasmtime_wasi::{WasiCtx, WasiCtxView, WasiView};
/// use wasmtime_wasi::p3::bindings::Command;
///
/// // This example is an example shim of executing a component based on the
/// // command line arguments provided to this program.
/// #[tokio::main]
/// async fn main() -> Result<()> {
/// let args = std::env::args().skip(1).collect::<Vec<_>>();
///
/// // Configure and create `Engine`
/// let mut config = Config::new();
/// config.wasm_component_model_async(true);
/// let engine = Engine::new(&config)?;
///
/// // Configure a `Linker` with WASI, compile a component based on
/// // command line arguments, and then pre-instantiate it.
/// let mut linker = Linker::<MyState>::new(&engine);
/// wasmtime_wasi::p3::add_to_linker(&mut linker)?;
/// let component = Component::from_file(&engine, &args[0])?;
///
///
/// // Configure a `WasiCtx` based on this program's environment. Then
/// // build a `Store` to instantiate into.
/// let mut builder = WasiCtx::builder();
/// builder.inherit_stdio().inherit_env().args(&args);
/// let mut store = Store::new(
/// &engine,
/// MyState {
/// ctx: builder.build(),
/// table: ResourceTable::default(),
/// },
/// );
///
/// // Instantiate the component and we're off to the races.
/// let command = Command::instantiate_async(&mut store, &component, &linker).await?;
/// let program_result = store.run_concurrent(async move |store| {
/// command.wasi_cli_run().call_run(store).await
/// }).await??.0;
/// match program_result {
/// Ok(()) => Ok(()),
/// Err(()) => std::process::exit(1),
/// }
/// }
///
/// struct MyState {
/// ctx: WasiCtx,
/// table: ResourceTable,
/// }
///
/// impl WasiView for MyState {
/// fn ctx(&mut self) -> WasiCtxView<'_> {
/// WasiCtxView{
/// ctx: &mut self.ctx,
/// table: &mut self.table,
/// }
/// }
/// }
/// ```
///
/// ---
pub use Command;
/// Pre-instantiated analog of [`Command`]
///
/// This can be used to front-load work such as export lookup before
/// instantiation.
///
/// # Examples
///
/// ```no_run
/// use wasmtime::{Engine, Result, Store, Config};
/// use wasmtime::component::{Linker, Component, ResourceTable};
/// use wasmtime_wasi::{WasiCtx, WasiCtxView, WasiView};
/// use wasmtime_wasi::p3::bindings::CommandPre;
///
/// // This example is an example shim of executing a component based on the
/// // command line arguments provided to this program.
/// #[tokio::main]
/// async fn main() -> Result<()> {
/// let args = std::env::args().skip(1).collect::<Vec<_>>();
///
/// // Configure and create `Engine`
/// let mut config = Config::new();
/// config.wasm_component_model_async(true);
/// let engine = Engine::new(&config)?;
///
/// // Configure a `Linker` with WASI, compile a component based on
/// // command line arguments, and then pre-instantiate it.
/// let mut linker = Linker::<MyState>::new(&engine);
/// wasmtime_wasi::p3::add_to_linker(&mut linker)?;
/// let component = Component::from_file(&engine, &args[0])?;
/// let pre = CommandPre::new(linker.instantiate_pre(&component)?)?;
///
///
/// // Configure a `WasiCtx` based on this program's environment. Then
/// // build a `Store` to instantiate into.
/// let mut builder = WasiCtx::builder();
/// builder.inherit_stdio().inherit_env().args(&args);
/// let mut store = Store::new(
/// &engine,
/// MyState {
/// ctx: builder.build(),
/// table: ResourceTable::default(),
/// },
/// );
///
/// // Instantiate the component and we're off to the races.
/// let command = pre.instantiate_async(&mut store).await?;
/// // TODO: Construct an accessor from `store` to call `run`
/// // https://github.com/bytecodealliance/wasmtime/issues/11249
/// //let program_result = command.wasi_cli_run().call_run(&mut store).await?;
/// let program_result = todo!();
/// match program_result {
/// Ok(()) => Ok(()),
/// Err(()) => std::process::exit(1),
/// }
/// }
///
/// struct MyState {
/// ctx: WasiCtx,
/// table: ResourceTable,
/// }
///
/// impl WasiView for MyState {
/// fn ctx(&mut self) -> WasiCtxView<'_> {
/// WasiCtxView{
/// ctx: &mut self.ctx,
/// table: &mut self.table,
/// }
/// }
/// }
/// ```
///
/// ---
// TODO: Make this public, once `CommandPre` can be used for
// calling exports
// https://github.com/bytecodealliance/wasmtime/issues/11249
pub use CommandPre;
pub use CommandIndices;