Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs/guides: some improvements to the webassembly section #349

Merged
merged 1 commit into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions content/docs/guides/webassembly/_index.md
Original file line number Diff line number Diff line change
@@ -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).
---

31 changes: 31 additions & 0 deletions content/docs/guides/webassembly/wasi.md
Original file line number Diff line number Diff line change
@@ -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
}
deadprogram marked this conversation as resolved.
Show resolved Hide resolved

// 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
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Using WebAssembly"
title: "Using WASM"
weight: 3
description: |
How to call WebAssembly from JavaScript in a browser.
Expand Down