A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Reorganize example documentation (#11757)
Alex Crichton97e0b7db9ba9
diff --git a/.github/workflows/main.yml b/.github/workflows/main.ymlindex 0bf0da0c2a..78f12e0992 100644--- a/.github/workflows/main.yml+++ b/.github/workflows/main.yml@@ -282,8 +282,6 @@ jobs:echo "${{ runner.tool_cache }}/mdbook/bin" >> $GITHUB_PATHcargo install --root ${{ runner.tool_cache }}/mdbook --version ${{ env.CARGO_MDBOOK_VERSION }} mdbook --locked- run: (cd docs && mdbook build)- - run: cargo build -p wasi-common --features wasmtime/wat,wasmtime/cranelift- - run: (cd docs && mdbook test -L ../target/debug/deps)# Build Rust API documentation.#diff --git a/docs/SUMMARY.md b/docs/SUMMARY.mdindex d9b0bbab4d..2ee46ed707 100644--- a/docs/SUMMARY.md+++ b/docs/SUMMARY.md@@ -7,54 +7,21 @@- [CLI Logging](./cli-logging.md)- [Cache Configuration](./cli-cache.md)- [Using the Wasmtime API](./lang.md)- - [Rust](./lang-rust.md)- - [Hello, world!](./examples-rust-hello-world.md)- - [Calculating the GCD](./examples-rust-gcd.md)- - [Using Linear Memory](./examples-rust-memory.md)- - [WASIp2](./examples-rust-wasip2.md)- - [Linking Modules](./examples-rust-linking.md)- - [Debugging](./examples-rust-debugging.md)- - [Core Dumps](./examples-rust-core-dumps.md)- - [Using Multi-Value](./examples-rust-multi-value.md)- - [`anyref` Reference Type](./examples-rust-anyref.md)- - [`externref` Reference Type](./examples-rust-externref.md)- - [Multiple Memories](./examples-rust-multimemory.md)- - [Serializing Modules](./examples-rust-serialize.md)- - [Multithreaded Embedding](./examples-rust-multithreaded-embedding.md)- - [Memory Protection Keys](./examples-rust-mpk.md)- - [C](./lang-c.md)- - [Hello, World!](./examples-c-hello-world.md)- - [Calculating the GCD](./examples-c-gcd.md)- - [Using Linear Memory](./examples-c-memory.md)- - [WASIp1](./examples-c-wasi.md)- - [Linking Modules](./examples-c-linking.md)- - [Debugging](./examples-c-debugging.md)- - [Using Multi-Value](./examples-c-multi-value.md)- - [`anyref` Reference Type](./examples-c-anyref.md)- - [`externref` Reference Type](./examples-c-externref.md)- - [Multiple Memories](./examples-c-multimemory.md)- - [Serializing Modules](./examples-c-serialize.md)- - [Multithreaded Embedding](./examples-c-multithreaded-embedding.md)- - [C++](./lang-cpp.md)- - [Hello, World!](./examples-cpp-hello-world.md)- - [Calculating the GCD](./examples-cpp-gcd.md)- - [Using Linear Memory](./examples-cpp-memory.md)- - [WASIp1](./examples-cpp-wasi.md)- - [Linking Modules](./examples-cpp-linking.md)- - [Using Multi-Value](./examples-cpp-multi-value.md)- - [`anyref` Reference Type](./examples-cpp-anyref.md)- - [`externref` Reference Type](./examples-cpp-externref.md)- - [Multiple Memories](./examples-cpp-multimemory.md)- - [Serializing Modules](./examples-cpp-serialize.md)- - [Multithreaded Embedding](./examples-cpp-multithreaded-embedding.md)- - [Async Host Functions](./examples-cpp-async.md)- - [Python](./lang-python.md)- - [.NET](./lang-dotnet.md)- - [Go](./lang-go.md)- - [Bash](./lang-bash.md)- - [Ruby](./lang-ruby.md)- - [Elixir](./lang-elixir.md)-- [Further Examples](./examples.md)+ - [Hello, world!](./examples-hello-world.md)+ - [Calculating the GCD](./examples-gcd.md)+ - [Using Linear Memory](./examples-memory.md)+ - [Linking Modules](./examples-linking.md)+ - [`anyref` Reference Type](./examples-anyref.md)+ - [`externref` Reference Type](./examples-externref.md)+ - [Multiple Memories](./examples-multimemory.md)+ - [Using Multi-Value](./examples-multi-value.md)+ - [Serializing Modules](./examples-serialize.md)+ - [Multithreaded Embedding](./examples-multithreaded-embedding.md)+ - [WASIp1](./examples-wasip1.md)+ - [WASIp2](./examples-wasip2.md)+ - [Core Dumps](./examples-core-dumps.md)+ - [Memory Protection Keys](./examples-mpk.md)+ - [Async Host Functions](./examples-async.md)- [Debugging WebAssembly](./examples-debugging.md)- [Debugging with `gdb` and `lldb`](./examples-debugging-native-debugger.md)- [Debugging with Core Dumps](./examples-debugging-core-dumps.md)diff --git a/docs/book.toml b/docs/book.tomlindex 47226af030..ebfc4b765a 100644--- a/docs/book.toml+++ b/docs/book.toml@@ -5,7 +5,70 @@ src = "."title = "Wasmtime"[output.html]-additional-js = ["js/moment.min.2.30.1.js", "js/mermaid.min.11.6.0.js", "js/index.js"]+additional-js = [+ "js/moment.min.2.30.1.js",+ "js/mermaid.min.11.6.0.js",+ "js/index.js",+ "js/langtabs.js",+]cname = "docs.wasmtime.dev"git-repository-url = "https://github.com/bytecodealliance/wasmtime"edit-url-template = "https://github.com/bytecodealliance/wasmtime/edit/main/docs/{path}"+additional-css = ["css/langtabs.css"]++[output.html.redirect]+"/examples-c-anyref.html" = "/examples-anyref.html"+"/examples-c-debugging.html" = "/examples-debugging.html"+"/examples-c-externref.html" = "/examples-externref.html"+"/examples-c-gcd.html" = "/examples-gcd.html"+"/examples-c-hello-world.html" = "/examples-hello-world.html"+"/examples-c-linking.html" = "/examples-linking.html"+"/examples-c-memory.html" = "/examples-memory.html"+"/examples-c-multi-value.html" = "/examples-multi-value.html"+"/examples-c-multimemory.html" = "/examples-multimemory.html"+"/examples-c-multithreaded-embedding.html" = "/examples-multithreaded-embedding.html"+"/examples-c-serialize.html" = "/examples-serialize.html"+"/examples-c-wasi.html" = "/examples-wasip1.html"++"/examples-cpp-anyref.html" = "/examples-anyref.html"+"/examples-cpp-debugging.html" = "/examples-debugging.html"+"/examples-cpp-externref.html" = "/examples-externref.html"+"/examples-cpp-gcppd.html" = "/examples-gcppd.html"+"/examples-cpp-hello-world.html" = "/examples-hello-world.html"+"/examples-cpp-linking.html" = "/examples-linking.html"+"/examples-cpp-memory.html" = "/examples-memory.html"+"/examples-cpp-multi-value.html" = "/examples-multi-value.html"+"/examples-cpp-multimemory.html" = "/examples-multimemory.html"+"/examples-cpp-multithreaded-embedding.html" = "/examples-multithreaded-embedding.html"+"/examples-cpp-serialize.html" = "/examples-serialize.html"+"/examples-cpp-wasi.html" = "/examples-wasip1.html"+"/examples-cpp-async.html" = "/examples-async.html"++"/examples-rust-anyref.html" = "/examples-anyref.html"+"/examples-rust-debugging.html" = "/examples-debugging.html"+"/examples-rust-externref.html" = "/examples-externref.html"+"/examples-rust-grustd.html" = "/examples-grustd.html"+"/examples-rust-hello-world.html" = "/examples-hello-world.html"+"/examples-rust-linking.html" = "/examples-linking.html"+"/examples-rust-memory.html" = "/examples-memory.html"+"/examples-rust-multi-value.html" = "/examples-multi-value.html"+"/examples-rust-multimemory.html" = "/examples-multimemory.html"+"/examples-rust-multithreaded-embedding.html" = "/examples-multithreaded-embedding.html"+"/examples-rust-serialize.html" = "/examples-serialize.html"+"/examples-rust-wasip2.html" = "/examples-wasip2.html"+"/examples-rust-wasi.html" = "/examples-wasip1.html"+"/examples-rust-wasip1.html" = "/examples-wasip1.html"+"/examples-rust-core-dumps.html" = "/examples-core-dumps.html"+"/examples-rust-mpk.html" = "/examples-mpk.html"++"/lang-rust.html" = "/lang.html#rust"+"/lang-c.html" = "/lang.html#c"+"/lang-bash.html" = "/lang.html#bash"+"/lang-python.html" = "/lang.html#python"+"/lang-go.html" = "/lang.html#go"+"/lang-dotnet.html" = "/lang.html#net"+"/lang-ruby.html" = "/lang.html#ruby"+"/lang-elixir.html" = "/lang.html#elixir"++[preprocessor.langtabs]+command = "mdbook-langtabs"diff --git a/docs/css/langtabs.css b/docs/css/langtabs.cssnew file mode 100644index 0000000000..de68a8bf5e--- /dev/null+++ b/docs/css/langtabs.css@@ -0,0 +1,136 @@+.langtabs {+ margin: 0.5em 0 1.5em 0;+ font-family: var(--fonts);+}++.langtabs-header {+ display: flex;+ overflow-x: auto;+ gap: 0.25rem;+ border-bottom: 1px solid var(--icons);+ padding-bottom: 1px;+ margin-bottom: -1px;+ position: relative;+ z-index: 2;+}++.langtabs-header {+ -webkit-overflow-scrolling: touch;+ scrollbar-width: none; /* Firefox */+}++.langtabs-header::-webkit-scrollbar {+ display: none; /* Chrome, Safari, Edge */+}++.langtabs-tab {+ padding: 0.6rem 1.1rem;+ background: none;+ border: 1px solid transparent;+ border-bottom: none;+ border-top-left-radius: 4px;+ border-top-right-radius: 4px;+ cursor: pointer;+ white-space: nowrap;+ display: flex;+ align-items: center;+ gap: 0.7rem;+ color: var(--text);+ font-size: 1.2rem;+ font-weight: 400;+ transition: all 0.15s ease;+ position: relative;+ top: 1px;+}++.langtabs-tab:hover {+ color: var(--links);+ background-color: rgba(0, 0, 0, 0.03);+}++.langtabs-tab.active {+ color: var(--links); /* Use theme link color */+ border-color: var(--icons);+ border-bottom: 1px solid var(--bg);+ background-color: var(--bg);+ font-weight: 500;+}++.langtabs-icon {+ width: 1.4em;+ height: 1.4em;+ font-size: 1.4em;+ display: inline-flex;+ align-items: center;+ justify-content: center;+}++/* inactive tabs use text color, active tabs use theme link color */+.langtabs-tab .langtabs-icon {+ color: inherit;+ opacity: 0.8;+}++.langtabs-tab.active .langtabs-icon {+ color: var(--links); /* Use theme link color */+ opacity: 1;+}++.langtabs-content {+ position: relative;+ border: 1px solid var(--icons);+ border-radius: 3px;+ border-top-left-radius: 0;+ overflow: hidden;+}++.langtabs-code {+ display: none;+}++.langtabs-code.active {+ display: block;+}++/* CodeBlock styling to match mdBook */+.langtabs-code pre {+ margin: 0;+ padding: 0;+ background-color: var(--bg);+}++.langtabs-code pre code {+ display: block;+ padding: 1rem;+ overflow-x: auto;+ font-family: var(--mono-font);+ font-size: 0.85em;+ line-height: 1.5;+}++@media print {+ .langtabs-tab:not(.active) {+ display: none;+ }++ .langtabs-content {+ border: 1px solid #ddd;+ }++ .langtabs-code.active {+ display: block !important;+ }+}++@media (max-width: 640px) {+ .langtabs-tab {+ padding: 0.5rem 0.8rem;+ font-size: 1.1rem;+ }++ .langtabs-icon {+ font-size: 1.3em;+ width: 1.3em;+ height: 1.3em;+ }+}\ No newline at end of filediff --git a/docs/examples-anyref.md b/docs/examples-anyref.mdnew file mode 100644index 0000000000..6dbc45a396--- /dev/null+++ b/docs/examples-anyref.md@@ -0,0 +1,34 @@+# Working with `anyref`++You can also browse this source code online and clone the wasmtime+repository to run the example locally:++* [Rust](https://github.com/bytecodealliance/wasmtime/blob/main/examples/anyref.rs)+* [C](https://github.com/bytecodealliance/wasmtime/blob/main/examples/anyref.c)+* [C++](https://github.com/bytecodealliance/wasmtime/blob/main/examples/anyref.cc)++This example demonstrates using `anyref` values.++## Wasm Source++```wat+{{#include ../examples/anyref.wat}}+```++## Host Source++<!-- langtabs-start -->++```rust+{{#include ../examples/anyref.rs}}+```++```c+{{#include ../examples/anyref.c}}+```++```cpp+{{#include ../examples/anyref.cc}}+```++<!-- langtabs-end -->diff --git a/docs/examples-cpp-async.md b/docs/examples-async.mdsimilarity index 85%rename from docs/examples-cpp-async.mdrename to docs/examples-async.mdindex 62ac756c79..5bacc5c0a9 100644--- a/docs/examples-cpp-async.md+++ b/docs/examples-async.md@@ -7,14 +7,18 @@ repository to run the example locally.This example demonstrates configuring Wasmtime for asynchronous operation and calling async host functions from wasm.-## `async.wat`+## Wasm Source```wat{{#include ../examples/async.wat}}```-## `async.cpp`+## Host Source++<!-- langtabs-start -->```cpp{{#include ../examples/async.cpp}}```++<!-- langtabs-end -->diff --git a/docs/examples-c-anyref.md b/docs/examples-c-anyref.mddeleted file mode 100644index a69a0cbcfa..0000000000--- a/docs/examples-c-anyref.md+++ /dev/null@@ -1,20 +0,0 @@-# Working with `anyref`--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/anyref.c--This example demonstrates using `anyref` values.--## `anyref.wat`--```wat-{{#include ../examples/anyref.wat}}-```--## `anyref.c`--```c-{{#include ../examples/anyref.c}}-```diff --git a/docs/examples-c-debugging.md b/docs/examples-c-debugging.mddeleted file mode 100644index 9e0c04abcb..0000000000--- a/docs/examples-c-debugging.md+++ /dev/null@@ -1,15 +0,0 @@-# Debugging--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/fib-debug/main.c--This example shows off how to set up a module for dynamic runtime debugging via-a native debugger like GDB or LLDB.--## `main.c`--```c-{{#include ../examples/fib-debug/main.c}}-```diff --git a/docs/examples-c-externref.md b/docs/examples-c-externref.mddeleted file mode 100644index 26708b8a7f..0000000000--- a/docs/examples-c-externref.md+++ /dev/null@@ -1,20 +0,0 @@-# Working with `externref`--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/externref.c--This example shows how to pass opaque host references into and out of WebAssembly using `externref`.--## `externref.wat`--```wat-{{#include ../examples/externref.wat}}-```--## `externref.c`--```c-{{#include ../examples/externref.c}}-```diff --git a/docs/examples-c-gcd.md b/docs/examples-c-gcd.mddeleted file mode 100644index 3816c94d3a..0000000000--- a/docs/examples-c-gcd.md+++ /dev/null@@ -1,22 +0,0 @@-# Calculating the GCD--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/gcd.c--This example shows off how run a wasm program which calculates the GCD of two-numbers.--## `gcd.wat`--```wat-{{#include ../examples/gcd.wat}}-```---## `gcd.c`--```c-{{#include ../examples/gcd.c}}-```diff --git a/docs/examples-c-hello-world.md b/docs/examples-c-hello-world.mddeleted file mode 100644index e27dfa370c..0000000000--- a/docs/examples-c-hello-world.md+++ /dev/null@@ -1,22 +0,0 @@-# Hello, world!--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/hello.c--This example shows off how to instantiate a simple wasm module and interact with-it.--## `hello.wat`--```wat-{{#include ../examples/hello.wat}}-```---## `hello.c`--```c-{{#include ../examples/hello.c}}-```diff --git a/docs/examples-c-linking.md b/docs/examples-c-linking.mddeleted file mode 100644index 51e327f9fa..0000000000--- a/docs/examples-c-linking.md+++ /dev/null@@ -1,27 +0,0 @@-# Linking modules--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/linking.c--This example shows off how to compile and instantiate modules which link-together.--## `linking1.wat`--```wat-{{#include ../examples/linking1.wat}}-```--## `linking2.wat`--```wat-{{#include ../examples/linking2.wat}}-```--## `linking.c`--```c-{{#include ../examples/linking.c}}-```diff --git a/docs/examples-c-memory.md b/docs/examples-c-memory.mddeleted file mode 100644index 758f61d7b2..0000000000--- a/docs/examples-c-memory.md+++ /dev/null@@ -1,24 +0,0 @@-# Using linear memory--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/memory.c--This example shows off how to interact with wasm memory in a module. Be sure to-read the documentation for [`Memory`] as well.--[`Memory`]: https://bytecodealliance.github.io/wasmtime/api/wasmtime/struct.Memory.html--## `memory.wat`--```wat-{{#include ../examples/memory.wat}}-```---## `memory.c`--```c-{{#include ../examples/memory.c}}-```diff --git a/docs/examples-c-multi-value.md b/docs/examples-c-multi-value.mddeleted file mode 100644index c55ef0db76..0000000000--- a/docs/examples-c-multi-value.md+++ /dev/null@@ -1,22 +0,0 @@-# Using multi-value--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/multi.c--This example shows off how to interact with a wasm module that uses multi-value-exports and imports.--## `multi.wat`--```wat-{{#include ../examples/multi.wat}}-```---## `multi.c`--```c-{{#include ../examples/multi.c}}-```diff --git a/docs/examples-c-multimemory.md b/docs/examples-c-multimemory.mddeleted file mode 100644index d112941cc0..0000000000--- a/docs/examples-c-multimemory.md+++ /dev/null@@ -1,20 +0,0 @@-# Working with Multiple Memories--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/multimemory.c--This example demonstrates instantiating and interacting with a module that has multiple linear memories.--## `multimemory.wat`--```wat-{{#include ../examples/multimemory.wat}}-```--## `multimemory.c`--```c-{{#include ../examples/multimemory.c}}-```diff --git a/docs/examples-c-multithreaded-embedding.md b/docs/examples-c-multithreaded-embedding.mddeleted file mode 100644index a586794218..0000000000--- a/docs/examples-c-multithreaded-embedding.md+++ /dev/null@@ -1,20 +0,0 @@-# Multithreaded Embedding--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/threads.c--This example demonstrates using Wasmtime in multithreaded runtimes.--## `threads.wat`--```wat-{{#include ../examples/threads.wat}}-```--## `threads.c`--```c-{{#include ../examples/threads.c}}-```diff --git a/docs/examples-c-serialize.md b/docs/examples-c-serialize.mddeleted file mode 100644index 9f7bd027cb..0000000000--- a/docs/examples-c-serialize.md+++ /dev/null@@ -1,14 +0,0 @@-# Serializing and Deserializing Modules--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/serialize.c--This example shows how to serialize a compiled module to disk and later deserialize it to skip compilation on the critical path.--## `serialize.c`--```c-{{#include ../examples/serialize.c}}-```diff --git a/docs/examples-c-wasi.md b/docs/examples-c-wasi.mddeleted file mode 100644index 8906562cd8..0000000000--- a/docs/examples-c-wasi.md+++ /dev/null@@ -1,21 +0,0 @@-# WASI--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/wasip1/main.c--This example shows off how to instantiate a wasm module using WASI imports.--## Wasm Source code--```rust,ignore-{{#include ../examples/wasm/wasi.rs}}-```---## `wasi.c`--```c-{{#include ../examples/wasip1/main.c}}-```diff --git a/docs/examples-rust-core-dumps.md b/docs/examples-core-dumps.mdsimilarity index 89%rename from docs/examples-rust-core-dumps.mdrename to docs/examples-core-dumps.mdindex a1169fe58e..53b0fd60f6 100644--- a/docs/examples-rust-core-dumps.md+++ b/docs/examples-core-dumps.md@@ -12,8 +12,12 @@ post-mortem analysis.[core dumps]: https://github.com/WebAssembly/tool-conventions/blob/main/Coredump.md[`wasmgdb`]: https://github.com/xtuc/wasm-coredump/blob/main/bin/wasmgdb/README.md-## `main.rs`+## Host Source-```rust,ignore+<!-- langtabs-start -->++```rust{{#include ../examples/coredump.rs}}```++<!-- langtabs-end -->diff --git a/docs/examples-cpp-anyref.md b/docs/examples-cpp-anyref.mddeleted file mode 100644index 11186b2050..0000000000--- a/docs/examples-cpp-anyref.md+++ /dev/null@@ -1,20 +0,0 @@-# Working with `anyref`--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/anyref.cc--This example demonstrates using `anyref` values.--## `anyref.wat`--```wat-{{#include ../examples/anyref.wat}}-```--## `anyref.cc`--```cpp-{{#include ../examples/anyref.cc}}-```diff --git a/docs/examples-cpp-externref.md b/docs/examples-cpp-externref.mddeleted file mode 100644index dc7f17f840..0000000000--- a/docs/examples-cpp-externref.md+++ /dev/null@@ -1,20 +0,0 @@-# Working with `externref`--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/externref.cc--This example shows how to pass opaque host references into and out of WebAssembly using `externref`.--## `externref.wat`--```wat-{{#include ../examples/externref.wat}}-```--## `externref.cc`--```cpp-{{#include ../examples/externref.cc}}-```diff --git a/docs/examples-cpp-gcd.md b/docs/examples-cpp-gcd.mddeleted file mode 100644index 2ac579856d..0000000000--- a/docs/examples-cpp-gcd.md+++ /dev/null@@ -1,20 +0,0 @@-# Calculating the GCD--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/gcd.cc--This example shows off how to run a wasm program which calculates the GCD of two numbers.--## `gcd.wat`--```wat-{{#include ../examples/gcd.wat}}-```--## `gcd.cc`--```cpp-{{#include ../examples/gcd.cc}}-```diff --git a/docs/examples-cpp-hello-world.md b/docs/examples-cpp-hello-world.mddeleted file mode 100644index 00d136b6a4..0000000000--- a/docs/examples-cpp-hello-world.md+++ /dev/null@@ -1,20 +0,0 @@-# Hello, world!--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/hello.cc--This example shows off how to instantiate a simple wasm module with a host function import and call an exported function.--## `hello.wat`--```wat-{{#include ../examples/hello.wat}}-```--## `hello.cc`--```cpp-{{#include ../examples/hello.cc}}-```diff --git a/docs/examples-cpp-linking.md b/docs/examples-cpp-linking.mddeleted file mode 100644index 312695d6f2..0000000000--- a/docs/examples-cpp-linking.md+++ /dev/null@@ -1,26 +0,0 @@-# Linking modules together--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/linking.cc--This example shows off how to link multiple wasm modules together, where one module imports functions exported by another.--## `linking1.wat`--```wat-{{#include ../examples/linking1.wat}}-```--## `linking2.wat`--```wat-{{#include ../examples/linking2.wat}}-```--## `linking.cc`--```cpp-{{#include ../examples/linking.cc}}-```diff --git a/docs/examples-cpp-memory.md b/docs/examples-cpp-memory.mddeleted file mode 100644index 780ad09c0d..0000000000--- a/docs/examples-cpp-memory.md+++ /dev/null@@ -1,20 +0,0 @@-# Working with Memory--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/memory.cc--This example shows off how to interact with wasm memory from the host, reading and writing data directly.--## `memory.wat`--```wat-{{#include ../examples/memory.wat}}-```--## `memory.cc`--```cpp-{{#include ../examples/memory.cc}}-```diff --git a/docs/examples-cpp-multi-value.md b/docs/examples-cpp-multi-value.mddeleted file mode 100644index a4e4afe935..0000000000--- a/docs/examples-cpp-multi-value.md+++ /dev/null@@ -1,22 +0,0 @@-# Using multi-value--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/multi.cc--This example shows off how to interact with a wasm module that uses multi-value-exports and imports.--## `multi.wat`--```wat-{{#include ../examples/multi.wat}}-```---## `multi.cc`--```c-{{#include ../examples/multi.cc}}-```diff --git a/docs/examples-cpp-multimemory.md b/docs/examples-cpp-multimemory.mddeleted file mode 100644index 30ccddc865..0000000000--- a/docs/examples-cpp-multimemory.md+++ /dev/null@@ -1,20 +0,0 @@-# Working with Multiple Memories--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/multimemory.cc--This example demonstrates using a module with multiple linear memories.--## `multimemory.wat`--```wat-{{#include ../examples/multimemory.wat}}-```--## `multimemory.cc`--```cpp-{{#include ../examples/multimemory.cc}}-```diff --git a/docs/examples-cpp-multithreaded-embedding.md b/docs/examples-cpp-multithreaded-embedding.mddeleted file mode 100644index 6293b22c45..0000000000--- a/docs/examples-cpp-multithreaded-embedding.md+++ /dev/null@@ -1,20 +0,0 @@-# Multithreaded Embedding--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/threads.cc--This example demonstrates using Wasmtime in multithreaded runtimes.--## `threads.wat`--```wat-{{#include ../examples/threads.wat}}-```--## `threads.cc`--```cpp-{{#include ../examples/threads.cc}}-```diff --git a/docs/examples-cpp-serialize.md b/docs/examples-cpp-serialize.mddeleted file mode 100644index 57ecfad80d..0000000000--- a/docs/examples-cpp-serialize.md+++ /dev/null@@ -1,14 +0,0 @@-# Serializing and Deserializing Modules--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/serialize.cc--This example shows how to serialize a compiled module to disk and later deserialize it to skip compilation on the critical path.--## `serialize.cc`--```cpp-{{#include ../examples/serialize.cc}}-```diff --git a/docs/examples-cpp-wasi.md b/docs/examples-cpp-wasi.mddeleted file mode 100644index e889b833bf..0000000000--- a/docs/examples-cpp-wasi.md+++ /dev/null@@ -1,21 +0,0 @@-# WASI--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/wasip1/main.cc--This example shows off how to instantiate a wasm module using WASI imports.--## Wasm Source code--```rust,ignore-{{#include ../examples/wasm/wasi.rs}}-```---## `wasi.cc`--```c-{{#include ../examples/wasip1/main.cc}}-```diff --git a/docs/examples-externref.md b/docs/examples-externref.mdnew file mode 100644index 0000000000..a7466f6189--- /dev/null+++ b/docs/examples-externref.md@@ -0,0 +1,36 @@+# Working with `externref`++You can also browse this source code online and clone the wasmtime+repository to run the example locally:++* [Rust](https://github.com/bytecodealliance/wasmtime/blob/main/examples/externref.rs)+* [C](https://github.com/bytecodealliance/wasmtime/blob/main/examples/externref.c)+* [C++](https://github.com/bytecodealliance/wasmtime/blob/main/examples/externref.cc)++[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/externref.rs++This example shows how to pass opaque host references into and out of WebAssembly using `externref`.++## Wasm Source++```wat+{{#include ../examples/externref.wat}}+```++## Host Source++<!-- langtabs-start -->++```rust+{{#include ../examples/externref.rs}}+```++```c+{{#include ../examples/externref.c}}+```++```cpp+{{#include ../examples/externref.cc}}+```++<!-- langtabs-end -->diff --git a/docs/examples-gcd.md b/docs/examples-gcd.mdnew file mode 100644index 0000000000..4d9b9c2c51--- /dev/null+++ b/docs/examples-gcd.md@@ -0,0 +1,35 @@+# Calculating the GCD++You can also browse this source code online and clone the wasmtime+repository to run the example locally:++* [Rust](https://github.com/bytecodealliance/wasmtime/blob/main/examples/gcd.rs)+* [C](https://github.com/bytecodealliance/wasmtime/blob/main/examples/gcd.c)+* [C++](https://github.com/bytecodealliance/wasmtime/blob/main/examples/gcd.cc)++This example shows off how run a wasm program which calculates the GCD of two+numbers.++## Wasm Source++```wat+{{#include ../examples/gcd.wat}}+```++## Host Source++<!-- langtabs-start -->++```rust+{{#include ../examples/gcd.rs}}+```++```c+{{#include ../examples/gcd.c}}+```++```cpp+{{#include ../examples/gcd.cc}}+```++<!-- langtabs-end -->diff --git a/docs/examples-hello-world.md b/docs/examples-hello-world.mdnew file mode 100644index 0000000000..0eb9338ec9--- /dev/null+++ b/docs/examples-hello-world.md@@ -0,0 +1,33 @@+# Hello, world!++You can also browse this source code online and clone the wasmtime+repository to run the example locally:++* [Rust](https://github.com/bytecodealliance/wasmtime/blob/main/examples/hello.rs)+* [C](https://github.com/bytecodealliance/wasmtime/blob/main/examples/hello.c)+* [C++](https://github.com/bytecodealliance/wasmtime/blob/main/examples/hello.cc)++This example shows off how to instantiate a simple wasm module and interact with+it.++## Wasm Source++```wat+{{#include ../examples/hello.wat}}+```++## Host Source++<!-- langtabs-start -->+```rust+{{#include ../examples/hello.rs}}+```++```c+{{#include ../examples/hello.c}}+```++```cpp+{{#include ../examples/hello.cc}}+```+<!-- langtabs-end -->diff --git a/docs/examples-linking.md b/docs/examples-linking.mdnew file mode 100644index 0000000000..5b3f1bc5a7--- /dev/null+++ b/docs/examples-linking.md@@ -0,0 +1,43 @@+# Linking modules++You can also browse this source code online and clone the wasmtime+repository to run the example locally:++* [Rust](https://github.com/bytecodealliance/wasmtime/blob/main/examples/linking.rs)+* [C](https://github.com/bytecodealliance/wasmtime/blob/main/examples/linking.c)+* [C++](https://github.com/bytecodealliance/wasmtime/blob/main/examples/linking.cc)++This example shows off how to compile and instantiate modules which link+together. Be sure to read the API documentation for [`Linker`] as well.++[`Linker`]: https://docs.rs/wasmtime/0.26.0/wasmtime/struct.Linker.html++## Wasm: `linking1.wat`++```wat+{{#include ../examples/linking1.wat}}+```++## Wasm: `linking2.wat`++```wat+{{#include ../examples/linking2.wat}}+```++## Host Source++<!-- langtabs-start -->++```rust+{{#include ../examples/linking.rs}}+```++```c+{{#include ../examples/linking.c}}+```++```cpp+{{#include ../examples/linking.cc}}+```++<!-- langtabs-end -->diff --git a/docs/examples-memory.md b/docs/examples-memory.mdnew file mode 100644index 0000000000..99f619c6ee--- /dev/null+++ b/docs/examples-memory.md@@ -0,0 +1,37 @@+# Using linear memory++You can also browse this source code online and clone the wasmtime+repository to run the example locally:++* [Rust](https://github.com/bytecodealliance/wasmtime/blob/main/examples/memory.rs)+* [C](https://github.com/bytecodealliance/wasmtime/blob/main/examples/memory.c)+* [C++](https://github.com/bytecodealliance/wasmtime/blob/main/examples/memory.cc)++This example shows off how to interact with wasm memory in a module. Be sure to+read the documentation for [`Memory`] as well.++[`Memory`]: https://bytecodealliance.github.io/wasmtime/api/wasmtime/struct.Memory.html++## Wasm Source++```wat+{{#include ../examples/memory.wat}}+```++## Host Source++<!-- langtabs-start -->++```rust+{{#include ../examples/memory.rs}}+```++```c+{{#include ../examples/memory.c}}+```++```cpp+{{#include ../examples/memory.cc}}+```++<!-- langtabs-end -->diff --git a/docs/examples-rust-mpk.md b/docs/examples-mpk.mdsimilarity index 85%rename from docs/examples-rust-mpk.mdrename to docs/examples-mpk.mdindex 9f0764c12e..499fb94ecf 100644--- a/docs/examples-rust-mpk.md+++ b/docs/examples-mpk.md@@ -7,8 +7,12 @@ repository to run the example locally.This example demonstrates using the [Memory Protection Keys](https://www.man7.org/linux/man-pages/man7/pkeys.7.html) feature on supported platforms.-## `mpk.rs`+## Host Source-```rust,ignore+<!-- langtabs-start -->++```rust{{#include ../examples/mpk.rs}}```++<!-- langtabs-end -->diff --git a/docs/examples-multi-value.md b/docs/examples-multi-value.mdnew file mode 100644index 0000000000..f1f2526d10--- /dev/null+++ b/docs/examples-multi-value.md@@ -0,0 +1,35 @@+# Using multi-value++You can also browse this source code online and clone the wasmtime+repository to run the example locally:++* [Rust](https://github.com/bytecodealliance/wasmtime/blob/main/examples/multi.rs)+* [C](https://github.com/bytecodealliance/wasmtime/blob/main/examples/multi.c)+* [C++](https://github.com/bytecodealliance/wasmtime/blob/main/examples/multi.cc)++This example shows off how to interact with a wasm module that uses multi-value+exports and imports.++## Wasm Source++```wat+{{#include ../examples/multi.wat}}+```++## Host Source++<!-- langtabs-start -->++```rust+{{#include ../examples/multi.rs}}+```++```c+{{#include ../examples/multi.c}}+```++```cpp+{{#include ../examples/multi.cc}}+```++<!-- langtabs-end -->diff --git a/docs/examples-multimemory.md b/docs/examples-multimemory.mdnew file mode 100644index 0000000000..5f06205f5c--- /dev/null+++ b/docs/examples-multimemory.md@@ -0,0 +1,34 @@+# Working with Multiple Memories++You can also browse this source code online and clone the wasmtime+repository to run the example locally:++* [Rust](https://github.com/bytecodealliance/wasmtime/blob/main/examples/multimemory.rs)+* [C](https://github.com/bytecodealliance/wasmtime/blob/main/examples/multimemory.c)+* [C++](https://github.com/bytecodealliance/wasmtime/blob/main/examples/multimemory.cc)++This example demonstrates using the multiple memories proposal, instantiating a module that imports and exports more than one linear memory.++## Wasm Source++```wat+{{#include ../examples/multimemory.wat}}+```++## Host Source++<!-- langtabs-start -->++```rust+{{#include ../examples/multimemory.rs}}+```++```c+{{#include ../examples/multimemory.c}}+```++```cpp+{{#include ../examples/multimemory.cc}}+```++<!-- langtabs-end -->diff --git a/docs/examples-multithreaded-embedding.md b/docs/examples-multithreaded-embedding.mdnew file mode 100644index 0000000000..fb534f6275--- /dev/null+++ b/docs/examples-multithreaded-embedding.md@@ -0,0 +1,34 @@+# Multithreaded Embedding++You can also browse this source code online and clone the wasmtime+repository to run the example locally:++* [Rust](https://github.com/bytecodealliance/wasmtime/blob/main/examples/threads.rs)+* [C](https://github.com/bytecodealliance/wasmtime/blob/main/examples/threads.c)+* [C++](https://github.com/bytecodealliance/wasmtime/blob/main/examples/threads.cc)++This example demonstrates using Wasmtime in multithreaded runtimes.++## Wasm Source++```wat+{{#include ../examples/threads.wat}}+```++## Host Source++<!-- langtabs-start -->++```rust+{{#include ../examples/threads.rs}}+```++```c+{{#include ../examples/threads.c}}+```++```cpp+{{#include ../examples/threads.cc}}+```++<!-- langtabs-end -->diff --git a/docs/examples-rust-anyref.md b/docs/examples-rust-anyref.mddeleted file mode 100644index b28812aba3..0000000000--- a/docs/examples-rust-anyref.md+++ /dev/null@@ -1,20 +0,0 @@-# Working with `anyref`--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/anyref.rs--This example demonstrates using `anyref` values.--## `anyref.wat`--```wat-{{#include ../examples/anyref.wat}}-```--## `anyref.rs`--```rust,ignore-{{#include ../examples/anyref.rs}}-```diff --git a/docs/examples-rust-debugging.md b/docs/examples-rust-debugging.mddeleted file mode 100644index 3ef9564139..0000000000--- a/docs/examples-rust-debugging.md+++ /dev/null@@ -1,15 +0,0 @@-# Debugging--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/fib-debug/main.rs--This example shows off how to set up a module for dynamic runtime debugging via-a native debugger like GDB or LLDB.--## `main.rs`--```rust,ignore-{{#include ../examples/fib-debug/main.rs}}-```diff --git a/docs/examples-rust-externref.md b/docs/examples-rust-externref.mddeleted file mode 100644index 99e336d1f2..0000000000--- a/docs/examples-rust-externref.md+++ /dev/null@@ -1,20 +0,0 @@-# Working with `externref`--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/externref.rs--This example shows how to pass opaque host references into and out of WebAssembly using `externref`.--## `externref.wat`--```wat-{{#include ../examples/externref.wat}}-```--## `externref.rs`--```rust,ignore-{{#include ../examples/externref.rs}}-```diff --git a/docs/examples-rust-gcd.md b/docs/examples-rust-gcd.mddeleted file mode 100644index bbc9c608ad..0000000000--- a/docs/examples-rust-gcd.md+++ /dev/null@@ -1,22 +0,0 @@-# Calculating the GCD--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/gcd.rs--This example shows off how run a wasm program which calculates the GCD of two-numbers.--## `gcd.wat`--```wat-{{#include ../examples/gcd.wat}}-```---## `gcd.rs`--```rust,ignore-{{#include ../examples/gcd.rs}}-```diff --git a/docs/examples-rust-hello-world.md b/docs/examples-rust-hello-world.mddeleted file mode 100644index 4ab24ceb3d..0000000000--- a/docs/examples-rust-hello-world.md+++ /dev/null@@ -1,25 +0,0 @@-# Hello, world!--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/hello.rs--This example shows off how to instantiate a simple wasm module and interact with-it. For more information about the types used here be sure to review the [core-concepts of the `wasmtime`-API](https://docs.rs/wasmtime/*/wasmtime/#core-concepts) as well as the general-[API documentation](https://docs.rs/wasmtime).--## `hello.wat`--```wat-{{#include ../examples/hello.wat}}-```---## `hello.rs`--```rust,ignore-{{#include ../examples/hello.rs}}-```diff --git a/docs/examples-rust-linking.md b/docs/examples-rust-linking.mddeleted file mode 100644index e176aec4e1..0000000000--- a/docs/examples-rust-linking.md+++ /dev/null@@ -1,29 +0,0 @@-# Linking modules--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/linking.rs--This example shows off how to compile and instantiate modules which link-together. Be sure to read the API documentation for [`Linker`] as well.--[`Linker`]: https://docs.rs/wasmtime/0.26.0/wasmtime/struct.Linker.html--## `linking1.wat`--```wat-{{#include ../examples/linking1.wat}}-```--## `linking2.wat`--```wat-{{#include ../examples/linking2.wat}}-```--## `linking.rs`--```rust,ignore-{{#include ../examples/linking.rs}}-```diff --git a/docs/examples-rust-memory.md b/docs/examples-rust-memory.mddeleted file mode 100644index 30c5ae7bc8..0000000000--- a/docs/examples-rust-memory.md+++ /dev/null@@ -1,24 +0,0 @@-# Using linear memory--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/memory.rs--This example shows off how to interact with wasm memory in a module. Be sure to-read the documentation for [`Memory`] as well.--[`Memory`]: https://bytecodealliance.github.io/wasmtime/api/wasmtime/struct.Memory.html--## `memory.wat`--```wat-{{#include ../examples/memory.wat}}-```---## `memory.rs`--```rust,ignore-{{#include ../examples/memory.rs}}-```diff --git a/docs/examples-rust-multi-value.md b/docs/examples-rust-multi-value.mddeleted file mode 100644index af42117c5f..0000000000--- a/docs/examples-rust-multi-value.md+++ /dev/null@@ -1,22 +0,0 @@-# Using multi-value--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/multi.rs--This example shows off how to interact with a wasm module that uses multi-value-exports and imports.--## `multi.wat`--```wat-{{#include ../examples/multi.wat}}-```---## `multi.rs`--```rust,ignore-{{#include ../examples/multi.rs}}-```diff --git a/docs/examples-rust-multimemory.md b/docs/examples-rust-multimemory.mddeleted file mode 100644index f22dd7a3d0..0000000000--- a/docs/examples-rust-multimemory.md+++ /dev/null@@ -1,20 +0,0 @@-# Working with Multiple Memories--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/multimemory.rs--This example demonstrates using the multiple memories proposal, instantiating a module that imports and exports more than one linear memory.--## `multimemory.wat`--```wat-{{#include ../examples/multimemory.wat}}-```--## `multimemory.rs`--```rust,ignore-{{#include ../examples/multimemory.rs}}-```diff --git a/docs/examples-rust-multithreaded-embedding.md b/docs/examples-rust-multithreaded-embedding.mddeleted file mode 100644index 86ba29f3f3..0000000000--- a/docs/examples-rust-multithreaded-embedding.md+++ /dev/null@@ -1,20 +0,0 @@-# Multithreaded Embedding--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/threads.rs--This example demonstrates using Wasmtime in multithreaded runtimes.--## `threads.wat`--```wat-{{#include ../examples/threads.wat}}-```--## `threads.rs`--```rust,ignore-{{#include ../examples/threads.rs}}-```diff --git a/docs/examples-rust-serialize.md b/docs/examples-rust-serialize.mddeleted file mode 100644index 9c11020284..0000000000--- a/docs/examples-rust-serialize.md+++ /dev/null@@ -1,14 +0,0 @@-# Serializing and Deserializing Modules--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/serialize.rs--This example shows how to compile a module once and serialize its compiled representation to disk and later deserialize it to skip compilation on the critical path. See also the [pre-compilation example](examples-pre-compiling-wasm.md) for ahead-of-time compilation.--## `serialize.rs`--```rust,ignore-{{#include ../examples/serialize.rs}}-```diff --git a/docs/examples-rust-wasip2.md b/docs/examples-rust-wasip2.mdindex 1a00fa623d..933fd4358e 100644--- a/docs/examples-rust-wasip2.md+++ b/docs/examples-rust-wasip2.md@@ -1,61 +1 @@# WASIp2--You can also [browse this source code online][code] and clone the wasmtime-repository to run the example locally.--[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/wasip2/main.rs--This example shows how to use the [`wasmtime-wasi`] crate to define WASI-functions within a [`Linker`] which can then be used to instantiate a-WebAssembly component.--[`wasmtime-wasi`]: https://crates.io/crates/wasmtime-wasi-[`Linker`]: https://docs.rs/wasmtime/*/wasmtime/struct.Linker.html--## WebAssembly Component Source Code--For this WASI example, this Hello World program is compiled to a WebAssembly component using the WASIp2 API.--`wasi.rs`-```rust-{{#include ../examples/wasm/wasi.rs}}-```--> Building instructions:-> 1. Have Rust installed-> 2. Add WASIp2 target if you haven't already: `rustup target add wasm32-wasip2`-> 3. `cargo build --target wasm32-wasip2`--Building this program generates `target/wasm32-wasip2/debug/wasi.wasm`, used below.--### Invoke the WASM component--This example shows adding and configuring the WASI imports to invoke the above WASM component.--`main.rs`-```rust,ignore-{{#include ../examples/wasip2/main.rs}}-```--### Async example--This [async example code][code2] shows how to use the [wasmtime-wasi][`wasmtime-wasi`] crate to-execute the same WASIp2 component from the example above. This example requires the `wasmtime` crate `async` feature to be enabled.--This does not require any change to the WASIp2 component, it's just the WASIp2 API host functions which are implemented to be async. See [wasmtime async support](https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.async_support).--[code2]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/wasip2-async/main.rs-[`wasmtime-wasi`]: https://docs.rs/wasmtime-wasi/*/wasmtime_wasi/preview2/index.html--```rust,ignore-{{#include ../examples/wasip2-async/main.rs}}-```--You can also [browse this source code online][code2] and clone the wasmtime-repository to run the example locally.--## Beyond Basics--Please see these references:-* The [book](https://component-model.bytecodealliance.org) for understanding the component model of WASIp2.-* [Bindgen Examples](https://docs.rs/wasmtime/latest/wasmtime/component/bindgen_examples/index.html) for implementing WASIp2 hosts and guests.\ No newline at end of filediff --git a/docs/examples-serialize.md b/docs/examples-serialize.mdnew file mode 100644index 0000000000..30e9aea3e9--- /dev/null+++ b/docs/examples-serialize.md@@ -0,0 +1,28 @@+# Serializing and Deserializing Modules++You can also browse this source code online and clone the wasmtime+repository to run the example locally:++* [Rust](https://github.com/bytecodealliance/wasmtime/blob/main/examples/serialize.rs)+* [C](https://github.com/bytecodealliance/wasmtime/blob/main/examples/serialize.c)+* [C++](https://github.com/bytecodealliance/wasmtime/blob/main/examples/serialize.cc)++This example shows how to compile a module once and serialize its compiled representation to disk and later deserialize it to skip compilation on the critical path. See also the [pre-compilation example](examples-pre-compiling-wasm.md) for ahead-of-time compilation.++## Host Source++<!-- langtabs-start -->++```rust+{{#include ../examples/serialize.rs}}+```++```c+{{#include ../examples/serialize.c}}+```++```cpp+{{#include ../examples/serialize.cc}}+```++<!-- langtabs-end -->diff --git a/docs/examples-wasip1.md b/docs/examples-wasip1.mdnew file mode 100644index 0000000000..232b32e520--- /dev/null+++ b/docs/examples-wasip1.md@@ -0,0 +1,34 @@+# WASI++You can also browse this source code online and clone the wasmtime+repository to run the example locally:++* [Rust](https://github.com/bytecodealliance/wasmtime/blob/main/examples/wasip1/main.rs)+* [C](https://github.com/bytecodealliance/wasmtime/blob/main/examples/wasip1/main.c)+* [C++](https://github.com/bytecodealliance/wasmtime/blob/main/examples/wasip1/main.cc)++This example shows off how to instantiate a wasm module using WASI imports.++## Wasm Source++```rust,ignore+{{#include ../examples/wasm/wasi.rs}}+```++## Host Source++<!-- langtabs-start -->++```rust+{{#include ../examples/wasip1/main.rs}}+```++```c+{{#include ../examples/wasip1/main.c}}+```++```cpp+{{#include ../examples/wasip1/main.cc}}+```++<!-- langtabs-end -->diff --git a/docs/examples-wasip2.md b/docs/examples-wasip2.mdnew file mode 100644index 0000000000..be67ff069a--- /dev/null+++ b/docs/examples-wasip2.md@@ -0,0 +1,68 @@+# WASIp2++You can also [browse this source code online][code] and clone the wasmtime+repository to run the example locally.++[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/wasip2/main.rs++This example shows how to use the [`wasmtime-wasi`] crate to define WASI+functions within a [`Linker`] which can then be used to instantiate a+WebAssembly component.++[`wasmtime-wasi`]: https://crates.io/crates/wasmtime-wasi+[`Linker`]: https://docs.rs/wasmtime/*/wasmtime/struct.Linker.html++## WebAssembly Component Source Code++For this WASI example, this Hello World program is compiled to a WebAssembly component using the WASIp2 API.++`wasi.rs`+```rust+{{#include ../examples/wasm/wasi.rs}}+```++> Building instructions:+> 1. Have Rust installed+> 2. Add WASIp2 target if you haven't already: `rustup target add wasm32-wasip2`+> 3. `cargo build --target wasm32-wasip2`++Building this program generates `target/wasm32-wasip2/debug/wasi.wasm`, used below.++### Invoke the WASM component++This example shows adding and configuring the WASI imports to invoke the above WASM component.++<!-- langtabs-start -->++```rust+{{#include ../examples/wasip2/main.rs}}+```++<!-- langtabs-end -->++### Async example++This [async example code][code2] shows how to use the [wasmtime-wasi][`wasmtime-wasi`] crate to+execute the same WASIp2 component from the example above. This example requires the `wasmtime` crate `async` feature to be enabled.++This does not require any change to the WASIp2 component, it's just the WASIp2 API host functions which are implemented to be async. See [wasmtime async support](https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.async_support).++[code2]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/wasip2-async/main.rs+[`wasmtime-wasi`]: https://docs.rs/wasmtime-wasi/*/wasmtime_wasi/preview2/index.html++<!-- langtabs-start -->++```rust+{{#include ../examples/wasip2-async/main.rs}}+```++<!-- langtabs-end -->++You can also [browse this source code online][code2] and clone the wasmtime+repository to run the example locally.++## Beyond Basics++Please see these references:+* The [book](https://component-model.bytecodealliance.org) for understanding the component model of WASIp2.+* [Bindgen Examples](https://docs.rs/wasmtime/latest/wasmtime/component/bindgen_examples/index.html) for implementing WASIp2 hosts and guests.diff --git a/docs/examples.md b/docs/examples.mddeleted file mode 100644index 1ab9078d16..0000000000--- a/docs/examples.md+++ /dev/null@@ -1,4 +0,0 @@-# Further Examples--The examples contained in this section explain how to use Wasmtime in several-common scenarios.diff --git a/docs/js/langtabs.js b/docs/js/langtabs.jsnew file mode 100644index 0000000000..8c76c79e86--- /dev/null+++ b/docs/js/langtabs.js@@ -0,0 +1,77 @@+(function loadDeviconCSS() {+ const link = document.createElement('link');+ link.rel = 'stylesheet';+ link.href = 'https://cdn.jsdelivr.net/gh/devicons/[email protected]/devicon.min.css';+ document.head.appendChild(link);+})();++document.addEventListener('DOMContentLoaded', function() {+ initLangTabs();++ // Listen for theme changes to re-style tabs+ const observer = new MutationObserver(function(mutations) {+ mutations.forEach(function(mutation) {+ if (mutation.attributeName === 'class' && mutation.target.nodeName === 'HTML') {+ setTimeout(initLangTabs, 50);+ }+ });+ });++ observer.observe(document.documentElement, {+ attributes: true+ });++ // Also handle theme changes when page hash changes (mdbook sometimes updates theme this way)+ window.addEventListener('hashchange', function() {+ setTimeout(initLangTabs, 100);+ });++ // Handle page navigation+ window.addEventListener('load', function() {+ setTimeout(initLangTabs, 100);+ });+});++function initLangTabs() {+ const langTabsContainers = document.querySelectorAll('.langtabs');++ langTabsContainers.forEach(function(container) {+ const tabButtons = container.querySelectorAll('.langtabs-tab');++ tabButtons.forEach(function(button) {+ button.removeEventListener('click', handleTabClick);+ button.addEventListener('click', handleTabClick);+ });++ // If no tab active select first+ if (!container.querySelector('.langtabs-tab.active')) {+ const firstButton = tabButtons[0];+ if (firstButton) {+ firstButton.click();+ }+ }+ });+}++function handleTabClick() {+ const container = this.closest('.langtabs');+ const lang = this.getAttribute('data-lang');++ // Deactivate all tabs in this container+ const tabButtons = container.querySelectorAll('.langtabs-tab');+ const tabContents = container.querySelectorAll('.langtabs-code');++ tabButtons.forEach(function(btn) {+ btn.classList.remove('active');+ });+ tabContents.forEach(function(content) {+ content.classList.remove('active');+ });++ // Activate selected tab+ this.classList.add('active');+ const activeContent = container.querySelector(`.langtabs-code[data-lang="${lang}"]`);+ if (activeContent) {+ activeContent.classList.add('active');+ }+}\ No newline at end of filediff --git a/docs/lang-bash.md b/docs/lang-bash.mddeleted file mode 100644index bc1f8f8294..0000000000--- a/docs/lang-bash.md+++ /dev/null@@ -1,42 +0,0 @@-# Using WebAssembly from Bash--## Getting started and simple example--First up you'll want to start a new module:--```text-$ mkdir -p gcd-bash-$ cd gcd-bash-$ touch gcd.wat gcd.sh-```--Next, copy this example WebAssembly text module into your project. It exports a function for calculating the greatest common denominator of two numbers.--## `gcd.wat`--```wat-{{#include ../examples/gcd.wat}}-```--Create a bash script that will invoke GCD three times.--## `gcd.sh`--```bash-#!/bin/bash--function gcd() {- # Cast to number; default = 0- local x=$(($1))- local y=$(($2))- # Invoke GCD from module; suppress stderr- local result=$(wasmtime --invoke gcd examples/gcd.wat $x $y 2>/dev/null)- echo "$result"-}--# main-for num in "27 6" "6 27" "42 12"; do- set -- $num- echo "gcd($1, $2) = $(gcd "$1" "$2")"-done-```diff --git a/docs/lang-c.md b/docs/lang-c.mddeleted file mode 100644index 5db21c9277..0000000000--- a/docs/lang-c.md+++ /dev/null@@ -1,6 +0,0 @@-# Embedding in C--This section is intended to showcase the C embedding API for Wasmtime. Full-reference documentation for the C API [can be found online][online].--[online]: https://bytecodealliance.github.io/wasmtime/c-api/diff --git a/docs/lang-cpp.md b/docs/lang-cpp.mddeleted file mode 100644index 65138c8e1b..0000000000--- a/docs/lang-cpp.md+++ /dev/null@@ -1,3 +0,0 @@-# Using WebAssembly from C++--The examples in this chapter show how to embed Wasmtime using the C++ API to execute wasm programs with various features. Consult the [API docs](https://docs.wasmtime.dev/c-api/) for the full C++ API.diff --git a/docs/lang-dotnet.md b/docs/lang-dotnet.mddeleted file mode 100644index 6e23544de4..0000000000--- a/docs/lang-dotnet.md+++ /dev/null@@ -1,87 +0,0 @@-# Using WebAssembly from .NET--The [Wasmtime](https://www.nuget.org/packages/Wasmtime) NuGet package can be used to-programmatically interact with WebAssembly modules.--This guide will go over adding Wasmtime to your project and demonstrate a simple-example of using a WebAssembly module from C#.--Make sure you have a [.NET Core SDK 3.0 SDK or later](https://dotnet.microsoft.com/download)-installed before we get started!--## Getting started and simple example--Start by creating a new .NET Core console project:--```text-$ mkdir gcd-$ cd gcd-$ dotnet new console-```--Next, add a reference to the Wasmtime NuGet package to your project:---```text-$ dotnet add package --version 0.19.0-preview1 wasmtime-```--Copy this example WebAssembly text module into your project directory as `gcd.wat`.--```wat-{{#include ../examples/gcd.wat}}-```--This module exports a function for calculating the greatest common denominator of two numbers.--Replace the code in `Program.cs` with the following:--```c#-using System;-using Wasmtime;--namespace Tutorial-{- class Program- {- static void Main(string[] args)- {- using var engine = new Engine();- using var module = Module.FromTextFile(engine, "gcd.wat");-- using var host = new Host(engine);- using dynamic instance = host.Instantiate(module);-- Console.WriteLine($"gcd(27, 6) = {instance.gcd(27, 6)}");- }- }-}-```--Run the .NET core program:--```text-$ dotnet run-```--The program should output:--```text-gcd(27, 6) = 3-```---If this is the output you see, congrats! You've successfully ran your first-WebAssembly code in .NET!--## More examples and contributing--The [.NET embedding of Wasmtime repository](https://github.com/bytecodealliance/wasmtime-dotnet)-contains the source code for the Wasmtime NuGet package.--The repository also has more [examples](https://github.com/bytecodealliance/wasmtime-dotnet/tree/main/examples)-as well.--Feel free to browse those, but if you find anything missing don't-hesitate to [open an issue](https://github.com/bytecodealliance/wasmtime-dotnet/issues/new) and let us-know if you have any questions!diff --git a/docs/lang-elixir.md b/docs/lang-elixir.mddeleted file mode 100644index d961f2ede5..0000000000--- a/docs/lang-elixir.md+++ /dev/null@@ -1,43 +0,0 @@-# Using WebAssembly from Elixir--Wasmtime [is available on Hex](https://hex.pm/packages/wasmex) and can-be used programmatically to interact with Wasm modules. This guide will go over-installing the wasmex package and running a simple Wasm module from Elixir.--## Getting started and simple example--First, copy this example WebAssembly text module into the current directory. It exports-a function for calculating the greatest common denominator of two numbers.--```wat-{{#include ../examples/gcd.wat}}-```--The library has a Rust-based native extension, but thanks to `rustler_precompiled`, you-should not have to compile anything. It'll just work!--This WAT file can be executed in `iex`:--```elixir-Mix.install([:wasmex])-bytes = File.read!("gcd.wat")-{:ok, pid} = Wasmex.start_link(%{bytes: bytes}) # starts a GenServer running a WASM instance-Wasmex.call_function(pid, "gcd", [27, 6])-```--The last command should output:--```elixir-iex(5)> Wasmex.call_function(pid, "gcd", [27, 6])-{:ok, [3]}-```--If this is the output you see, congrats! You've successfully ran your first-WebAssembly code in Elixir!--## More examples and contributing--To learn more, check out an [another example](https://github.com/tessi/wasmex#example)-and the [API documentation](https://hexdocs.pm/wasmex/Wasmex.html).-If you have any questions, do not hesitate to open an issue on the-[GitHub repository](https://github.com/tessi/wasmex).diff --git a/docs/lang-go.md b/docs/lang-go.mddeleted file mode 100644index e82a8c4270..0000000000--- a/docs/lang-go.md+++ /dev/null@@ -1,78 +0,0 @@-# Using WebAssembly from Go--Wasmtime [is available as a Go-Module](https://pkg.go.dev/github.com/bytecodealliance/wasmtime-go). This guide-will go over adding Wasmtime to your project, and some provided examples of what-can be done with WebAssembly modules.--Make sure you're using Go 1.12 or later with modules support.--## Getting started and simple example--First up you'll want to start a new module:--```console-mkdir hello-wasm-cd hello-wasm-go mod init hello-wasm-go get github.com/bytecodealliance/wasmtime-go-```--Next, copy this example WebAssembly text module into your project. It exports a-function for calculating the greatest common denominator of two numbers.--```wat-{{#include ../examples/gcd.wat}}-```--Next, we can write our code in `main.go` which reads this file and runs it:--```go-package main--import (- "fmt"- "github.com/bytecodealliance/wasmtime-go"-)--func main() {- engine := wasmtime.NewEngine()- store := wasmtime.NewStore(engine)- module, err := wasmtime.NewModuleFromFile(engine, "gcd.wat")- check(err)- instance, err := wasmtime.NewInstance(store, module, []wasmtime.AsExtern{})- check(err)-- gcd := instance.GetExport(store, "gcd").Func()- val, err := gcd.Call(store, 6, 27)- check(err)- fmt.Printf("gcd(6, 27) = %d\n", val.(int32))-}--func check(err error) {- if err != nil {- panic(err)- }-}-```--And finally we can build and run it:--```console-$ go run main.go-gcd(6, 27) = 3-```--If this is the output you see, congrats! You've successfully ran your first-WebAssembly code in Go!--## More examples and contributing--The `wasmtime` Go package [lives in its own-repository](https://github.com/bytecodealliance/wasmtime-go) and has a [number-of other more advanced-examples](https://pkg.go.dev/github.com/bytecodealliance/wasmtime-go?tab=doc#pkg-examples)-as well. Feel free to browse those, but if you find anything missing don't-hesitate to [open an-issue](https://github.com/bytecodealliance/wasmtime-go/issues/new) and let us-know if you have any questions!diff --git a/docs/lang-python.md b/docs/lang-python.mddeleted file mode 100644index baef9de085..0000000000--- a/docs/lang-python.md+++ /dev/null@@ -1,76 +0,0 @@-# Using WebAssembly from Python--Wasmtime [is available on PyPI](https://pypi.org/project/wasmtime/) and can be-used programmatically or as a python module loader, which allows almost any-WebAssembly module to be used as a python module. This guide will go over adding-Wasmtime to your project, and some provided examples of what can be done with-WebAssembly modules.--Make sure you've got Python 3.5 or newer installed locally, and we can get-started!--## Getting started and simple example--First, copy this example WebAssembly text module into your project with the filename `gcd.wat`. It exports a-function for calculating the greatest common denominator of two numbers.--```wat-{{#include ../examples/gcd.wat}}-```--Next, install the [Wasmtime package](https://pypi.org/project/wasmtime/) from-PyPi. It can be installed as a dependency through Pip or related tools such as-Pipenv.--```bash-pip install wasmtime-```--Or--```bash-pipenv install wasmtime-```--After you have Wasmtime installed and you've imported `wasmtime`, you can import-WebAssembly modules in your project like any other python module.--```python-import wasmtime.loader-import gcd--print("gcd(27, 6) =", gcd.gcd(27, 6))-```--This script should output--```bash-gcd(27, 6) = 3-```--If this is the output you see, congrats! You've successfully ran your first-WebAssembly code in python!--You can also alternatively use the [`wasmtime` package's-API](https://bytecodealliance.github.io/wasmtime-py/):--```python-from wasmtime import Store, Module, Instance--store = Store()-module = Module.from_file(store.engine, 'gcd.wat')-instance = Instance(store, module, [])-gcd = instance.exports(store)['gcd']-print("gcd(27, 6) = %d" % gcd(store, 27, 6))-```--## More examples and contributing--The `wasmtime` Python package currently [lives in its own repository outside of-`wasmtime`](https://github.com/bytecodealliance/wasmtime-py) and has a [number-of other more advanced-examples](https://github.com/bytecodealliance/wasmtime-py/tree/main/examples)-as well. Feel free to browse those, but if you find anything missing don't-hesitate to [open an-issue](https://github.com/bytecodealliance/wasmtime-py/issues/new) and let us-know if you have any questions!diff --git a/docs/lang-ruby.md b/docs/lang-ruby.mddeleted file mode 100644index 61f81db041..0000000000--- a/docs/lang-ruby.md+++ /dev/null@@ -1,63 +0,0 @@-# Using WebAssembly from Ruby--Wasmtime [is available on RubyGems](https://rubygems.org/gems/wasmtime) and can-be used programmatically to interact with Wasm modules. This guide will go over-installing the Wasmtime gem and running a simple Wasm module from Ruby.--Make sure you've got Ruby 3.0 or newer installed locally, and we can get-started!--## Getting started and simple example--First, copy this example WebAssembly text module into your project. It exports-a function for calculating the greatest common divisor of two numbers.--```wat-{{#include ../examples/gcd.wat}}-```--Next, install the Wasmtime Ruby gems by either adding it your project's-`Gemfile`:--```bash-bundle add wasmtime-```--Or by using the `gem` command directly:--```bash-gem install wasmtime-```--The gem has a Rust-based native extension, but thanks to precompiled gems, you-should not have to compile anything. It'll just work!--Now that you have the Wasmtime gem installed, let's create a Ruby script to-execute the `gcd` module from before.--```ruby-require "wasmtime"--engine = Wasmtime::Engine.new-mod = Wasmtime::Module.from_file(engine, "gcd.wat")-store = Wasmtime::Store.new(engine)-instance = Wasmtime::Instance.new(store, mod)--puts "gcd(27, 6) = #{instance.invoke("gcd", 27, 6)}"-```--This script should output--```bash-gcd(27, 6) = 3-```--If this is the output you see, congrats! You've successfully ran your first-WebAssembly code in Ruby!--## More examples and contributing--To learn more, check out the [more advanced examples](https://github.com/bytecodealliance/wasmtime-rb/tree/main/examples)-and the [API documentation](https://bytecodealliance.github.io/wasmtime-rb/latest/).-If you have any questions, do not hesitate to open an issue on the-[GitHub repository](https://github.com/bytecodealliance/wasmtime-rb).diff --git a/docs/lang-rust.md b/docs/lang-rust.mddeleted file mode 100644index 1e62c0ef25..0000000000--- a/docs/lang-rust.md+++ /dev/null@@ -1,197 +0,0 @@-# Using WebAssembly from Rust--This document shows an example of how to embed Wasmtime using the [Rust-API][apidoc] to execute a simple wasm program. Be sure to also check out the-[full API documentation][apidoc] for a full listing of what the [`wasmtime`-crate][wasmtime] has to offer.--[apidoc]: https://bytecodealliance.github.io/wasmtime/api/wasmtime/-[wasmtime]: https://crates.io/crates/wasmtime--## Creating the WebAssembly to execute--We'll just assume that you've already got a wasm file on hand for the rest of-this tutorial. To make things simple we'll also just assume you've got a-`hello.wat` file which looks like this:--```wat-(module- (func (export "answer") (result i32)- i32.const 42- )-)-```--Here we're just exporting one function which returns an integer that we'll read-from Rust.--## Hello, World!--First up let's create a rust project--```console-cargo new --bin wasmtime_hello-cd wasmtime_hello-```--Next you'll want to add `hello.wat` to the root of your project.--We will be using the `wasmtime` crate to run the wasm file. Please execute the command `cargo add wasmtime` to use the latest version of the crate. The `dependencies` block in the `Cargo.toml` file will appear as follows:--```toml-[dependencies]-wasmtime = "19.0.0"-```--Next up let's write the code that we need to execute this wasm file. The-simplest version of this looks like so:--```rust,no_run-# extern crate wasmtime;-use std::error::Error;-use wasmtime::*;--fn main() -> Result<(), Box<dyn Error>> {- // An engine stores and configures global compilation settings like- // optimization level, enabled wasm features, etc.- let engine = Engine::default();--# if false {- // We start off by creating a `Module` which represents a compiled form- // of our input wasm module. In this case it'll be JIT-compiled after- // we parse the text format.- let module = Module::from_file(&engine, "hello.wat")?;-# }-# let module = Module::new(&engine, r#"(module (func (export "answer") (result i32) i32.const 42))"#)?;-- // A `Store` is what will own instances, functions, globals, etc. All wasm- // items are stored within a `Store`, and it's what we'll always be using to- // interact with the wasm world. Custom data can be stored in stores but for- // now we just use `()`.- let mut store = Store::new(&engine, ());-- // With a compiled `Module` we can then instantiate it, creating- // an `Instance` which we can actually poke at functions on.- let instance = Instance::new(&mut store, &module, &[])?;-- // The `Instance` gives us access to various exported functions and items,- // which we access here to pull out our `answer` exported function and- // run it.- let answer = instance.get_func(&mut store, "answer")- .expect("`answer` was not an exported function");-- // There's a few ways we can call the `answer` `Func` value. The easiest- // is to statically assert its signature with `typed` (in this case- // asserting it takes no arguments and returns one i32) and then call it.- let answer = answer.typed::<(), i32>(&store)?;-- // And finally we can call our function! Note that the error propagation- // with `?` is done to handle the case where the wasm function traps.- let result = answer.call(&mut store, ())?;- println!("Answer: {:?}", result);- Ok(())-}-```--We can build and execute our example with `cargo run`. Note that by depending on-`wasmtime` you're depending on a JIT compiler, so it may take a moment to build-all of its dependencies:--```shell-session-$ cargo run- Compiling ...- ...- Finished dev [unoptimized + debuginfo] target(s) in 42.32s- Running `wasmtime_hello/target/debug/wasmtime_hello`-Answer: 42-```--and there we go! We've now executed our first WebAssembly in `wasmtime` and-gotten the result back.--## Importing Host Functionality--What we've just seen is a pretty small example of how to call a wasm function-and take a look at the result. Most interesting wasm modules, however, are going-to import some functions to do something a bit more interesting. For that you'll-need to provide imported functions from Rust for wasm to call!--Let's take a look at a wasm module which imports a logging function as well as-some simple arithmetic from the environment.--```wat-(module- (import "" "log" (func $log (param i32)))- (import "" "double" (func $double (param i32) (result i32)))- (func (export "run")- i32.const 0- call $log- i32.const 1- call $log- i32.const 2- call $double- call $log- )-)-```--This wasm module will call our `"log"` import a few times and then also call the-`"double"` import. We can compile and instantiate this module with code that-looks like this:--```rust,no_run-# extern crate wasmtime;-use std::error::Error;-use wasmtime::*;--struct Log {- integers_logged: Vec<u32>,-}--fn main() -> Result<(), Box<dyn Error>> {- let engine = Engine::default();-# if false {- let module = Module::from_file(&engine, "hello.wat")?;-# }-# let module = Module::new(&engine, r#"(module (import "" "log" (func $log (param i32))) (import "" "double" (func $double (param i32) (result i32))) (func (export "run") i32.const 0 call $log i32.const 1 call $log i32.const 2 call $double call $log))"#)?;-- // For host-provided functions it's recommended to use a `Linker` which does- // name-based resolution of functions.- let mut linker = Linker::new(&engine);-- // First we create our simple "double" function which will only multiply its- // input by two and return it.- linker.func_wrap("", "double", |param: i32| param * 2)?;-- // Next we define a `log` function. Note that we're using a- // Wasmtime-provided `Caller` argument to access the state on the `Store`,- // which allows us to record the logged information.- linker.func_wrap("", "log", |mut caller: Caller<'_, Log>, param: u32| {- println!("log: {}", param);- caller.data_mut().integers_logged.push(param);- })?;-- // As above, instantiation always happens within a `Store`. This means to- // actually instantiate with our `Linker` we'll need to create a store. Note- // that we're also initializing the store with our custom data here too.- //- // Afterwards we use the `linker` to create the instance.- let data = Log { integers_logged: Vec::new() };- let mut store = Store::new(&engine, data);- let instance = linker.instantiate(&mut store, &module)?;-- // Like before, we can get the run function and execute it.- let run = instance.get_typed_func::<(), ()>(&mut store, "run")?;- run.call(&mut store, ())?;-- // We can also inspect what integers were logged:- println!("logged integers: {:?}", store.data().integers_logged);-- Ok(())-}-```--Note that there's a number of ways to define a `Func`, be sure to [consult its-documentation][`Func`] for other ways to create a host-defined function.--[`Func`]: https://bytecodealliance.github.io/wasmtime/api/wasmtime/struct.Func.htmldiff --git a/docs/lang.md b/docs/lang.mdindex be222bf6ea..40b357fe28 100644--- a/docs/lang.md+++ b/docs/lang.md@@ -2,13 +2,121 @@Wasmtime can be used as a library to embed WebAssembly execution supportwithin applications. Wasmtime is written in Rust, but bindings are available-through a C API for a number of other languages too:--* [Rust](lang-rust.md)-* [C](lang-c.md)-* [Python](lang-python.md)-* [.NET](lang-dotnet.md)-* [Go](lang-go.md)-* [Bash](lang-bash.md)-* [Ruby](lang-ruby.md)-* [Elixir](lang-elixir.md)+through a C API for a number of other languages too. This chapter has a number+of examples which come from the Wasmtime repository itself and showcase the+Rust, C, and C++ embedding APIs.++# Officially supported bindings++The following languages are all developed in the Wasmtime repository itself and+have tests/documentation in the main repository itself.++## Rust++Wasmtime is itself written in Rust and is available as the [`wasmtime`] crate on+crates.io. API reference documentation for Wasmtime can be found on+[docs.rs](https://docs.rs/wasmtime) and includes a number of examples throughout+the documentation.++[`wasmtime`]: https://crates.io/crates/wasmtime++## C++Wasmtime provides a C API through `libwasmtime.a`, for example. The C API is+developed/tested in the Wasmtime repository itself and is the main entrypoint of+all other language support for Wasmtime other than Rust. Note that the C API is+not always in perfect parity with the Rust API and can lag behind in terms of+features. This is not intentional, however, and with sufficient development+resources the two APIs will be kept in-sync.++Documentation for the C API can be found at+[docs.wasmtime.dev/c-api](https://docs.wasmtime.dev/c-api/). Documentation on+how to build the C API can be found in the [README of the C API]. Building the C+API uses CMake to orchestrate the build and Cargo under the hood to build the+Rust code.++The C API can also be installed through `*-c-api-*` [release artifacts].++[README of the C API]: https://github.com/bytecodealliance/wasmtime/blob/main/crates/c-api/README.md+[release artifacts]: github.com/bytecodealliance/wasmtime/releases/latest++## C++++Wasmtime supports C++ as a header-based library layered on top of the C API. The+C++ API header use the `*.hh` extension and are installed alongside the C API+meaning that if you install the C API you've got the C++ API as well. The C+++API is focused on automating resource management of the C API and providing an+easier-to-use API on top.++## Bash++Wasmtime is available in Bash through the [`wasmtime` CLI](./cli.md) executable+and its various subcommands. Source for the `wasmtime` executable is developed+in the same repository as Wasmtime itself. Installation of `wasmtime` can be+[found in this documentation](./cli-install.md).++# External bindings to Wasmtime++The following language bindings are all developed outside of the Wasmtime+repository. Consequently they are not officially supported and may have varying+levels of support and activity. Note that many of these bindings are in the+bytecodealliance GitHub organization but are still not tested/developed in-sync+with the main repository.++## Python++Python bindings for Wasmtime are developed in the [wasmtime-py+repository](https://github.com/bytecodealliance/wasmtime-py). These bindings are+built on the C API and developed externally from the main Wasmtime repository so+updates can lag behind the main repository sometimes in terms of release+schedule and features.++Python bindings are published to the+[`wasmtime`](https://pypi.org/project/wasmtime/) package on PyPI.++## Go++Go bindings for Wasmtime are developed in the [wasmtime-go+repository](https://github.com/bytecodealliance/wasmtime-go). These bindings are+built on the C API and developed externally from the main Wasmtime repository so+updates can lag behind the main repository sometimes in terms of release+schedule and features.++Documentation for the Go API bindings can be found [on+pkg.go.dev](https://pkg.go.dev/github.com/bytecodealliance/wasmtime-go), and be+sure to use the version-picker to pick the latest major version which tracks+Wasmtime's own major versions.++## .NET++The [Wasmtime](https://www.nuget.org/packages/Wasmtime) NuGet package can be+used to programmatically interact with WebAssembly modules and requires+[.NET Core SDK 3.0 SDK or later](https://dotnet.microsoft.com/download)+installed as well.++The [.NET embedding of Wasmtime+repository](https://github.com/bytecodealliance/wasmtime-dotnet) contains the+source code for the Wasmtime NuGet package and+the repository also has more+[examples](https://github.com/bytecodealliance/wasmtime-dotnet/tree/main/examples)+as well.++## Ruby++Wasmtime [is available on RubyGems](https://rubygems.org/gems/wasmtime) and can+be used programmatically to interact with Wasm modules. To learn more, check out+the [more advanced+examples](https://github.com/bytecodealliance/wasmtime-rb/tree/main/examples)+and the [API+documentation](https://bytecodealliance.github.io/wasmtime-rb/latest/). If you+have any questions, do not hesitate to open an issue on the [GitHub+repository](https://github.com/bytecodealliance/wasmtime-rb).++## Elixir++Wasmtime [is available on Hex](https://hex.pm/packages/wasmex) and can be used+programmatically to interact with Wasm modules. To learn more, check out an+[another example](https://github.com/tessi/wasmex#example) and the [API+documentation](https://hexdocs.pm/wasmex/Wasmex.html). If you have any+questions, do not hesitate to open an issue on the [GitHub+repository](https://github.com/tessi/wasmex).