You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -96,9 +95,9 @@ that is, code which fulfills the definition of the interface function declared i
96
95
97
96
## 4. Compile a WebAssembly Preview 2 component with `wasi-sdk`'s `wasm32-wasip2-clang`
98
97
99
-
"P1" refers to [WASI Preview 1](https://github.com/WebAssembly/WASI/blob/main/legacy/README.md),
98
+
"P1" refers to [WASI Preview 1](https://github.com/WebAssembly/WASI/tree/wasi-0.1),
100
99
the initial version of the WASI APIs.
101
-
"P2" refers to [WASI Preview 2](https://github.com/WebAssembly/WASI/blob/main/wasip2/README.md),
100
+
"P2" refers to [WASI Preview 2](https://github.com/WebAssembly/WASI/blob/main/docs/Preview2.md),
102
101
which introduced the component model.
103
102
104
103
While in the past building a P2 component required conversion from a P1 component,
@@ -303,40 +302,109 @@ world root {
303
302
...
304
303
```
305
304
306
-
###6. Run the component from the example host
305
+
## 6. Run the component with `wasmtime --invoke`
307
306
308
-
The following section requires you to have [a Rust toolchain][rust] installed.
307
+
If you want to quickly run the `add` export without writing a host application that embeds Wasmtime,
308
+
you can invoke it directly with the Wasmtime CLI.
309
309
310
-
> [!WARNING]
311
-
> You must be careful to use a version of the adapter (`wasi_snapshot_preview1.wasm`)
312
-
> that is compatible with the version of `wasmtime` that will be used,
313
-
> to ensure that WASI interface versions (and relevant implementation) match.
314
-
> (The `wasmtime` version is specified in [the Cargo configuration file][cargo-config]
315
-
> for the example host.)
310
+
```console
311
+
wasmtime run --invoke 'add(2, 2)' adder.wasm
312
+
```
313
+
314
+
Depending on your Wasmtime version, the shorthand form may also work:
315
+
316
+
```console
317
+
wasmtime --invoke 'add(2,2)' adder.wasm
318
+
```
319
+
320
+
## 7. Run the component from the example C host
321
+
322
+
This repository includes a C application that can execute components that implement the add interface. This application embeds Wasmtime using the Wasmtime C API:
323
+
`component-model/examples/example-c-host/host.c`.
324
+
325
+
The application expects three arguments: the two numbers to add and the Wasm component that executed the addition. For example:
326
+
327
+
```sh
328
+
./adder-host <x><y><path-to-component.wasm>
329
+
```
330
+
331
+
You can either use a Dockerfile to execute your add component with the C application or directly run the application.
332
+
333
+
### Option A: Compile and run the host directly
334
+
335
+
If the Wasmtime C API headers and library are installed on your system,
336
+
you can compile and run the host directly:
337
+
338
+
On Linux, the following commands install the C API artifacts in `/usr/local`
0 commit comments