File tree Expand file tree Collapse file tree 18 files changed +342
-1
lines changed Expand file tree Collapse file tree 18 files changed +342
-1
lines changed Original file line number Diff line number Diff line change 7
7
- [ Examples] ( ./examples.md )
8
8
- [ Markdown parser] ( ./examples-markdown.md )
9
9
- [ Profiling WebAssembly] ( ./examples-profiling.md )
10
+ - [ Embedding in Rust] ( ./examples-rust-embed.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
+ - [ WASI] ( ./examples-rust-wasi.md )
15
+ - [ Linking modules] ( ./examples-rust-linking.md )
16
+ - [ Debugging] ( ./examples-rust-debugging.md )
17
+ - [ Using multi-value] ( ./examples-rust-multi-value.md )
18
+ - [ Embedding in C] ( ./examples-c-embed.md )
19
+ - [ Hello, world!] ( ./examples-c-hello-world.md )
20
+ - [ Calculating the GCD] ( ./examples-c-gcd.md )
21
+ - [ Using linear memory] ( ./examples-c-memory.md )
22
+ - [ WASI] ( ./examples-c-wasi.md )
23
+ - [ Linking modules] ( ./examples-c-linking.md )
24
+ - [ Debugging] ( ./examples-c-debugging.md )
25
+ - [ Using multi-value] ( ./examples-c-multi-value.md )
10
26
- [ Using WebAssembly from your lanugage] ( ./lang.md )
11
27
- [ Python] ( ./lang-python.md )
12
28
- [ .NET] ( ./lang-dotnet.md )
Original file line number Diff line number Diff line change 3
3
This document shows an example of how to embed Wasmtime using the [ Rust
4
4
API] [ apidoc ] to execute a simple wasm program. Be sure to also check out the
5
5
[ full API documentation] [ apidoc ] for a full listing of what the [ ` wasmtime `
6
- crate] [ crate ] has to offer.
6
+ crate] [ wasmtime ] has to offer.
7
7
8
8
[ apidoc ] : https://bytecodealliance.github.io/wasmtime/api/wasmtime/
9
9
[ wasmtime ] : https://crates.io/crates/wasmtime
Original file line number Diff line number Diff line change
1
+ # Debugging
2
+
3
+ You can also [ browse this source code online] [ code ] and clone the wasmtime
4
+ repository to run the example locally.
5
+
6
+ [ code ] : https://github.com/bytecodealliance/wasmtime/blob/master/examples/fib-debug/main.c
7
+
8
+ This example shows off how to set up a module for dynamic runtime debugging via
9
+ a native debugger like GDB or LLDB.
10
+
11
+ ## ` main.c `
12
+
13
+ ``` c
14
+ {{#include ../examples/fib-debug/main.c}}
15
+ ```
Original file line number Diff line number Diff line change
1
+ # Embedding in C
2
+
3
+ This section is intended to showcase the C embedding API for Wasmtime. The C
4
+ embedding API is based on the [ proposed wasm C embedding API] [ proposal ] (namely
5
+ [ ` wasm.h ` ] ) and has a few extension headers (like [ ` wasi.h ` ] and
6
+ [ ` wasmtime.h ` ] ) which are intended to eventually become part of the standard
7
+ themselves one day.
8
+
9
+ [ proposal ] : https://github.com/webassembly/wasm-c-api
10
+ [ `wasm.h` ] : https://github.com/WebAssembly/wasm-c-api/blob/master/include/wasm.h
11
+ [ `wasi.h` ] : https://github.com/bytecodealliance/wasmtime/blob/master/crates/c-api/include/wasi.h
12
+ [ `wasmtime.h` ] : https://github.com/bytecodealliance/wasmtime/blob/master/crates/c-api/include/wasmtime.h
Original file line number Diff line number Diff line change
1
+ # Calculating the GCD
2
+
3
+ You can also [ browse this source code online] [ code ] and clone the wasmtime
4
+ repository to run the example locally.
5
+
6
+ [ code ] : https://github.com/bytecodealliance/wasmtime/blob/master/examples/gcd.c
7
+
8
+ This example shows off how run a wasm program which calculates the GCD of two
9
+ numbers.
10
+
11
+ ## ` gcd.wat `
12
+
13
+ ``` wat
14
+ {{#include ../examples/gcd.wat}}
15
+ ```
16
+
17
+
18
+ ## ` gcd.c `
19
+
20
+ ``` rust
21
+ {{#include .. / examples / gcd . c}}
22
+ ```
Original file line number Diff line number Diff line change
1
+ # Hello, world!
2
+
3
+ You can also [ browse this source code online] [ code ] and clone the wasmtime
4
+ repository to run the example locally.
5
+
6
+ [ code ] : https://github.com/bytecodealliance/wasmtime/blob/master/examples/hello.c
7
+
8
+ This example shows off how to instantiate a simple wasm module and interact with
9
+ it.
10
+
11
+ ## ` hello.wat `
12
+
13
+ ``` wat
14
+ {{#include ../examples/hello.wat}}
15
+ ```
16
+
17
+
18
+ ## ` hello.c `
19
+
20
+ ``` c
21
+ {{#include ../examples/hello.c}}
22
+ ```
Original file line number Diff line number Diff line change
1
+ # Linking modules
2
+
3
+ You can also [ browse this source code online] [ code ] and clone the wasmtime
4
+ repository to run the example locally.
5
+
6
+ [ code ] : https://github.com/bytecodealliance/wasmtime/blob/master/examples/linking.c
7
+
8
+ This example shows off how to compile and instantiate modules which link
9
+ together.
10
+
11
+ ## ` linking1.wat `
12
+
13
+ ``` wat
14
+ {{#include ../examples/linking1.wat}}
15
+ ```
16
+
17
+ ## ` linking2.wat `
18
+
19
+ ``` wat
20
+ {{#include ../examples/linking2.wat}}
21
+ ```
22
+
23
+ ## ` linking.c `
24
+
25
+ ``` c
26
+ {{#include ../examples/linking.c}}
27
+ ```
Original file line number Diff line number Diff line change
1
+ # Using linear memory
2
+
3
+ You can also [ browse this source code online] [ code ] and clone the wasmtime
4
+ repository to run the example locally.
5
+
6
+ [ code ] : https://github.com/bytecodealliance/wasmtime/blob/master/examples/memory.c
7
+
8
+ This example shows off how to interact with wasm memory in a module. Be sure to
9
+ read the documentation for [ ` Memory ` ] as well.
10
+
11
+ [ `Memory` ] : https://bytecodealliance.github.io/wasmtime/api/wasmtime/struct.Memory.html
12
+
13
+ ## ` memory.wat `
14
+
15
+ ``` wat
16
+ {{#include ../examples/memory.wat}}
17
+ ```
18
+
19
+
20
+ ## ` memory.c `
21
+
22
+ ``` c
23
+ {{#include ../examples/memory.c}}
24
+ ```
Original file line number Diff line number Diff line change
1
+ # Using multi-value
2
+
3
+ You can also [ browse this source code online] [ code ] and clone the wasmtime
4
+ repository to run the example locally.
5
+
6
+ [ code ] : https://github.com/bytecodealliance/wasmtime/blob/master/examples/multi.c
7
+
8
+ This example shows off how to interact with a wasm module that uses multi-value
9
+ exports and imports.
10
+
11
+ ## ` multi.wat `
12
+
13
+ ``` wat
14
+ {{#include ../examples/multi.wat}}
15
+ ```
16
+
17
+
18
+ ## ` multi.c `
19
+
20
+ ``` c
21
+ {{#include ../examples/multi.c}}
22
+ ```
Original file line number Diff line number Diff line change
1
+ # WASI
2
+
3
+ You can also [ browse this source code online] [ code ] and clone the wasmtime
4
+ repository to run the example locally.
5
+
6
+ [ code ] : https://github.com/bytecodealliance/wasmtime/blob/master/examples/wasi/main.c
7
+
8
+ This example shows off how to instantiate a wasm module using WASI imports.
9
+
10
+ ## Wasm Source code
11
+
12
+ ``` rust
13
+ {{#include .. / examples / wasi / wasm / wasi . c}}
14
+ ```
15
+
16
+
17
+ ## ` wasi.c `
18
+
19
+ ``` c
20
+ {{#include ../examples/wasi/main.c}}
21
+ ```
Original file line number Diff line number Diff line change
1
+ # Debugging
2
+
3
+ You can also [ browse this source code online] [ code ] and clone the wasmtime
4
+ repository to run the example locally.
5
+
6
+ [ code ] : https://github.com/bytecodealliance/wasmtime/blob/master/examples/fib-debug/main.rs
7
+
8
+ This example shows off how to set up a module for dynamic runtime debugging via
9
+ a native debugger like GDB or LLDB.
10
+
11
+ ## ` main.rs `
12
+
13
+ ``` rust
14
+ {{#include .. / examples / fib - debug / main . rs}}
15
+ ```
Original file line number Diff line number Diff line change
1
+ # Embedding in Rust
2
+
3
+ This section is intended to showcase the Rust embedding API for Wasmtime. This
4
+ is done through the [ ` wasmtime ` crate] ( https://crates.io/crates/wasmtime ) . In
5
+ addition to browsing the following examples you can also browse the [ specific
6
+ section on Rust embedding] ( ./embed-rust.md ) or the [ full API
7
+ documentation] ( https://docs.rs/wasmtime ) .
Original file line number Diff line number Diff line change
1
+ # Calculating the GCD
2
+
3
+ You can also [ browse this source code online] [ code ] and clone the wasmtime
4
+ repository to run the example locally.
5
+
6
+ [ code ] : https://github.com/bytecodealliance/wasmtime/blob/master/examples/gcd.rs
7
+
8
+ This example shows off how run a wasm program which calculates the GCD of two
9
+ numbers.
10
+
11
+ ## ` gcd.wat `
12
+
13
+ ``` wat
14
+ {{#include ../examples/gcd.wat}}
15
+ ```
16
+
17
+
18
+ ## ` gcd.rs `
19
+
20
+ ``` rust
21
+ {{#include .. / examples / gcd . rs}}
22
+ ```
Original file line number Diff line number Diff line change
1
+ # Hello, world!
2
+
3
+ You can also [ browse this source code online] [ code ] and clone the wasmtime
4
+ repository to run the example locally.
5
+
6
+ [ code ] : https://github.com/bytecodealliance/wasmtime/blob/master/examples/hello.rs
7
+
8
+ This example shows off how to instantiate a simple wasm module and interact with
9
+ it.
10
+
11
+ ## ` hello.wat `
12
+
13
+ ``` wat
14
+ {{#include ../examples/hello.wat}}
15
+ ```
16
+
17
+
18
+ ## ` hello.rs `
19
+
20
+ ``` rust
21
+ {{#include .. / examples / hello . rs}}
22
+ ```
Original file line number Diff line number Diff line change
1
+ # Linking modules
2
+
3
+ You can also [ browse this source code online] [ code ] and clone the wasmtime
4
+ repository to run the example locally.
5
+
6
+ [ code ] : https://github.com/bytecodealliance/wasmtime/blob/master/examples/linking.rs
7
+
8
+ This example shows off how to compile and instantiate modules which link
9
+ together.
10
+
11
+ ## ` linking1.wat `
12
+
13
+ ``` wat
14
+ {{#include ../examples/linking1.wat}}
15
+ ```
16
+
17
+ ## ` linking2.wat `
18
+
19
+ ``` wat
20
+ {{#include ../examples/linking2.wat}}
21
+ ```
22
+
23
+ ## ` linking.rs `
24
+
25
+ ``` rust
26
+ {{#include .. / examples / linking . rs}}
27
+ ```
Original file line number Diff line number Diff line change
1
+ # Using linear memory
2
+
3
+ You can also [ browse this source code online] [ code ] and clone the wasmtime
4
+ repository to run the example locally.
5
+
6
+ [ code ] : https://github.com/bytecodealliance/wasmtime/blob/master/examples/memory.rs
7
+
8
+ This example shows off how to interact with wasm memory in a module. Be sure to
9
+ read the documentation for [ ` Memory ` ] as well.
10
+
11
+ [ `Memory` ] : https://bytecodealliance.github.io/wasmtime/api/wasmtime/struct.Memory.html
12
+
13
+ ## ` memory.wat `
14
+
15
+ ``` wat
16
+ {{#include ../examples/memory.wat}}
17
+ ```
18
+
19
+
20
+ ## ` memory.rs `
21
+
22
+ ``` rust
23
+ {{#include .. / examples / memory . rs}}
24
+ ```
Original file line number Diff line number Diff line change
1
+ # Using multi-value
2
+
3
+ You can also [ browse this source code online] [ code ] and clone the wasmtime
4
+ repository to run the example locally.
5
+
6
+ [ code ] : https://github.com/bytecodealliance/wasmtime/blob/master/examples/multi.rs
7
+
8
+ This example shows off how to interact with a wasm module that uses multi-value
9
+ exports and imports.
10
+
11
+ ## ` multi.wat `
12
+
13
+ ``` wat
14
+ {{#include ../examples/multi.wat}}
15
+ ```
16
+
17
+
18
+ ## ` multi.rs `
19
+
20
+ ``` rust
21
+ {{#include .. / examples / multi . rs}}
22
+ ```
Original file line number Diff line number Diff line change
1
+ # WASI
2
+
3
+ You can also [ browse this source code online] [ code ] and clone the wasmtime
4
+ repository to run the example locally.
5
+
6
+ [ code ] : https://github.com/bytecodealliance/wasmtime/blob/master/examples/wasi/main.rs
7
+
8
+ This example shows off how to instantiate a wasm module using WASI imports.
9
+
10
+ ## Wasm Source code
11
+
12
+ ``` rust
13
+ {{#include .. / examples / wasi / wasm / wasi . rs}}
14
+ ```
15
+
16
+
17
+ ## ` wasi.rs `
18
+
19
+ ``` rust
20
+ {{#include .. / examples / wasi / main . rs}}
21
+ ```
You can’t perform that action at this time.
0 commit comments