Skip to content

Refactor 6 #277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions component-model/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ git-repository-url = "https://github.com/bytecodealliance/component-docs/tree/ma
edit-url-template = "https://github.com/bytecodealliance/component-docs/tree/main/component-model/{path}"
additional-css = ["theme/head.hbs"]

[output.html.redirect]
"/creating-and-consuming/composing.html" = "/composing-and-distributing/composing.html"
"/creating-and-consuming/distributing.html" = "/composing-and-distributing/distributing.html"
"/creating-and-consuming/running.html" = "/running-components.html"
"/creating-and-consuming/authoring.html" = "/language-support.html"
"/creating-and-consuming.html" = "/language-support.html"
"/runtimes/wasmtime.html" = "/running-components/wasmtime.html"
"/runtimes/jco.html" = "/running-components/jco.html"

[preprocessor.alerts]

[output.linkcheck]
16 changes: 6 additions & 10 deletions component-model/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,14 @@
- [JavaScript](./language-support/javascript.md)
- [Python](./language-support/python.md)
- [Rust](./language-support/rust.md)
- [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)
- [Running Components](./running-components.md)
- [Wasmtime](./running-components/wasmtime.md)
- [jco](./running-components/jco.md)
- [Consuming and Distributing Components](./composing-and-distributing.md)
- [Composing Components](./composing-and-distributing/composing.md)
- [Distributing and Fetching Components and WIT](./composing-and-distributing/distributing.md)
- [Tutorial](./tutorial.md)

# Runtime Support

- [Wasmtime](./runtimes/wasmtime.md)
- [jco](./runtimes/jco.md)

# Advanced Topics

- [Canonical ABI](./advanced/canonical-abi.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Creating and Consuming Components
# Composing and Distributing Components

The component model defines how components interface to each other and to hosts. This section describes how to work with components - from authoring them in custom code or by composing existing components, through to using them in applications and distributing them via registries.
5 changes: 0 additions & 5 deletions component-model/src/creating-and-consuming/authoring.md

This file was deleted.

31 changes: 0 additions & 31 deletions component-model/src/creating-and-consuming/running.md

This file was deleted.

6 changes: 3 additions & 3 deletions component-model/src/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ The WebAssembly Component Model is a broad-reaching architecture for building in
[Python]: ./language-support/python.md
[Rust]: ./language-support/rust.md

[Composing]: ./creating-and-consuming/composing.md
[Running]: ./creating-and-consuming/running.md
[Distributing]: ./creating-and-consuming/distributing.md
[Composing]: ./composing-and-distributing/composing.md
[Running]: ./running-components.md
[Distributing]: ./composing-and-distributing/distributing.md

> [!NOTE]
>This documentation is aimed at _users_ of the component model: developers of libraries and applications.
Expand Down
3 changes: 1 addition & 2 deletions component-model/src/language-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -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](./running-components/wasmtime.md) for more details.
2 changes: 1 addition & 1 deletion component-model/src/language-support/javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ download a pre-existing interface that defines what your component should do.
The [`adder` world][adder-world] contains an interface with a single `add` function that sums two numbers:

```wit
{{#include ../../exmaples/tutorial/wit/adder/world.wit}}
{{#include ../../examples/tutorial/wit/adder/world.wit}}
```

