diff --git a/content/docs/guides/webassembly/_index.md b/content/docs/guides/webassembly/_index.md new file mode 100644 index 00000000..d3aa74ca --- /dev/null +++ b/content/docs/guides/webassembly/_index.md @@ -0,0 +1,7 @@ +--- +title: "WebAssembly" +weight: 2 +description: > + 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). +--- + diff --git a/content/docs/guides/webassembly/wasi.md b/content/docs/guides/webassembly/wasi.md new file mode 100644 index 00000000..0841889f --- /dev/null +++ b/content/docs/guides/webassembly/wasi.md @@ -0,0 +1,31 @@ +--- +title: "Using WASI" +weight: 3 +description: | + How to use TinyGo with the WebAssembly System Interface (WASI). +--- + +TinyGo is very useful for compiling programs for use on servers and other edge devices (WASI). + +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. + +Here is a small TinyGo program for use within a WASI host application: + +```go +package main + +//go:wasm-module yourmodulename +//export add +func add(x, y uint32) uint32 { + return x + y +} + +// main is required for the `wasi` target, even if it isn't used. +func main() {} +``` + +To compile the above TinyGo program for use on any WASI runtime: + +```shell +tinygo build -o main.wasm -target=wasi main.go +``` diff --git a/content/docs/guides/webassembly.md b/content/docs/guides/webassembly/wasm.md similarity index 99% rename from content/docs/guides/webassembly.md rename to content/docs/guides/webassembly/wasm.md index d85b8c92..399078e6 100644 --- a/content/docs/guides/webassembly.md +++ b/content/docs/guides/webassembly/wasm.md @@ -1,5 +1,5 @@ --- -title: "Using WebAssembly" +title: "Using WASM" weight: 3 description: | How to call WebAssembly from JavaScript in a browser.