basic

command
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

Basic example

This example shows how to extend a Go application with an addition function defined in WebAssembly.

$ go run add.go 7 9
7 + 9 = 16

Compilation

wazero is a WebAssembly runtime, embedded in your host application. To run WebAssembly functions, you need access to a WebAssembly Binary (Wasm), typically a %.wasm file.

add.wasm was compiled from add.go with TinyGo, as it is the most common way to compile Go source to Wasm. Here's the minimal command to build a %.wasm binary.

cd testdata; tinygo build -o add.wasm -target=wasi add.go

Notes

  • Many other languages compile to (target) Wasm including AssemblyScript, C, C++, Rust, and Zig!
  • The embedding application is often called the "host" in WebAssembly.
  • The Wasm binary is often called the "guest" in WebAssembly. Sometimes they need imports to implement features such as console output. TinyGo's wasi target, requires WASI imports.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL