Skip to content

Commit 97e0b7d

Browse files
authored
Reorganize example documentation (#11757)
* Reorganize example documentation This commit reorganizes example documentation in our online documentation. The main changes here are: * Chapter-per-language is now removed in favor of tabs-in-a-page for avoiding having the book be so large. Tabs are made with [mdbook-langtabs]. * Language-specific pages are all consolidated into a single page. * Language-specific documentation now only mentions where to find docs instead of trying to document an intro for each language here. * "Further examples" was folded into the main API section, meaning we just have one chapter of a lot of examples. The main goal is to make the book less overwhelming from an example perspective and ideally make it a bit easier to discover things. The langtabs plugin is nice but not perfect, e.g. it doesn't support `#`-anchors nor remembers which language you were looking at. Overall though I feel this is still better than before. [mdbook-langtabs]: https://github.com/nx10/mdbook-langtabs * Fix typos * Remove testing of mdbook from CI
1 parent 4f2fa15 commit 97e0b7d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+879
-1427
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,6 @@ jobs:
282282
echo "${{ runner.tool_cache }}/mdbook/bin" >> $GITHUB_PATH
283283
cargo install --root ${{ runner.tool_cache }}/mdbook --version ${{ env.CARGO_MDBOOK_VERSION }} mdbook --locked
284284
- run: (cd docs && mdbook build)
285-
- run: cargo build -p wasi-common --features wasmtime/wat,wasmtime/cranelift
286-
- run: (cd docs && mdbook test -L ../target/debug/deps)
287285

288286
# Build Rust API documentation.
289287
#

docs/SUMMARY.md

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,21 @@
77
- [CLI Logging](./cli-logging.md)
88
- [Cache Configuration](./cli-cache.md)
99
- [Using the Wasmtime API](./lang.md)
10-
- [Rust](./lang-rust.md)
11-
- [Hello, world!](./examples-rust-hello-world.md)
12-
- [Calculating the GCD](./examples-rust-gcd.md)
13-
- [Using Linear Memory](./examples-rust-memory.md)
14-
- [WASIp2](./examples-rust-wasip2.md)
15-
- [Linking Modules](./examples-rust-linking.md)
16-
- [Debugging](./examples-rust-debugging.md)
17-
- [Core Dumps](./examples-rust-core-dumps.md)
18-
- [Using Multi-Value](./examples-rust-multi-value.md)
19-
- [`anyref` Reference Type](./examples-rust-anyref.md)
20-
- [`externref` Reference Type](./examples-rust-externref.md)
21-
- [Multiple Memories](./examples-rust-multimemory.md)
22-
- [Serializing Modules](./examples-rust-serialize.md)
23-
- [Multithreaded Embedding](./examples-rust-multithreaded-embedding.md)
24-
- [Memory Protection Keys](./examples-rust-mpk.md)
25-
- [C](./lang-c.md)
26-
- [Hello, World!](./examples-c-hello-world.md)
27-
- [Calculating the GCD](./examples-c-gcd.md)
28-
- [Using Linear Memory](./examples-c-memory.md)
29-
- [WASIp1](./examples-c-wasi.md)
30-
- [Linking Modules](./examples-c-linking.md)
31-
- [Debugging](./examples-c-debugging.md)
32-
- [Using Multi-Value](./examples-c-multi-value.md)
33-
- [`anyref` Reference Type](./examples-c-anyref.md)
34-
- [`externref` Reference Type](./examples-c-externref.md)
35-
- [Multiple Memories](./examples-c-multimemory.md)
36-
- [Serializing Modules](./examples-c-serialize.md)
37-
- [Multithreaded Embedding](./examples-c-multithreaded-embedding.md)
38-
- [C++](./lang-cpp.md)
39-
- [Hello, World!](./examples-cpp-hello-world.md)
40-
- [Calculating the GCD](./examples-cpp-gcd.md)
41-
- [Using Linear Memory](./examples-cpp-memory.md)
42-
- [WASIp1](./examples-cpp-wasi.md)
43-
- [Linking Modules](./examples-cpp-linking.md)
44-
- [Using Multi-Value](./examples-cpp-multi-value.md)
45-
- [`anyref` Reference Type](./examples-cpp-anyref.md)
46-
- [`externref` Reference Type](./examples-cpp-externref.md)
47-
- [Multiple Memories](./examples-cpp-multimemory.md)
48-
- [Serializing Modules](./examples-cpp-serialize.md)
49-
- [Multithreaded Embedding](./examples-cpp-multithreaded-embedding.md)
50-
- [Async Host Functions](./examples-cpp-async.md)
51-
- [Python](./lang-python.md)
52-
- [.NET](./lang-dotnet.md)
53-
- [Go](./lang-go.md)
54-
- [Bash](./lang-bash.md)
55-
- [Ruby](./lang-ruby.md)
56-
- [Elixir](./lang-elixir.md)
57-
- [Further Examples](./examples.md)
10+
- [Hello, world!](./examples-hello-world.md)
11+
- [Calculating the GCD](./examples-gcd.md)
12+
- [Using Linear Memory](./examples-memory.md)
13+
- [Linking Modules](./examples-linking.md)
14+
- [`anyref` Reference Type](./examples-anyref.md)
15+
- [`externref` Reference Type](./examples-externref.md)
16+
- [Multiple Memories](./examples-multimemory.md)
17+
- [Using Multi-Value](./examples-multi-value.md)
18+
- [Serializing Modules](./examples-serialize.md)
19+
- [Multithreaded Embedding](./examples-multithreaded-embedding.md)
20+
- [WASIp1](./examples-wasip1.md)
21+
- [WASIp2](./examples-wasip2.md)
22+
- [Core Dumps](./examples-core-dumps.md)
23+
- [Memory Protection Keys](./examples-mpk.md)
24+
- [Async Host Functions](./examples-async.md)
5825
- [Debugging WebAssembly](./examples-debugging.md)
5926
- [Debugging with `gdb` and `lldb`](./examples-debugging-native-debugger.md)
6027
- [Debugging with Core Dumps](./examples-debugging-core-dumps.md)

docs/book.toml

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,70 @@ src = "."
55
title = "Wasmtime"
66

77
[output.html]
8-
additional-js = ["js/moment.min.2.30.1.js", "js/mermaid.min.11.6.0.js", "js/index.js"]
8+
additional-js = [
9+
"js/moment.min.2.30.1.js",
10+
"js/mermaid.min.11.6.0.js",
11+
"js/index.js",
12+
"js/langtabs.js",
13+
]
914
cname = "docs.wasmtime.dev"
1015
git-repository-url = "https://github.com/bytecodealliance/wasmtime"
1116
edit-url-template = "https://github.com/bytecodealliance/wasmtime/edit/main/docs/{path}"
17+
additional-css = ["css/langtabs.css"]
18+
19+
[output.html.redirect]
20+
"/examples-c-anyref.html" = "/examples-anyref.html"
21+
"/examples-c-debugging.html" = "/examples-debugging.html"
22+
"/examples-c-externref.html" = "/examples-externref.html"
23+
"/examples-c-gcd.html" = "/examples-gcd.html"
24+
"/examples-c-hello-world.html" = "/examples-hello-world.html"
25+
"/examples-c-linking.html" = "/examples-linking.html"
26+
"/examples-c-memory.html" = "/examples-memory.html"
27+
"/examples-c-multi-value.html" = "/examples-multi-value.html"
28+
"/examples-c-multimemory.html" = "/examples-multimemory.html"
29+
"/examples-c-multithreaded-embedding.html" = "/examples-multithreaded-embedding.html"
30+
"/examples-c-serialize.html" = "/examples-serialize.html"
31+
"/examples-c-wasi.html" = "/examples-wasip1.html"
32+
33+
"/examples-cpp-anyref.html" = "/examples-anyref.html"
34+
"/examples-cpp-debugging.html" = "/examples-debugging.html"
35+
"/examples-cpp-externref.html" = "/examples-externref.html"
36+
"/examples-cpp-gcppd.html" = "/examples-gcppd.html"
37+
"/examples-cpp-hello-world.html" = "/examples-hello-world.html"
38+
"/examples-cpp-linking.html" = "/examples-linking.html"
39+
"/examples-cpp-memory.html" = "/examples-memory.html"
40+
"/examples-cpp-multi-value.html" = "/examples-multi-value.html"
41+
"/examples-cpp-multimemory.html" = "/examples-multimemory.html"
42+
"/examples-cpp-multithreaded-embedding.html" = "/examples-multithreaded-embedding.html"
43+
"/examples-cpp-serialize.html" = "/examples-serialize.html"
44+
"/examples-cpp-wasi.html" = "/examples-wasip1.html"
45+
"/examples-cpp-async.html" = "/examples-async.html"
46+
47+
"/examples-rust-anyref.html" = "/examples-anyref.html"
48+
"/examples-rust-debugging.html" = "/examples-debugging.html"
49+
"/examples-rust-externref.html" = "/examples-externref.html"
50+
"/examples-rust-grustd.html" = "/examples-grustd.html"
51+
"/examples-rust-hello-world.html" = "/examples-hello-world.html"
52+
"/examples-rust-linking.html" = "/examples-linking.html"
53+
"/examples-rust-memory.html" = "/examples-memory.html"
54+
"/examples-rust-multi-value.html" = "/examples-multi-value.html"
55+
"/examples-rust-multimemory.html" = "/examples-multimemory.html"
56+
"/examples-rust-multithreaded-embedding.html" = "/examples-multithreaded-embedding.html"
57+
"/examples-rust-serialize.html" = "/examples-serialize.html"
58+
"/examples-rust-wasip2.html" = "/examples-wasip2.html"
59+
"/examples-rust-wasi.html" = "/examples-wasip1.html"
60+
"/examples-rust-wasip1.html" = "/examples-wasip1.html"
61+
"/examples-rust-core-dumps.html" = "/examples-core-dumps.html"
62+
"/examples-rust-mpk.html" = "/examples-mpk.html"
63+
64+
"/lang-rust.html" = "/lang.html#rust"
65+
"/lang-c.html" = "/lang.html#c"
66+
"/lang-bash.html" = "/lang.html#bash"
67+
"/lang-python.html" = "/lang.html#python"
68+
"/lang-go.html" = "/lang.html#go"
69+
"/lang-dotnet.html" = "/lang.html#net"
70+
"/lang-ruby.html" = "/lang.html#ruby"
71+
"/lang-elixir.html" = "/lang.html#elixir"
72+
73+
[preprocessor.langtabs]
74+
command = "mdbook-langtabs"

docs/css/langtabs.css

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
.langtabs {
2+
margin: 0.5em 0 1.5em 0;
3+
font-family: var(--fonts);
4+
}
5+
6+
.langtabs-header {
7+
display: flex;
8+
overflow-x: auto;
9+
gap: 0.25rem;
10+
border-bottom: 1px solid var(--icons);
11+
padding-bottom: 1px;
12+
margin-bottom: -1px;
13+
position: relative;
14+
z-index: 2;
15+
}
16+
17+
.langtabs-header {
18+
-webkit-overflow-scrolling: touch;
19+
scrollbar-width: none; /* Firefox */
20+
}
21+
22+
.langtabs-header::-webkit-scrollbar {
23+
display: none; /* Chrome, Safari, Edge */
24+
}
25+
26+
.langtabs-tab {
27+
padding: 0.6rem 1.1rem;
28+
background: none;
29+
border: 1px solid transparent;
30+
border-bottom: none;
31+
border-top-left-radius: 4px;
32+
border-top-right-radius: 4px;
33+
cursor: pointer;
34+
white-space: nowrap;
35+
display: flex;
36+
align-items: center;
37+
gap: 0.7rem;
38+
color: var(--text);
39+
font-size: 1.2rem;
40+
font-weight: 400;
41+
transition: all 0.15s ease;
42+
position: relative;
43+
top: 1px;
44+
}
45+
46+
.langtabs-tab:hover {
47+
color: var(--links);
48+
background-color: rgba(0, 0, 0, 0.03);
49+
}
50+
51+
.langtabs-tab.active {
52+
color: var(--links); /* Use theme link color */
53+
border-color: var(--icons);
54+
border-bottom: 1px solid var(--bg);
55+
background-color: var(--bg);
56+
font-weight: 500;
57+
}
58+
59+
.langtabs-icon {
60+
width: 1.4em;
61+
height: 1.4em;
62+
font-size: 1.4em;
63+
display: inline-flex;
64+
align-items: center;
65+
justify-content: center;
66+
}
67+
68+
/* inactive tabs use text color, active tabs use theme link color */
69+
.langtabs-tab .langtabs-icon {
70+
color: inherit;
71+
opacity: 0.8;
72+
}
73+
74+
.langtabs-tab.active .langtabs-icon {
75+
color: var(--links); /* Use theme link color */
76+
opacity: 1;
77+
}
78+
79+
.langtabs-content {
80+
position: relative;
81+
border: 1px solid var(--icons);
82+
border-radius: 3px;
83+
border-top-left-radius: 0;
84+
overflow: hidden;
85+
}
86+
87+
.langtabs-code {
88+
display: none;
89+
}
90+
91+
.langtabs-code.active {
92+
display: block;
93+
}
94+
95+
/* CodeBlock styling to match mdBook */
96+
.langtabs-code pre {
97+
margin: 0;
98+
padding: 0;
99+
background-color: var(--bg);
100+
}
101+
102+
.langtabs-code pre code {
103+
display: block;
104+
padding: 1rem;
105+
overflow-x: auto;
106+
font-family: var(--mono-font);
107+
font-size: 0.85em;
108+
line-height: 1.5;
109+
}
110+
111+
@media print {
112+
.langtabs-tab:not(.active) {
113+
display: none;
114+
}
115+
116+
.langtabs-content {
117+
border: 1px solid #ddd;
118+
}
119+
120+
.langtabs-code.active {
121+
display: block !important;
122+
}
123+
}
124+
125+
@media (max-width: 640px) {
126+
.langtabs-tab {
127+
padding: 0.5rem 0.8rem;
128+
font-size: 1.1rem;
129+
}
130+
131+
.langtabs-icon {
132+
font-size: 1.3em;
133+
width: 1.3em;
134+
height: 1.3em;
135+
}
136+
}

docs/examples-anyref.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Working with `anyref`
2+
3+
You can also browse this source code online and clone the wasmtime
4+
repository to run the example locally:
5+
6+
* [Rust](https://github.com/bytecodealliance/wasmtime/blob/main/examples/anyref.rs)
7+
* [C](https://github.com/bytecodealliance/wasmtime/blob/main/examples/anyref.c)
8+
* [C++](https://github.com/bytecodealliance/wasmtime/blob/main/examples/anyref.cc)
9+
10+
This example demonstrates using `anyref` values.
11+
12+
## Wasm Source
13+
14+
```wat
15+
{{#include ../examples/anyref.wat}}
16+
```
17+
18+
## Host Source
19+
20+
<!-- langtabs-start -->
21+
22+
```rust
23+
{{#include ../examples/anyref.rs}}
24+
```
25+
26+
```c
27+
{{#include ../examples/anyref.c}}
28+
```
29+
30+
```cpp
31+
{{#include ../examples/anyref.cc}}
32+
```
33+
34+
<!-- langtabs-end -->

docs/examples-cpp-async.md renamed to docs/examples-async.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ repository to run the example locally.
77

88
This example demonstrates configuring Wasmtime for asynchronous operation and calling async host functions from wasm.
99

10-
## `async.wat`
10+
## Wasm Source
1111

1212
```wat
1313
{{#include ../examples/async.wat}}
1414
```
1515

16-
## `async.cpp`
16+
## Host Source
17+
18+
<!-- langtabs-start -->
1719

1820
```cpp
1921
{{#include ../examples/async.cpp}}
2022
```
23+
24+
<!-- langtabs-end -->

docs/examples-c-anyref.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

docs/examples-c-debugging.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)