|
1 | 1 | ## Component Model Concepts |
2 | 2 |
|
3 | | -This section introduces the core concepts and [rationale](./why-component-model.md) of the component model. |
4 | | - |
5 | | -* A [WebAssembly Component](./components.md) is the next evolution of core WebAssembly binaries. |
6 | | - * WebAssembly components are *nestable* -- they may contain one or more core modules and/or sub-components composed together. |
7 | | -* The Component Model extends core WebAssembly by introducing higher level types and interface-driven development |
8 | | - * [WebAssembly Interface Types (WIT)][wit] is the [IDL (Interface Definition Language)][wiki-idl] used to formally define functionality for WebAssembly modules. |
9 | | - * With WIT, WebAssembly components gain the ability to conform an language-agnostic and encode that support, so any WebAssembly component binary can be interrogated *and* executed. |
10 | | - * An [Interface](./interfaces.md) describes the types and functions used for a specific, focused bit of functionality. |
11 | | - * A [World](./worlds.md) assembles interfaces to express what features a component offers, and what features it depends on. |
12 | | - * A [Package](./packages.md) is a set of WIT files containing a related set of interfaces and worlds. |
13 | | -* The Component Model introduces the idea of a "platform" to core WebAssembly -- enabling the structured, standardized use of "host" functionality for WebAssembly "guest"s. |
14 | | - * The WebAssembly System Interface (WASI) defines in WIT a family of interfaces for common system-level functions. |
15 | | - * WASI defines common execution environments such as the command line (`wasi:cli`) or a HTTP server (`wasi:http`). |
16 | | -* The Component Model makes core WebAssembly composable -- components that provide functionality and those that use them can be composed together into *one* resulting component |
| 3 | +The WebAssembly Component Model extends core WebAssembly in several ways. |
| 4 | +The Component Model: |
| 5 | +* Adds consistent representation of higher-level types |
| 6 | +* Enables interface-driven development |
| 7 | +* Makes core WebAssembly composable: |
| 8 | +components that provide functionality and those that use them |
| 9 | +can be composed together into *one* resulting component. |
| 10 | + |
| 11 | +This section introduces the core concepts behind the component model. |
| 12 | +For the rationale behind the component model, see [the previous section](./why-component-model.md). |
| 13 | + |
| 14 | +### Components |
| 15 | + |
| 16 | +A [WebAssembly Component](./components.md) is a binary that |
| 17 | +conforms to the [Canonical ABI](../advanced/canonical-abi.md); |
| 18 | +often a WebAssembly core module extended with the features |
| 19 | +of the Component Model |
| 20 | +(higher-level types, interfaces). |
| 21 | +WebAssembly components are *nestable*: |
| 22 | +they may contain zero or more core modules and/or sub-components composed together. |
| 23 | +For example, a component implementing a simple calculator might be written |
| 24 | +by composing together a component that parses strings to floating-point numbers |
| 25 | +with a component that does the main arithmetic. |
| 26 | + |
| 27 | +### WebAssembly Interface Types (WIT) |
| 28 | + |
| 29 | +[WebAssembly Interface Types (WIT)][wit] is the [Interface Definition Language (IDL)][wiki-idl] |
| 30 | +used to formally define functionality for WebAssembly components. |
| 31 | +WIT gives WebAssembly components the ability to express type signatures |
| 32 | +in a language-agnostic way, |
| 33 | +so any component binary can be checked, composed and executed. |
| 34 | + |
| 35 | +#### Interfaces |
| 36 | + |
| 37 | +An [_interface_](./interfaces.md) is a collection of type definitions |
| 38 | +and function declarations (function names accompanied by type signatures). |
| 39 | +Typically, a single interface describes a specific, focused bit |
| 40 | +of functionality. |
| 41 | + |
| 42 | +For example, in [wasi-cli][wasi-cli-stdio], |
| 43 | +three separate interfaces are used to implement `stdin`, `stdout`, and `stderr` |
| 44 | +(streams typically available in command-line-like environments) |
| 45 | + |
| 46 | +### Worlds |
| 47 | + |
| 48 | +A [_world_](./worlds.md) is a collection of interfaces and types |
| 49 | +that expresses what features a component offers |
| 50 | +and what features it depends on. |
| 51 | + |
| 52 | +For example, wasi-cli includes the [`command` world][wasi-cli-command], |
| 53 | +which depends on interfaces |
| 54 | +that represent the `stdin`, `stdout`, and `stderr` streams, |
| 55 | +among other things. |
| 56 | +A component implementing the `command` world |
| 57 | +must be invoked in an environment that implements those interfaces. |
| 58 | + |
| 59 | +### Packages |
| 60 | + |
| 61 | + A [_package_](./packages.md) is a set of WIT files |
| 62 | +containing a related set of interfaces and worlds. |
| 63 | + |
| 64 | +For example, the [wasi-http](https://github.com/WebAssembly/wasi-http/blob/main/wit/proxy.wit) package includes |
| 65 | +an `imports` world encapsulating the interfaces that an HTTP proxy depends on, |
| 66 | +and a `proxy` world that depends on `imports`. |
| 67 | + |
| 68 | +### Platforms |
| 69 | + |
| 70 | +In the context of WebAssembly, a _host_ refers to a WebAssembly runtime |
| 71 | +capable of executing WebAssembly binaries. |
| 72 | +The runtime can be inside a browser or can stand alone. |
| 73 | +A _guest_ refers to the WebAssembly binary that is executed by the host. |
| 74 | +(These terms borrow from their analogs in [virtualization](https://en.wikipedia.org/wiki/Virtualization), where a guest is |
| 75 | +a software-based virtual machine that runs on physical hardware, |
| 76 | +which is the "host") |
| 77 | + |
| 78 | +The Component Model introduces the idea of a _platform_ |
| 79 | +to core WebAssembly—enabling the structured, standardized use |
| 80 | +of host functionality for WebAssembly guests. |
| 81 | +Components may import functionality that is provided |
| 82 | +by the platform on which they are executed. |
| 83 | + |
| 84 | +### WASI |
| 85 | + |
| 86 | +The WebAssembly System Interface ([WASI][wasi]) defines in WIT |
| 87 | +a family of interfaces for common system-level functions. |
| 88 | +WASI defines a platform for component writers that mimics |
| 89 | +existing programs that developers are familiar with |
| 90 | +(for example, `wasi-cli` or `wasi-http`), |
| 91 | +standardizing the functionality components depend on. |
17 | 92 |
|
18 | 93 | > [!NOTE] |
19 | | -> The Component Model is stewarded by the Bytecode Alliance and designed [in the open][cm-repo]. |
| 94 | +> The Component Model is stewarded by the [Bytecode Alliance](https://bytecodealliance.org/) and designed [in the open][cm-repo]. |
20 | 95 | > |
21 | | -> See the [`WebAssembly/component-model`][cm-repo] repository for [Goals][goals],[use cases][use-cases], and [high level design choices][design-choices]. |
| 96 | +> See the [`WebAssembly/component-model`][cm-repo] repository for [goals][goals], [use cases][use-cases], and [high level design choices][design-choices]. |
22 | 97 |
|
23 | 98 | [cm-repo]: https://github.com/WebAssembly/component-model |
24 | | -[wiki-idl]: https://en.wikipedia.org/wiki/Web_IDL |
| 99 | +[wiki-idl]: https://en.wikipedia.org/wiki/Interface_description_language |
25 | 100 | [goals]: https://github.com/WebAssembly/component-model/blob/main/design/high-level/Goals.md |
26 | 101 | [use-cases]: https://github.com/WebAssembly/component-model/blob/main/design/high-level/UseCases.md |
27 | 102 | [design-choices]: https://github.com/WebAssembly/component-model/blob/main/design/high-level/Choices.md |
28 | 103 | [wit]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md |
| 104 | +[wasi]: https://wasi.dev/ |
| 105 | +[wasi-cli]: https://github.com/WebAssembly/wasi-cli/ |
| 106 | +[wasi-cli-stdio]: https://github.com/WebAssembly/wasi-cli/blob/main/wit/stdio.wit |
| 107 | +[wasi-cli-command]: https://github.com/WebAssembly/wasi-cli/blob/main/wit/command.wit |
| 108 | +[wasi-http]: https://github.com/WebAssembly/wasi-http |
29 | 109 |
|
30 | 110 | [!NOTE]: # |
0 commit comments