> [!NOTE]
Expand Down
6 changes: 3 additions & 3 deletions component-model/src/language-support/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ world root {
```

As the import is unfulfilled, the `calculator.wasm` component could not run by itself in its current form. To fulfill the `add` import, so that
only `calculate` is exported, you would need to [compose the `calculator.wasm` with some `adder.wasm` into a single, self-contained component](../creating-and-consuming/composing.md).
only `calculate` is exported, you would need to [compose the `calculator.wasm` with some `adder.wasm` into a single, self-contained component](../composing-and-distributing/composing.md).

## Creating a command component with `cargo component`

Expand Down Expand Up @@ -284,7 +284,7 @@ As mentioned above, `cargo component build` doesn't generate a WIT file for a co
}
```

5. [Compose the command component with the `.wasm` components that implement the imports.](../creating-and-consuming/composing.md)
5. [Compose the command component with the `.wasm` components that implement the imports.](../composing-and-distributing/composing.md)

6. Run the composed component:

Expand Down Expand Up @@ -488,7 +488,7 @@ To use the calculator engine in another component, that component must import th
}
```

You can now build the command component and [compose it with the `.wasm` component that implements the resource.](../creating-and-consuming/composing.md). You can then run the composed command with `wasmtime run`.
You can now build the command component and [compose it with the `.wasm` component that implements the resource.](../composing-and-distributing/composing.md). You can then run the composed command with `wasmtime run`.

### Implementing and exporting a resource implementation in a host

Expand Down
3 changes: 3 additions & 0 deletions component-model/src/running-components.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Running Components

There are two standard wit worlds that runtimes support. These worlds are the [`wasi:cli/command` world](https://github.com/WebAssembly/wasi-cli/blob/main/wit/command.wit) and the [`wasi:http/proxy` world](https://github.com/WebAssembly/wasi-http/blob/main/wit/proxy.wit). All other wit worlds and interfaces are considered to be custom. In the following sections, you'll see how to run components that implement either world, as well as how to invoke custom exports.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Wasmtime

[Wasmtime](https://github.com/bytecodealliance/wasmtime/) is the reference implementation of the Component Model. It supports running components that implement the [`wasi:cli/command` world](https://github.com/WebAssembly/wasi-cli/blob/main/wit/command.wit) and serving components that implement the [`wasi:http/proxy` world](https://github.com/WebAssembly/wasi-http/blob/main/wit/proxy.wit).
[Wasmtime](https://github.com/bytecodealliance/wasmtime/) is the reference implementation of the Component Model. It supports running components that implement the [`wasi:cli/command` world](https://github.com/WebAssembly/wasi-cli/blob/main/wit/command.wit) and serving components that implement the [`wasi:http/proxy` world](https://github.com/WebAssembly/wasi-http/blob/main/wit/proxy.wit). Wasmtime can also invoke functions exported from a component.

## Running command components with Wasmtime
To run a command component with Wasmtime, execute:
Expand All @@ -27,3 +27,14 @@ 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 components with custom 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.

```sh
wasmtime run --invoke 'foo(1, 2)' <path-to-wasm-file>
```
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).
8 changes: 3 additions & 5 deletions component-model/src/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,15 @@ These files define:

## Create an `add` component

Reference the [language guide](language-support.md) and [authoring components
documentation](creating-and-consuming/authoring.md) to create a component that implements the
Reference the [language guide](language-support.md) to create a component that implements the
`adder` world of `adder/wit/world.wit`.

For reference, see the completed
[example](https://github.com/bytecodealliance/component-docs/tree/main/component-model/examples/tutorial/adder/).

## Create a `calculator` component

Reference the [language guide](language-support.md) and [authoring components
documentation](creating-and-consuming/authoring.md) to create a component that implements the
Reference the [language guide](language-support.md) to create a component that implements the
`calculator` world of `wit/calculator/world.wit`.

For reference, see the completed
Expand Down Expand Up @@ -160,7 +158,7 @@ wac plug calculator.wasm --plug adder.wasm -o composed.wasm
wac plug command.wasm --plug composed.wasm -o final.wasm
```

> If you'd prefer to take a more visual approach to composing components, see the [documentation on composing components with wasmbuilder.app](creating-and-consuming/composing.md#composing-components-with-a-visual-interface).
> If you'd prefer to take a more visual approach to composing components, see the [documentation on composing components with wasmbuilder.app](composing-and-distributing/composing.md#composing-components-with-a-visual-interface).

## Running the calculator

Expand Down