From 6afe0208b3ea630bb13178373e1592541945e972 Mon Sep 17 00:00:00 2001 From: macovedj Date: Tue, 17 Jun 2025 15:59:56 -0500 Subject: [PATCH] running.md moved to wasmtime.md section and updated for custom invocations --- component-model/src/SUMMARY.md | 1 - .../src/creating-and-consuming/running.md | 31 ------------------- component-model/src/introduction.md | 4 +-- component-model/src/language-support.md | 3 +- component-model/src/runtimes/wasmtime.md | 10 ++++++ 5 files changed, 13 insertions(+), 36 deletions(-) delete mode 100644 component-model/src/creating-and-consuming/running.md diff --git a/component-model/src/SUMMARY.md b/component-model/src/SUMMARY.md index cb1af074..0ce291e8 100644 --- a/component-model/src/SUMMARY.md +++ b/component-model/src/SUMMARY.md @@ -25,7 +25,6 @@ - [Creating and Consuming Components](./creating-and-consuming.md) - [Authoring Components](./creating-and-consuming/authoring.md) - [Composing Components](./creating-and-consuming/composing.md) - - [Running Components](./creating-and-consuming/running.md) - [Distributing and Fetching Components and WIT](./creating-and-consuming/distributing.md) - [Tutorial](./tutorial.md) diff --git a/component-model/src/creating-and-consuming/running.md b/component-model/src/creating-and-consuming/running.md deleted file mode 100644 index a76398b6..00000000 --- a/component-model/src/creating-and-consuming/running.md +++ /dev/null @@ -1,31 +0,0 @@ -# Running Components - -You can "run" a component by calling one of its exports. In some cases, this requires a custom host. For "command" components, though, you can use the `wasmtime` command line. This can be a convenient tool for testing components and exploring the component model. Other runtimes are also available - see the "Runtimes" section of the sidebar for more info. - -> A "command" component is one that exports the `wasi:cli/run` interface, and imports only interfaces listed in the [`wasi:cli/command` world](https://github.com/WebAssembly/wasi-cli/blob/main/wit/command.wit). - -You must use a recent version of `wasmtime` ([`v14.0.0` or greater](https://github.com/bytecodealliance/wasmtime/releases)), as earlier releases of the `wasmtime` command line do not include component model support. - -To run your component, run: - -```sh -wasmtime run -``` - -## Running components with custom exports - -If you're writing a library-style component - that is, one that exports a custom API - then you can run it in `wasmtime` by writing a "command" component that imports and invokes your custom API. By [composing](./composing.md) the command and the library, you can exercise the library in `wasmtime`. - -1. Write your library component. The component's world (`.wit` file) must export an interface and/or one or more functions through which a consumer can call it. See the [language support guide](../language-support.md) for how to implement an export. - -2. Build your library component to a `.wasm` file. - -3. Write your command component. The component's world (`.wit` file) must import the interface or functions exported from the library. Write the command to call the library's API. See the [language support guide](../language-support.md) for how to call an imported interface. - -4. Build your command component to a `.wasm` file. You will not be able to run this in `wasmtime` yet, as its imports are not yet satisfied. - -5. Compose your command component with your library component by running `wac plug --plug -o main.wasm`. - -6. Run the composed component using `wasmtime run main.wasm` - -See [Composing Components](./composing.md) for more details. diff --git a/component-model/src/introduction.md b/component-model/src/introduction.md index 8d0546e6..7ab84feb 100644 --- a/component-model/src/introduction.md +++ b/component-model/src/introduction.md @@ -5,8 +5,8 @@ The WebAssembly Component Model is a broad-reaching architecture for building in | Understanding components | Building components | Using components | |--------------------------|----------------------|-------------------| | [Why Components?] | [C/C++] | [Composing] | -| [Components] | [C#] | [Running] | -| [Interfaces] | [Go] | [Distributing] | +| [Components] | [C#] | [Distributing] | +| [Interfaces] | [Go] | | | [Worlds] | [JavaScript] | | | | [Python] | | | | [Rust] | | diff --git a/component-model/src/language-support.md b/component-model/src/language-support.md index 1eb02c53..da61df4f 100644 --- a/component-model/src/language-support.md +++ b/component-model/src/language-support.md @@ -89,5 +89,4 @@ working with WebAssembly modules and components. You can "run" a component by calling one of its exports. Hosts and runtimes often only support running components with certain exports. The [`wasmtime`](https://github.com/bytecodealliance/wasmtime) CLI can only run "command" components, so in order to run the `add` function above, it first must be composed with a primary "command" component -that calls it. See [documentation on running components](./creating-and-consuming/running.md) for -more details. +that calls it. See [documentation on running components](./runtimes/wasmtime.md) for more details. diff --git a/component-model/src/runtimes/wasmtime.md b/component-model/src/runtimes/wasmtime.md index d0a3b471..88cc9a2c 100644 --- a/component-model/src/runtimes/wasmtime.md +++ b/component-model/src/runtimes/wasmtime.md @@ -27,3 +27,13 @@ Try out building and running HTTP components with one of these tutorials 1. [Hello WASI HTTP tutorial](https://github.com/sunfishcode/hello-wasi-http) - build and serve a simple Rust-based HTTP component 2. [HTTP Auth Middleware tutorial](https://github.com/fermyon/http-auth-middleware#running-with-wasmtime) - compose a HTTP authentication middleware component with a business logic component + +## Running components with custom exports +As of Wasmtime Version 33.0.0, there is [support for invoking custom component exports](https://bytecodealliance.org/articles/invoking-component-functions-in-wasmtime-cli). + + +As an example, if your component exports a function `add` which takes two numeric arguments, you can make use of this feature with the following command. + +`wasmtime run --invoke 'foo(1, 2)' ` + +Make sure to wrap your invocation in single quotes abd to include parentheses, even if your function doesn't take any arguments. For a full list of ways to represent the various wit types when passing arguments to your exported function, visit the [WAVE repo](https://github.com/bytecodealliance/wasm-tools/tree/main/crates/wasm-wave). \ No newline at end of file