A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Update documentation in examples (#13499)
Alex Crichton99767bf8ee12
diff --git a/examples/README.md b/examples/README.mdindex af3951760a..172cc4a2e2 100644--- a/examples/README.md+++ b/examples/README.md@@ -8,11 +8,11 @@ Most examples are available in Rust, C, and C++, using the `wasmtime` crate or t`*.wat` file which is the wasm input, or a Rust project in a `wasm` folder whichis the source code for the original wasm file.-Rust examples can be executed with `cargo run --example $name`. C and C++ examples can-be built with `mkdir build && cd build && cmake $name`, where for C `$name` is the-basename of the example, and for C++ it is `[basename]-cpp`. You can run-`cmake --build .` to build all examples or `cmake --build . --target wasmtime-$name`,-replacing the name as you wish.+Rust examples can be executed with `cargo run --example $name`. C and C++ examples+can be built with `cmake -B build -S examples` followed by `cmake --build build`+to build all examples, or `cmake --build build --target wasmtime-$name` to build+a single one, where for C `$name` is the basename of the example, and for C+++it is `[basename]-cpp`. The resulting executable is placed in `build/`.They can also be [built manually](https://docs.wasmtime.dev/c-api/).For more information see the examples themselves!diff --git a/examples/anyref.c b/examples/anyref.cindex e1897e6dfc..98036ac492 100644--- a/examples/anyref.c+++ b/examples/anyref.c@@ -1,10 +1,11 @@/*Example of using `anyref` values.-You can build using cmake:+You can build and run this example using cmake:-mkdir build && cd build && cmake .. && \- cmake --build . --target wasmtime-anyref+ cmake -B build -S examples+ cmake --build build --target wasmtime-anyref+ ./build/wasmtime-anyref*/#include <assert.h>diff --git a/examples/anyref.cc b/examples/anyref.ccindex 189dcdd704..b15d663f11 100644--- a/examples/anyref.cc+++ b/examples/anyref.cc@@ -1,14 +1,11 @@/*Example of using `anyref` values.-You can build the example using CMake:+You can build and run the example using CMake:-mkdir build && (cd build && cmake .. && \- cmake --build . --target wasmtime-anyref-cpp)--And then run it:--build/wasmtime-anyref-cpp+ cmake -B build -S examples+ cmake --build build --target wasmtime-anyref-cpp+ ./build/wasmtime-anyref-cpp*/#include <fstream>diff --git a/examples/async.cc b/examples/async.ccindex 0c11000553..8bf6c9bfbb 100644--- a/examples/async.cc+++ b/examples/async.cc@@ -16,9 +16,11 @@ You can compile and run this example on Linux with:Note that on Windows and macOS the command will be similar, but you'll needto tweak the `-lpthread` and such annotations.-You can also build using cmake:+You can also build and run this example using cmake:-mkdir build && cd build && cmake .. && cmake --build . --target wasmtime-async+ cmake -B build -S examples+ cmake --build build --target wasmtime-async+ ./build/wasmtime-async*/#include <array>diff --git a/examples/externref.c b/examples/externref.cindex 64f90c4ed0..6ff6e13bb5 100644--- a/examples/externref.c+++ b/examples/externref.c@@ -1,10 +1,11 @@/*Example of using `externref` values.-You can build using cmake:+You can build and run this example using cmake:-mkdir build && cd build && cmake .. && \- cmake --build . --target wasmtime-externref+ cmake -B build -S examples+ cmake --build build --target wasmtime-externref+ ./build/wasmtime-externref*/#include <assert.h>diff --git a/examples/fuel.c b/examples/fuel.cindex 1d7ad9c451..cc9680a2e5 100644--- a/examples/fuel.c+++ b/examples/fuel.c@@ -2,9 +2,11 @@Example of instantiating of the WebAssembly module and invoking its exportedfunction.-You can build using cmake:+You can build and run this example using cmake:-mkdir build && cd build && cmake .. && cmake --build . --target wasmtime-fuel+ cmake -B build -S examples+ cmake --build build --target wasmtime-fuel+ ./build/wasmtime-fuel*/#include <assert.h>diff --git a/examples/gcd.c b/examples/gcd.cindex 7f6b1b005b..77d3f05449 100644--- a/examples/gcd.c+++ b/examples/gcd.c@@ -2,9 +2,11 @@Example of instantiating of the WebAssembly module and invoking its exportedfunction.-You can build using cmake:+You can build and run this example using cmake:-mkdir build && cd build && cmake .. && cmake --build . --target wasmtime-gcd+ cmake -B build -S examples+ cmake --build build --target wasmtime-gcd+ ./build/wasmtime-gcd*/#include <assert.h>diff --git a/examples/hello.c b/examples/hello.cindex cc71630a04..62e1340a8d 100644--- a/examples/hello.c+++ b/examples/hello.c@@ -2,9 +2,11 @@Example of instantiating of the WebAssembly module and invoking its exportedfunction.-You can build using cmake:+You can build and run this example using cmake:-mkdir build && cd build && cmake .. && cmake --build . --target wasmtime-hello+ cmake -B build -S examples+ cmake --build build --target wasmtime-hello+ ./build/wasmtime-hello*/#include <assert.h>diff --git a/examples/interrupt.c b/examples/interrupt.cindex 021970453d..d309f2162a 100644--- a/examples/interrupt.c+++ b/examples/interrupt.c@@ -2,10 +2,11 @@Example of instantiating of the WebAssembly module and invoking its exportedfunction.-You can build using cmake:+You can build and run this example using cmake:-mkdir build && cd build && cmake .. && \- cmake --build . --target wasmtime-interrupt+ cmake -B build -S examples+ cmake --build build --target wasmtime-interrupt+ ./build/wasmtime-interrupt*/#include <assert.h>diff --git a/examples/linking.c b/examples/linking.cindex c3fa3a6ac2..a394173b9b 100644--- a/examples/linking.c+++ b/examples/linking.c@@ -2,9 +2,11 @@Example of compiling, instantiating, and linking two WebAssembly modulestogether.-You can build using cmake:+You can build and run this example using cmake:-mkdir build && cd build && cmake .. && cmake --build . --target wasmtime-linking+ cmake -B build -S examples+ cmake --build build --target wasmtime-linking+ ./build/wasmtime-linking*/#include <assert.h>diff --git a/examples/memory.c b/examples/memory.cindex e99e57268a..3bd1a419ff 100644--- a/examples/memory.c+++ b/examples/memory.c@@ -2,9 +2,11 @@Example of instantiating of the WebAssembly module and invoking its exportedfunction.-You can build using cmake:+You can build and run this example using cmake:-mkdir build && cd build && cmake .. && cmake --build . --target wasmtime-memory+ cmake -B build -S examples+ cmake --build build --target wasmtime-memory+ ./build/wasmtime-memoryAlso note that this example was taken fromhttps://github.com/WebAssembly/wasm-c-api/blob/master/example/memory.cdiff --git a/examples/multi.c b/examples/multi.cindex 61fce9a71e..1e16d8f879 100644--- a/examples/multi.c+++ b/examples/multi.c@@ -2,9 +2,11 @@Example of instantiating of the WebAssembly module and invoking its exportedfunction.-You can build using cmake:+You can build and run this example using cmake:-mkdir build && cd build && cmake .. && cmake --build . --target wasmtime-multi+ cmake -B build -S examples+ cmake --build build --target wasmtime-multi+ ./build/wasmtime-multiAlso note that this example was taken fromhttps://github.com/WebAssembly/wasm-c-api/blob/master/example/multi.cdiff --git a/examples/multi.cc b/examples/multi.ccindex 34a20e481f..417858f825 100644--- a/examples/multi.cc+++ b/examples/multi.cc@@ -2,14 +2,11 @@Example of instantiating of the WebAssembly module and invoking its exportedfunction.-You can build the example using CMake:+You can build and run the example using CMake:-mkdir build && (cd build && cmake .. && \- cmake --build . --target wasmtime-multi-cpp)--And then run it:--build/wasmtime-multi-cpp+ cmake -B build -S examples+ cmake --build build --target wasmtime-multi-cpp+ ./build/wasmtime-multi-cpp*/#include <fstream>diff --git a/examples/multimemory.c b/examples/multimemory.cindex 41cf16f67c..45e3bfd3d0 100644--- a/examples/multimemory.c+++ b/examples/multimemory.c@@ -1,10 +1,11 @@/*An example of how to interact with multiple memories.-You can build using cmake:+You can build and run this example using cmake:-mkdir build && cd build && cmake .. && \- cmake --build . --target wasmtime-multimemory+ cmake -B build -S examples+ cmake --build build --target wasmtime-multimemory+ ./build/wasmtime-multimemory*/#include <inttypes.h>diff --git a/examples/multimemory.cc b/examples/multimemory.ccindex e208b2002e..ea6b834102 100644--- a/examples/multimemory.cc+++ b/examples/multimemory.cc@@ -1,14 +1,11 @@/*An example of how to interact with multiple memories.-You can build the example using CMake:+You can build and run the example using CMake:-mkdir build && (cd build && cmake .. && \- cmake --build . --target wasmtime-multimemory-cpp)--And then run it:--build/wasmtime-multimemory-cpp+ cmake -B build -S examples+ cmake --build build --target wasmtime-multimemory-cpp+ ./build/wasmtime-multimemory-cpp*/#include <fstream>diff --git a/examples/resource-component/main.rs b/examples/resource-component/main.rsindex efe0802671..54acd084c2 100644--- a/examples/resource-component/main.rs+++ b/examples/resource-component/main.rs@@ -2,7 +2,7 @@/*You can execute this example with:- cmake examples/+ cargo build --target wasm32-wasip2 -p example-resource-component-wasmcargo run --example resource-component*/diff --git a/examples/serialize.c b/examples/serialize.cindex 650100013e..69639cae9a 100644--- a/examples/serialize.c+++ b/examples/serialize.c@@ -2,10 +2,11 @@Example of instantiating of the WebAssembly module and invoking its exportedfunction.-You can build using cmake:+You can build and run this example using cmake:-mkdir build && cd build && cmake .. && \- cmake --build . --target wasmtime-serialize+ cmake -B build -S examples+ cmake --build build --target wasmtime-serialize+ ./build/wasmtime-serialize*/#include <assert.h>diff --git a/examples/serialize.cc b/examples/serialize.ccindex 4b39ebc833..615bb5ee3a 100644--- a/examples/serialize.cc+++ b/examples/serialize.cc@@ -2,14 +2,11 @@Small example of how to serialize compiled wasm module to the disk,and then instantiate it from the compilation artifacts.-You can build the example using CMake:+You can build and run the example using CMake:-mkdir build && (cd build && cmake .. && \- cmake --build . --target wasmtime-serialize-cpp)--And then run it:--build/wasmtime-serialize-cpp+ cmake -B build -S examples+ cmake --build build --target wasmtime-serialize-cpp+ ./build/wasmtime-serialize-cpp*/#include <fstream>diff --git a/examples/threads.c b/examples/threads.cindex fd0ed83815..4e15106993 100644--- a/examples/threads.c+++ b/examples/threads.c@@ -2,9 +2,11 @@Example of instantiating of the WebAssembly module and invoking its exportedfunction in a separate thread.-You can build using cmake:+You can build and run this example using cmake:-mkdir build && cd build && cmake .. && cmake --build . --target wasmtime-threads+ cmake -B build -S examples+ cmake --build build --target wasmtime-threads+ ./build/wasmtime-threads*/#ifndef _WIN32diff --git a/examples/threads.cc b/examples/threads.ccindex 84793c13c2..c3df84358a 100644--- a/examples/threads.cc+++ b/examples/threads.cc@@ -2,14 +2,11 @@Example of instantiating of the WebAssembly module and invoking its exportedfunction in a separate thread.-You can build the example using CMake:+You can build and run the example using CMake:-mkdir build && (cd build && cmake .. && \- cmake --build . --target wasmtime-threads-cpp)--And then run it:--build/wasmtime-threads-cpp+ cmake -B build -S examples+ cmake --build build --target wasmtime-threads-cpp+ ./build/wasmtime-threads-cpp*/#include <fstream>diff --git a/examples/wasip1-async/main.rs b/examples/wasip1-async/main.rsindex 3474305eb4..018a2e7c6f 100644--- a/examples/wasip1-async/main.rs+++ b/examples/wasip1-async/main.rs@@ -3,7 +3,7 @@/*You can execute this example with:- cmake examples/+ cargo build --target wasm32-wasip1 -p example-wasi-wasmcargo run --example wasip1-async*/diff --git a/examples/wasip1/main.c b/examples/wasip1/main.cindex a57b346633..4dacd21eec 100644--- a/examples/wasip1/main.c+++ b/examples/wasip1/main.c@@ -3,7 +3,7 @@ Example of instantiating a WebAssembly which uses WASI imports.You can compile and run this example on Linux with:- cmake examples/+ cargo build --target wasm32-wasip1 -p example-wasi-wasmcargo build --release -p wasmtime-c-apicc examples/wasip1/main.c \-I crates/c-api/include \@@ -15,9 +15,12 @@ You can compile and run this example on Linux with:Note that on Windows and macOS the command will be similar, but you'll needto tweak the `-lpthread` and such annotations.-You can also build using cmake:+You can also build and run this example using cmake:-mkdir build && cd build && cmake .. && cmake --build . --target wasmtime-wasip1+ cargo build --target wasm32-wasip1 -p example-wasi-wasm+ cmake -B build -S examples+ cmake --build build --target wasmtime-wasip1+ ./build/wasmtime-wasip1*/#include <assert.h>diff --git a/examples/wasip1/main.cc b/examples/wasip1/main.ccindex 62b8ebcbe5..930a591ae4 100644--- a/examples/wasip1/main.cc+++ b/examples/wasip1/main.cc@@ -1,14 +1,12 @@/*Example of instantiating a wasm module which uses WASI imports.-You can build the example using CMake:+You can build and run the example using CMake:-mkdir build && (cd build && cmake .. && \- cmake --build . --target wasmtime-wasip1-cpp)--And then run it:--build/wasmtime-wasip1-cpp+ cargo build --target wasm32-wasip1 -p example-wasi-wasm+ cmake -B build -S examples+ cmake --build build --target wasmtime-wasip1-cpp+ ./build/wasmtime-wasip1-cpp*/#include <fstream>diff --git a/examples/wasip1/main.rs b/examples/wasip1/main.rsindex c9e381a985..e1db094fcd 100644--- a/examples/wasip1/main.rs+++ b/examples/wasip1/main.rs@@ -2,7 +2,7 @@/*You can execute this example with:- cmake examples/+ cargo build --target wasm32-wasip1 -p example-wasi-wasmcargo run --example wasip1*/diff --git a/examples/wasip2-async/main.rs b/examples/wasip2-async/main.rsindex 8dec512efb..bdc1a6ffb4 100644--- a/examples/wasip2-async/main.rs+++ b/examples/wasip2-async/main.rs@@ -3,7 +3,7 @@/*You can execute this example with:- cmake examples/+ cargo build --target wasm32-wasip2 -p example-wasi-wasmcargo run --example wasip2-async*/diff --git a/examples/wasip2/main.rs b/examples/wasip2/main.rsindex 22dfaae889..e12fd94b79 100644--- a/examples/wasip2/main.rs+++ b/examples/wasip2/main.rs@@ -2,7 +2,7 @@/*You can execute this example with:- cmake examples/+ cargo build --target wasm32-wasip2 -p example-wasi-wasmcargo run --example wasip2*/