-
Notifications
You must be signed in to change notification settings - Fork 79
feat: add FAQ section #271
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
vados-cosmonic
merged 28 commits into
bytecodealliance:main
from
vados-cosmonic:feat=add-faq-section
Jul 4, 2025
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
374cba8
feat: add FAQ section
vados-cosmonic 9586074
fix: improve emphasis in question title
vados-cosmonic 93c6c7c
fix: comment out ellipsis in wat
vados-cosmonic d10761d
fix: comment out component WAT ellipsis
vados-cosmonic 6d9d06f
fix: wording on s-expressions
vados-cosmonic 83b4fd7
fix: it's -> its
vados-cosmonic d676fed
fix: remove errant brace
vados-cosmonic 2ac73d7
fix: webassembly -> wasi
vados-cosmonic 9547372
fix: note p1's legacy specification
vados-cosmonic 3050a0d
fix: 'core components'
vados-cosmonic 358d618
fix: contrast sentence
vados-cosmonic d083463
fix: primitive types
vados-cosmonic 7232d66
fix: clarify interaction with outside world
vados-cosmonic e96058d
fix: typo
vados-cosmonic 4be8023
fix: contrast sentence
vados-cosmonic 8f9eacd
fix: wasi description
vados-cosmonic d0149cb
fix: platform builder sentence
vados-cosmonic 8e8951c
fix: self describing explanation
vados-cosmonic 61e65a4
refactor: wording around imports
vados-cosmonic 6f5667b
fix: component description
vados-cosmonic 690f838
refactor: remove unneeded sentence
vados-cosmonic a42455c
fix: include imports
vados-cosmonic 1d6ecc5
fix: add split up question
vados-cosmonic 2db1009
refactor: WIT + WASI explanation
vados-cosmonic fb8acad
fix: cm section
vados-cosmonic d3a1e04
fix: prose, organization
vados-cosmonic 5e2f93e
fix: components mention
vados-cosmonic 001bd1d
fix: it's -> its
vados-cosmonic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| # Frequently Asked Questions (FAQ) | ||
|
|
||
| This page hosts a series of questions that are frequently asked along with descriptions | ||
| of concepts that may be confusing with regards to core WebAssembly, WebAssembly components | ||
| (i.e. the Component Model), and the WebAssembly ecosystem as a whole. | ||
|
|
||
| ## Q: What is the difference between a _module_ and _component_ in WebAssembly? | ||
|
|
||
| A WebAssembly module (more precisely referred to as a "WebAssembly core module") is a | ||
| binary that conforms to the [WebAssembly Core Specification][wasm-core-spec]. | ||
|
|
||
| A WebAssembly component: | ||
| - Adheres to the component model [binary format][cm-binary-format] (as opposed to a WebAssembly core binary format) | ||
| - Uses the [WebAssembly Interface types][wit] specification to encode type information. | ||
| - Adheres to the Component Model [Canonical ABI][cabi] for converting between rich types and those present in core WebAssembly. | ||
|
|
||
| WebAssembly Components can (and often do) contain core modules, but generally WebAssembly core modules | ||
| *cannot* contain Components. WebAssembly components and WebAssembly core modules have a different binary format. | ||
|
|
||
| WebAssembly components can be expressed via both a binary and textual format (["WAT", the WebAssembly Text format][wat]). | ||
|
|
||
| [wat]: https://webassembly.github.io/spec/core/text/index.html | ||
| [cabi]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md | ||
| [cm-binary-format]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/Binary.md | ||
| [wasi-p1]: https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/witx/wasi_snapshot_preview1.witx | ||
| [wasm-core-spec]: https://webassembly.github.io/spec/core/ | ||
|
|
||
| ## Q: How can I tell if a WebAssembly binary is a component or a module? | ||
|
|
||
| After converting a WebAssembly binary to its textual format (e.g. via a tool like [`wasm-tools print`][wasm-tools-examples]), | ||
| it is easy to tell a WebAssembly core module and a WebAssembly component apart. | ||
|
|
||
| A WebAssembly core module generally consists of a top level `(module)` s-expression: | ||
| ```wat | ||
| (module | ||
| ;; ... | ||
| ) | ||
| ``` | ||
|
|
||
| A WebAssembly component generally consists of a `(component)` s-expression (and may contain | ||
| nested `(core:module)`/`(component)` s-expressions): | ||
|
|
||
| ```wat | ||
| (component | ||
| ;; ... | ||
| ) | ||
| ``` | ||
|
|
||
| [WASM-tools-examples]: https://github.com/bytecodealliance/wasm-tools?tab=readme-ov-file#examples | ||
|
|
||
| ## Q: How do WebAssembly Components and the WebAssembly System Interface (WASI) relate to each other? | ||
|
|
||
| While WebAssembly core module *can* represent higher level types using the available primitives, every binary and platform | ||
| may do so in an ad-hoc manner. The Component Model presents a consistent way of representing a rich set of types familiar in | ||
| most high level languages that is consistent across binaries and platforms. | ||
|
|
||
| The set of rich types which can be used by WebAssembly components are called [WebAssembly Interface Types (WIT)][wit]. | ||
|
|
||
| The WebAssembly System Interface (WASI) is a set of APIs (specified in WIT) developed for eventual standardization by the WASI | ||
| Subgroup, which is a subgroup of the WebAssembly Community Group. WASI defines interfaces, functions and types that | ||
| a system or platform can expose to a WebAssembly component. At a glance, many parts of WASI are UNIX-like, | ||
| in that they match traditional expectations for programs like STDIN, STDOUT, and writing to files. | ||
|
|
||
| Some WASI system interfaces work at a much higher level than the command line however, like | ||
| [`wasi:http`][wasi-http]. `wasi:http` is included as a standardized platform due to the ubiquity | ||
| of the internet and the common use case of WebAssembly components with "the web" as a platform. | ||
|
|
||
| With WIT, platform builders can define *any* interface that WebAssembly components | ||
| expect to access -- WASI is a standardized set which enables to build on a shared base set of abstractions. | ||
|
|
||
| [wit]: https://component-model.bytecodealliance.org/design/wit.html | ||
| [wasi-http]: https://github.com/WebAssembly/wasi-http | ||
|
|
||
| ## Q: I see the terms Preview 1 and Preview 2 frequently. What do those refer to? | ||
|
|
||
| Preview 1 refers to the first iteration of the Component Model which was based on WITX and is now deprecated: | ||
|
|
||
| https://github.com/WebAssembly/WASI/tree/main/legacy | ||
|
|
||
| Preview 2 refers to a newer iteration of the Component Model which uses WebAssembly Interface Types (WIT): | ||
|
|
||
| https://github.com/WebAssembly/WASI/tree/main/wasip2 | ||
|
|
||
| Many programming language toolchains may only support Preview 1 components natively, but this isn't a problem | ||
| in practice as Preview 1 components can be *adapted* into Preview 2 components automatically. | ||
|
|
||
| While somewhat confusing a WASI Preview 1 "component" is in fact a *WebAssembly core module*. More precisely, a | ||
| Preview 1 "component" is a WebAssembly core module with a well-defined set of imports and exports ([legacy specification][wasi-p1]). | ||
|
|
||
| ## Q: What are component imports? | ||
|
|
||
| WebAssembly components are self-describing -- information about required external functionality (which must be provided by the platform or another component) is included in the binary. | ||
| For example, a WebAssembly component that may require some use of outside environment variables may *import* a WASI interface like `wasi:cli/environment`. | ||
|
|
||
| > [!NOTE] | ||
| > The values provided by the `wasi:cli/environment` are not guaranteed | ||
| > to be ENV variables on the host machine -- this is a choice left to the | ||
| > platform, in the implementation of `wasi:cli/environment` that it exposes. | ||
| > | ||
| > For example, platforms may choose to elide sensitive environment variables, or provide none at all, in practice. | ||
vados-cosmonic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Imports are easiest illustrated with WIT: | ||
|
|
||
| ```wit | ||
| package example-namespace:example-package; | ||
|
|
||
| world example-world { | ||
| import wasi:cli/environment@0.2.4; | ||
| } | ||
| ``` | ||
|
|
||
| The [`environment` interface in `wasi:cli`][wasi-cli-env] provides various types and functions for interacting with | ||
| environment variables. | ||
|
|
||
| The component is said to "import" the `wasi:cli/environment` interface, using the available functions and types therein. | ||
itowlson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| [wasi-cli-env]: https://github.com/WebAssembly/wasi-cli/blob/main/wit/environment.wit | ||
|
|
||
| ## Q: What are component exports? | ||
|
|
||
| WebAssembly components are self-describing -- along with imports, WebAssembly components can also describe what functionality | ||
| they *export*, which callers of the component (e.g. another component, a WebAssembly host) can reference. | ||
|
|
||
| Exports are easiest illustrated with WIT: | ||
|
|
||
| ```wit | ||
| package example-namespace:example-package; | ||
|
|
||
| interface example-interface { | ||
| say-hello: func(name: string) -> string; | ||
| } | ||
|
|
||
| world example-world { | ||
| export example-interface; | ||
| } | ||
| ``` | ||
|
|
||
| For the component that inhabits the `example-world` defined above, callers can expect the WebAssembly binary to | ||
| have a `say-hello` function that is callable via the `example-namespace:example-package/example-interface` interface. | ||
|
|
||
| The component is said to "export" the `example-interface` interface, making available the functions and types therein. | ||
itowlson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Still have questions? | ||
|
|
||
| Please contribute to the Component Book by filing your question (or one that you think should be covered here) as | ||
| [an issue on GitHub][gh-issues]. | ||
|
|
||
| [gh-issues-new]: https://github.com/bytecodealliance/component-docs/issues/new | ||
|
|
||
| [!NOTE]: # | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.