Skip to content

Commit dff85bd

Browse files
refactor: add new sections to contain reworked rust sections
1 parent e80af3e commit dff85bd

File tree

21 files changed

+319
-87
lines changed

21 files changed

+319
-87
lines changed

component-model/book.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ git-repository-url = "https://github.com/bytecodealliance/component-docs/tree/ma
1010
edit-url-template = "https://github.com/bytecodealliance/component-docs/tree/main/component-model/{path}"
1111
additional-css = ["theme/head.hbs"]
1212

13+
[output.html.fold]
14+
enable = true
15+
level = 1
16+
1317
[output.html.redirect]
1418
"/creating-and-consuming/composing.html" = "/composing-and-distributing/composing.html"
1519
"/creating-and-consuming/distributing.html" = "/composing-and-distributing/distributing.html"

component-model/src/SUMMARY.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,22 @@
1717
# Using WebAssembly Components
1818

1919
- [Creating Components](./language-support.md)
20-
- [C/C++](./language-support/c.md)
21-
- [C#](./language-support/csharp.md)
22-
- [Go](./language-support/go.md)
23-
- [JavaScript](./language-support/javascript.md)
24-
- [Python](./language-support/python.md)
25-
- [Rust](./language-support/rust.md)
26-
- [MoonBit](./language-support/moonbit.md)
27-
- [WebAssembly Text Format (WAT)](./language-support/wat.md)
28-
- [Other Languages](./language-support/other-languages.md)
20+
- [Building a simple component](./building-a-simple-component.md)
21+
- [C/C++](./language-support/building-a-simple-component/c.md)
22+
- [C#](./language-support/building-a-simple-component/csharp.md)
23+
- [Go](./language-support/building-a-simple-component/go.md)
24+
- [JavaScript](./language-support/building-a-simple-component/javascript.md)
25+
- [Python](./language-support/building-a-simple-component/python.md)
26+
- [Rust](./language-support/building-a-simple-component/rust.md)
27+
- [MoonBit](./language-support/building-a-simple-component/moonbit.md)
28+
- [WebAssembly Text Format (WAT)](./language-support/building-a-simple-component/wat.md)
29+
- [Other Languages](./language-support/building-a-simple-component/other-languages.md)
30+
- [Importing and reusing components](./importing-and-reusing-components.md)
31+
- [Rust](./language-support/importing-and-reusing-components/rust.md)
32+
- [Creating runnable components](./creating-runnable-components.md)
33+
- [Rust](./language-support/creating-runnable-components/rust.md)
34+
- [Using WIT resources](./using-wit-resources.md)
35+
- [Rust](./language-support/using-wit-resources/rust.md)
2936
- [Running Components](./running-components.md)
3037
- [Wasmtime](./running-components/wasmtime.md)
3138
- [jco](./running-components/jco.md)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Building a simple component
2+
3+
This section contains guides on how to build a simple WebAssembly component that implements an adder,
4+
with the following [WIT][docs-wit] interface:
5+
6+
```wit
7+
{{#include ../examples/tutorial/wit/adder/world.wit}}
8+
```
9+
10+
## Languages
11+
12+
This guide is implemented for various languages:
13+
14+
| Language |
15+
|----------------------------------------------------------------------------------------|
16+
| [C/C++](./language-support/building-a-simple-component/c.md) |
17+
| [C#](./language-support/building-a-simple-component/csharp.md) |
18+
| [Go](./language-support/building-a-simple-component/go.md) |
19+
| [JavaScript](./language-support/building-a-simple-component/javascript.md) |
20+
| [Python](./language-support/building-a-simple-component/python.md) |
21+
| [Rust](./language-support/building-a-simple-component/rust.md) |
22+
| [MoonBit](./language-support/building-a-simple-component/moonbit.md) |
23+
| [WebAssembly Text Format (WAT)](./language-support/building-a-simple-component/wat.md) |
24+
| [Other Languages](./language-support/building-a-simple-component/other-languages.md) |
25+
26+
[docs-wit]: ./design/wit.md

component-model/src/composing-and-distributing/composing.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,5 @@ You can compose components visually using the builder app at [wasmbuilder.app](h
155155

156156
5. When you have connected all the imports and exports that you want,
157157
click the Download Component button to download the composed component as a `.wasm` file.
158+
159+
[!NOTE]: #
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Creating Runnable Components
2+
3+
This section contains language-specific guides on how to create runnable components.
4+
5+
At a high level there are at least two ways to create components that are more like binaries than libraries
6+
(i.e. that are easy to run from a tool like `wasmtime`):
7+
8+
- Creating a "command" component
9+
- Exporting the `wasi:cli/run` interface
10+
11+
This section explores how to do the above in relevant languages.
12+
13+
## Languages
14+
15+
This guide is implemented for various languages:
16+
17+
| Language |
18+
|-----------------------------------------------------------------|
19+
| [Rust](./language-support/creating-runnable-components/rust.md) |
20+
21+
[docs-wit]: ./design/wit.md
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Importing and reusing components
2+
3+
This section contains language-specific guides on how to reuse existing WebAssembly
4+
components, in particular using an `adder` component to complete a `calculator` component.
5+
6+
The `adder` component has the following [WIT][docs-wit] interface:
7+
8+
```wit
9+
{{#include ../examples/tutorial/wit/adder/world.wit}}
10+
```
11+
12+
The `calculator` component has the following interface:
13+
14+
```wit
15+
{{#include ../examples/tutorial/wit/calculator/world.wit}}
16+
```
17+
18+
## Languages
19+
20+
This guide is implemented for various languages:
21+
22+
| Language |
23+
|---------------------------------------------------------------------|
24+
| [Rust](./language-support/importing-and-reusing-components/rust.md) |
25+
26+
[docs-wit]: ./design/wit.md

component-model/src/introduction.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ This documentation is aimed at _users_ of the component model: developers of lib
2626
[Interfaces]: ./design/interfaces.md
2727
[Worlds]: ./design/worlds.md
2828

29-
[C/C++]: ./language-support/c.md
30-
[C#]: ./language-support/csharp.md
31-
[Go]: ./language-support/go.md
32-
[JavaScript]: ./language-support/javascript.md
33-
[Python]: ./language-support/python.md
34-
[Rust]: ./language-support/rust.md
35-
[MoonBit]: ./language-support/moonbit.md
29+
[C/C++]: ./language-support/building-a-simple-component/c.md
30+
[C#]: ./language-support/building-a-simple-component/csharp.md
31+
[Go]: ./language-support/building-a-simple-component/go.md
32+
[JavaScript]: ./language-support/building-a-simple-component/javascript.md
33+
[Python]: ./language-support/building-a-simple-component/python.md
34+
[Rust]: ./language-support/building-a-simple-component/rust.md
35+
[MoonBit]: ./language-support/building-a-simple-component/moonbit.md
3636

3737
[Composing]: ./composing-and-distributing/composing.md
3838
[Running]: ./running-components.md

component-model/src/language-support.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@ The last section, on WebAssembly Text Format (WAT),
2323
details how to write WebAssembly components by hand,
2424
without using a higher-level language front-end.
2525

26-
- [C/C++ Tooling](./language-support/c.md)
27-
- [Building a Component with `wit-bindgen` and `wasm-tools`](./language-support/c.md#building-a-component-with-wit-bindgen-and-wasm-tools)
28-
- [Running a Component from C/C++ Applications](./language-support/c.md#running-a-component-from-cc-applications)
29-
- [C# Tooling](./language-support/csharp.md)
30-
- [Go Tooling](./language-support/go.md)
31-
- [JavaScript Tooling](./language-support/javascript.md)
32-
- [Building a Component with `jco`](./language-support/javascript.md#building-a-component-with-jco)
33-
- [Running a Component from JavaScript Applications](./language-support/javascript.md#running-a-component-from-javascript-applications)
34-
- [Python Tooling](./language-support/python.md)
35-
- [Building a Component with `componentize-py`](./language-support/python.md#building-a-component-with-componentize-py)
36-
- [Running components from Python Applications](./language-support/python.md#running-components-from-python-applications)
37-
- [Rust Tooling](./language-support/rust.md)
38-
- [Building a Component](./language-support/rust.md#building-a-component)
39-
- [Running a Component from Rust Applications](./language-support/rust.md#running-a-component-from-rust-appliacations)
40-
- [MoonBit Tooling](./language-support/moonbit.md)
41-
- [WebAssembly Text Format (WAT)](./language-support/wat.md#wat-webassembly-text-format)
42-
- [Building a Component from WAT with `wasm-tools`](./language-support/wat.md#building-a-component-with-wasm-tools)
43-
- [Running a Component with Wasmtime](./language-support/wat.md#running-a-component-with-wasmtime)
44-
- [Other Languages with Component Model Support](./language-support/other-languages.md)
26+
- [C/C++ Tooling](./language-support/building-a-simple-component/c.md)
27+
- [Building a Component with `wit-bindgen` and `wasm-tools`](./language-support/building-a-simple-component/c.md#building-a-component-with-wit-bindgen-and-wasm-tools)
28+
- [Running a Component from C/C++ Applications](./language-support/building-a-simple-component/c.md#running-a-component-from-cc-applications)
29+
- [C# Tooling](./language-support/building-a-simple-component/csharp.md)
30+
- [Go Tooling](./language-support/building-a-simple-component/go.md)
31+
- [JavaScript Tooling](./language-support/building-a-simple-component/javascript.md)
32+
- [Building a Component with `jco`](./language-support/building-a-simple-component/javascript.md#building-a-component-with-jco)
33+
- [Running a Component from JavaScript Applications](./language-support/building-a-simple-component/javascript.md#running-a-component-from-javascript-applications)
34+
- [Python Tooling](./language-support/building-a-simple-component/python.md)
35+
- [Building a Component with `componentize-py`](./language-support/building-a-simple-component/python.md#building-a-component-with-componentize-py)
36+
- [Running components from Python Applications](./language-support/building-a-simple-component/python.md#running-components-from-python-applications)
37+
- [Rust Tooling](./language-support/building-a-simple-component/rust.md)
38+
- [Building a Component](./language-support/building-a-simple-component/rust.md#building-a-component)
39+
- [Running a Component from Rust Applications](./language-support/building-a-simple-component/rust.md#running-a-component-from-rust-appliacations)
40+
- [MoonBit Tooling](./language-support/building-a-simple-component/moonbit.md)
41+
- [WebAssembly Text Format (WAT)](./language-support/building-a-simple-component/wat.md#wat-webassembly-text-format)
42+
- [Building a Component from WAT with `wasm-tools`](./language-support/building-a-simple-component/wat.md#building-a-component-with-wasm-tools)
43+
- [Running a Component with Wasmtime](./language-support/building-a-simple-component/wat.md#running-a-component-with-wasmtime)
44+
- [Other Languages with Component Model Support](./language-support/building-a-simple-component/other-languages.md)

component-model/src/language-support/c.md renamed to component-model/src/language-support/building-a-simple-component/c.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ First, install the following dependencies:
4040
as well as converting between preview1 modules and preview2 components in
4141
the optional manual workflow.
4242
3. The [`WASI SDK`](https://github.com/webassembly/wasi-sdk)
43-
* WASI SDK is a WASI enabled C/C++ toolchain which includes a version of the C standard
43+
* WASI SDK is a WASI enabled C/C++ toolchain which includes a version of the C standard
4444
library (`libc`) implemented with WASI interfaces,
4545
among other artifacts necessary to compile C/C++ to WebAssembly.
4646
* On a Linux system, you can skip to the ["Install"](https://github.com/webassembly/wasi-sdk?tab=readme-ov-file#install) section.
@@ -91,7 +91,7 @@ Next, create a file named `component.c` with code that implements the `adder` wo
9191
that is, code which fulfills the definition of the interface function declared in `adder.h`.
9292

9393
```c
94-
{{#include ../../examples/tutorial/c/adder/component.c}}
94+
{{#include ../../../examples/tutorial/c/adder/component.c}}
9595
```
9696
9797
## 4. Compile a WebAssembly Preview 2 component with `wasi-sdk`'s `wasm32-wasip2-clang`
@@ -231,7 +231,7 @@ For example, if we modify the above code to reference `printf()`,
231231
it would compile to a P1 component:
232232

233233
```c
234-
{{#include ../../examples/tutorial/c/adder/component_with_printf.c}}
234+
{{#include ../../../examples/tutorial/c/adder/component_with_printf.c}}
235235
```
236236
237237
However, the module would fail to transform to a P2 component:
@@ -314,14 +314,14 @@ The following section requires you to have [a Rust toolchain][rust] installed.
314314
> (The `wasmtime` version is specified in [the Cargo configuration file][cargo-config]
315315
> for the example host.)
316316
317-
{{#include example-host-part1.md}}
317+
{{#include ../example-host-part1.md}}
318318

319319
A successful run should show the following output
320320
(of course, the paths to your example host and adder component will vary,
321321
and you should substitute `adder.wasm` with `adder.component.wasm`
322322
if you followed the manual instructions above):
323323

324-
{{#include example-host-part2.md}}
324+
{{#include ../example-host-part2.md}}
325325

326326
## 7. Run the component from C/C++ Applications
327327

@@ -334,7 +334,7 @@ and run by their toolchains,
334334
or even composed with a C language command component and run via the `wasmtime` CLI
335335
or any other host.
336336

337-
See the [Rust Tooling guide](../language-support/rust.md#running-a-component-from-rust-applications)
337+
See the [Rust Tooling guide](./rust.md#running-a-component-from-rust-applications)
338338
for instructions on how to run this component from the Rust `example-host`
339339
(replacing the path to `add.wasm` with your `adder.wasm` or `adder.component.wasm` above).
340340

component-model/src/language-support/csharp.md renamed to component-model/src/language-support/building-a-simple-component/csharp.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ For this example we will use a WIT file containing two worlds
4343
Copy and paste the following into a new file called "`wit/component.wit`".
4444

4545
```wit
46-
{{#include ../../examples/tutorial/csharp/adder/world-hostapp.wit}}
46+
{{#include ../../../examples/tutorial/csharp/adder/world-hostapp.wit}}
4747
```
4848

4949
In the `adder.csproj` project file, add a new `<ItemGroup>`
@@ -88,7 +88,7 @@ This is because we've promised an implementation, but haven't yet written one fo
8888
To fix this, add the following code in a file called `Component.cs`:
8989

9090
```csharp
91-
{{#include ../../examples/tutorial/csharp/adder/Component.cs}}
91+
{{#include ../../../examples/tutorial/csharp/adder/Component.cs}}
9292
```
9393

9494
Then, we can build our component:
@@ -103,12 +103,12 @@ The component will be available at `bin/Debug/net10.0/wasi-wasm/native/adder.was
103103

104104
The following section requires you to have [a Rust toolchain][rust] installed.
105105

106-
{{#include example-host-part1.md}}
106+
{{#include ../example-host-part1.md}}
107107

108108
A successful run should show the following output
109109
(of course, the paths to your example host and adder component will vary):
110110

111-
{{#include example-host-part2.md}}
111+
{{#include ../example-host-part2.md}}
112112

113113
[rust]: https://www.rust-lang.org/learn/get-started
114114

@@ -135,7 +135,7 @@ cd host-app
135135
Copy the following WIT file into a file called `wit/add.wit` in your project:
136136

137137
```wit
138-
{{#include ../../examples/tutorial/csharp/adder/world-hostapp.wit}}
138+
{{#include ../../../examples/tutorial/csharp/adder/world-hostapp.wit}}
139139
```
140140

141141
Add it to your `host-app.csproj` project file as a new `ItemGroup` at the top level:
@@ -154,7 +154,7 @@ Now we'll be focusing on the executable side of the application—the `hostapp`
154154
Modify `Program.cs` to look like this:
155155

156156
```csharp
157-
{{#include ../../examples/tutorial/csharp/adder/Program.cs}}
157+
{{#include ../../../examples/tutorial/csharp/adder/Program.cs}}
158158
```
159159

160160
Once again, compile your component with `dotnet build`:

0 commit comments

Comments
 (0)