Skip to content

Commit 752508c

Browse files
authored andcommitted
docs/guides: some improvements to the webassembly section
Signed-off-by: deadprogram <ron@hybridgroup.com>
1 parent 91d5dd3 commit 752508c

File tree

Image for: File tree

3 files changed

Image for: 3 files changed
+39
-1
lines changed

3 files changed

Image for: 3 files changed
+39
-1
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: "WebAssembly"
3+
weight: 2
4+
description: >
5+
TinyGo is very useful for compiling programs both for use in browsers (WASM) as well as for use on servers and other edge devices (WASI).
6+
---
7+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: "Using WASI"
3+
weight: 3
4+
description: |
5+
How to use TinyGo with the WebAssembly System Interface (WASI).
6+
---
7+
8+
TinyGo is very useful for compiling programs for use on servers and other edge devices (WASI).
9+
10+
TinyGo programs can run in Fastly Compute@Edge (https://developer.fastly.com/learning/compute/go/), Fermyon Spin (https://developer.fermyon.com/spin/go-components), wazero (https://wazero.io/languages/tinygo/) and many other WebAssembly runtimes.
11+
12+
Here is a small TinyGo program for use within a WASI host application:
13+
14+
```go
15+
package main
16+
17+
//go:wasm-module yourmodulename
18+
//export add
19+
func add(x, y uint32) uint32 {
20+
return x + y
21+
}
22+
23+
// main is required for the `wasi` target, even if it isn't used.
24+
func main() {}
25+
```
26+
27+
To compile the above TinyGo program for use on any WASI runtime:
28+
29+
```shell
30+
tinygo build -o main.wasm -target=wasi main.go
31+
```

‎content/docs/guides/webassembly.md renamed to ‎content/docs/guides/webassembly/wasm.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Using WebAssembly"
2+
title: "Using WASM"
33
weight: 3
44
description: |
55
How to call WebAssembly from JavaScript in a browser.

0 commit comments

Image for: 0 commit comments
Comments
 (0)