From 0c4ff189f5ee4706bb37b8d6b0c8abdc4aaa11cf Mon Sep 17 00:00:00 2001 From: deadprogram Date: Tue, 25 Apr 2023 21:22:39 +0200 Subject: [PATCH] docs/guides: some improvements to the webassembly section Signed-off-by: deadprogram --- content/docs/guides/webassembly/_index.md | 7 +++++ content/docs/guides/webassembly/wasi.md | 30 +++++++++++++++++++ .../{webassembly.md => webassembly/wasm.md} | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 content/docs/guides/webassembly/_index.md create mode 100644 content/docs/guides/webassembly/wasi.md rename content/docs/guides/{webassembly.md => webassembly/wasm.md} (99%) 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..29da62ea --- /dev/null +++ b/content/docs/guides/webassembly/wasi.md @@ -0,0 +1,30 @@ +--- +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 + +//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.