|
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 |
| 4 | +by introducing higher-level types |
| 5 | +and interface-driven development. |
| 6 | +The Component Model makes core WebAssembly composable: |
| 7 | +components that provide functionality and those that use them |
| 8 | +can be composed together into *one* resulting component. |
| 9 | + |
| 10 | +This section introduces the core concepts behind the component model. |
| 11 | +For the rationale behind the component model, see [the previous section](./why-component-model.md). |
| 12 | + |
| 13 | +### Components |
| 14 | + |
| 15 | +A [WebAssembly Component](./components.md) is a core module extended with higher-level types and interfaces. |
| 16 | +WebAssembly components are *nestable*: |
| 17 | +they may contain one or more core modules and/or sub-components composed together. |
| 18 | +For example, a component implementing a simple calculator might be written |
| 19 | +by composing together a component that parses strings to floating-point numbers |
| 20 | +with a component that does the main arithmetic. |
| 21 | + |
| 22 | +### WebAssembly Interface Types (WIT) |
| 23 | + |
| 24 | +[WebAssembly Interface Types (WIT)][wit] is the [IDL (Interface Definition Language)][wiki-idl] |
| 25 | +used to formally define functionality for WebAssembly modules. |
| 26 | +WIT gives WebAssembly components the ability to express type signatures |
| 27 | +in a language-agnostic way, |
| 28 | +so any component binary can be both checked and executed. |
| 29 | + |
| 30 | +### Interfaces |
| 31 | + |
| 32 | +An [_interface_](./interfaces.md) is a collection of type definitions |
| 33 | +and function declarations (function names accompanied by type signatures). |
| 34 | +Typically, a single interface describes a specific, focused bit |
| 35 | +of functionality. |
| 36 | +For example, in [wasi-cli][wasi-cli-stdio], |
| 37 | +three separate interfaces are used to implement `stdin`, `stdout`, and `stderr` |
| 38 | +(the three input and output streams typically available |
| 39 | +in a command-line environment.) |
| 40 | + |
| 41 | +### Worlds |
| 42 | + |
| 43 | +A [_world_](./worlds.md) is a collection of interfaces |
| 44 | +that expresses what features a component offers |
| 45 | +and what features it depends on. |
| 46 | +For example, wasi-cli includes the [`stdio` world][wasi-cli-stdio], |
| 47 | +which collects together three separate interfaces |
| 48 | +that represent the `stdin`, `stdout`, and `stderr` streams. |
| 49 | +Any component implementing the `stdio` world |
| 50 | +must implement those three interfaces. |
| 51 | + |
| 52 | +### Packages |
| 53 | + |
| 54 | + A [_package_](./packages.md) is a set of WIT files |
| 55 | + containing a related set of interfaces and worlds. |
| 56 | + For example, the wasi-cli package includes |
| 57 | + the `stdio` world and the `environment` world, among others, |
| 58 | + with each defined in its own WIT file. |
| 59 | + |
| 60 | +### Platforms |
| 61 | + |
| 62 | +In the context of WebAssembly, the _host_ is the browser or stand-alone runtime |
| 63 | +that runs WebAssembly modules. |
| 64 | +The _guest_ is the WebAssembly module that is executed by the host. |
| 65 | +(These terms come from virtualization, where a guest is |
| 66 | +a software-based virtual machine that runs on physical hardware, |
| 67 | +which is the "host") |
| 68 | + |
| 69 | +The Component Model introduces the idea of a _platform_ |
| 70 | +to core WebAssembly—enabling the structured, standardized use |
| 71 | +of host functionality for WebAssembly guests. |
| 72 | + |
| 73 | +## WASI |
| 74 | + |
| 75 | +The WebAssembly System Interface ([WASI][wasi]) defines in WIT |
| 76 | +a family of interfaces for common system-level functions. |
| 77 | +WASI standardizes the functionality provided by platforms, |
| 78 | +so that component writers can rely on functionality |
| 79 | +that is guaranteed to be available on any conformant platform. |
| 80 | + |
| 81 | +WASI defines common collections of functionality |
| 82 | +such as the command line ([`wasi:cli`][wasi-cli]) |
| 83 | +or an HTTP server ([`wasi:http`][wasi-http]). |
17 | 84 |
|
18 | 85 | > [!NOTE] |
19 | | -> The Component Model is stewarded by the Bytecode Alliance and designed [in the open][cm-repo]. |
| 86 | +> The Component Model is stewarded by the [Bytecode Alliance](https://bytecodealliance.org/) and designed [in the open][cm-repo]. |
20 | 87 | > |
21 | | -> See the [`WebAssembly/component-model`][cm-repo] repository for [Goals][goals],[use cases][use-cases], and [high level design choices][design-choices]. |
| 88 | +> See the [`WebAssembly/component-model`][cm-repo] repository for [goals][goals], [use cases][use-cases], and [high level design choices][design-choices]. |
22 | 89 |
|
23 | 90 | [cm-repo]: https://github.com/WebAssembly/component-model |
24 | | -[wiki-idl]: https://en.wikipedia.org/wiki/Web_IDL |
| 91 | +[wiki-idl]: https://en.wikipedia.org/wiki/Interface_description_language |
25 | 92 | [goals]: https://github.com/WebAssembly/component-model/blob/main/design/high-level/Goals.md |
26 | 93 | [use-cases]: https://github.com/WebAssembly/component-model/blob/main/design/high-level/UseCases.md |
27 | 94 | [design-choices]: https://github.com/WebAssembly/component-model/blob/main/design/high-level/Choices.md |
28 | 95 | [wit]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md |
| 96 | +[wasi]: https://wasi.dev/ |
| 97 | +[wasi-cli]: https://github.com/WebAssembly/wasi-cli/ |
| 98 | +[wasi-cli-stdio]: https://github.com/WebAssembly/wasi-cli/blob/main/wit/stdio.wit |
| 99 | +[wasi-http]: https://github.com/WebAssembly/wasi-http |
29 | 100 |
|
30 | 101 | [!NOTE]: # |
0 commit comments