Help us shape the future of Go! Take the 2026 Go Developer Survey

tinygo

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package tinygo manages the TinyGo compiler TinyAgent uses to build Go plugin source into WebAssembly.

TinyGo is an external dependency shipped separately by the TinyGo project; it is NOT part of TinyAgent. It is never embedded in the TinyAgent binary (this package has no go:embed and bundles no archives) and never committed to the repository. TinyAgent downloads the pinned release below on first use (or with `tinyagent tinygo install`), checks it against the SHA-256 pinned in this file before extracting anything, and caches it under the user cache directory. An existing TinyGo can be used instead with the tinygo config key or TINYAGENT_TINYGO.

Bumping the pinned version: set Version, replace every Checksums entry with the sha256 of the matching tinygo<ver>.<os>-<arch>.tar.gz release asset (`gh release view v<ver> -R tinygo-org/tinygo --json assets` lists them as digests), and run `tinyagent tinygo update`.

Index

Constants

View Source
const DefaultBaseURL = "https://github.com/tinygo-org/tinygo/releases/download"

DefaultBaseURL serves the release archives.

View Source
const EnvOverride = "TINYAGENT_TINYGO"

EnvOverride names the environment variable pointing at an existing tinygo executable.

View Source
const MaxArchiveBytes = 1 << 30

MaxArchiveBytes caps a download.

View Source
const MaxSourceBytes = 4 << 20

MaxSourceBytes caps the Go source of one module.

View Source
const PDKFile = "zz_tinyagent_pdk.go"

PDKFile is the helper file added to every build. It gives the module input() and output() over the Extism kernel and an empty main, so plugin source needs no third-party imports (builds run offline).

View Source
const Version = "0.44.0"

Version is the pinned TinyGo release.

Variables

View Source
var Checksums = map[string]string{
	"linux/amd64":  "ed0f45543a49ff2a99120a5a1b8814a0750e1fda1a66f8e2a0a172576134aaf9",
	"linux/arm64":  "48cece9e1e886a176caad0918182d90f8348ad3084774e6239f42e5e11e40990",
	"darwin/amd64": "405b8241e20825cd3e7267706eb27c4f40fe372f3548a4d7f80ef2eb640957a7",
	"darwin/arm64": "696a37db149c2c37ed0da96cc1f2cca2630fca0c4dd19823a2a481c9b4a6a748",
}

Checksums are the pinned sha256 digests of the release archives, by GOOS/GOARCH.

View Source
var ErrMissing = errors.New("TinyGo is not installed; run `tinyagent tinygo install` (it downloads the pinned TinyGo release, a separate project, not part of TinyAgent) or set the tinygo config key / " + EnvOverride)

ErrMissing is returned by Resolve when no TinyGo is available and downloading wasn't allowed.

Functions

func Build

func Build(ctx context.Context, tinygoBin string, files map[string][]byte, run Runner) ([]byte, error)

Build compiles a module's Go source (package main, standard library only, exports marked //go:wasmexport) to WebAssembly with tinygo for wasip1, in a fresh temp directory, through run. run must not be nil: the source may be agent-written, so it never builds unconfined.

func Sources

func Sources(dir string) (map[string][]byte, string, error)

Sources reads the .go files directly in dir (no subdirectories, tests or go.mod) and returns them with their combined sha256.

Types

type Manager

type Manager struct {
	CacheDir  string // holds tinygo-<version>/
	BaseURL   string
	Version   string
	Checksums map[string]string
	GOOS      string
	GOARCH    string
	Override  string // an existing tinygo executable
	HTTP      *http.Client
}

Manager resolves, installs and updates the TinyGo toolchain.

func Default

func Default(override string) (*Manager, error)

Default is the Manager for this build: the pinned release, cached under os.UserCacheDir()/tinyagent/toolchains, with override (config) or TINYAGENT_TINYGO taking precedence.

func (*Manager) Bin

func (m *Manager) Bin() string

Bin is the tinygo executable inside Dir.

func (*Manager) Checksum

func (m *Manager) Checksum() (string, error)

Checksum is the pinned digest for this platform.

func (*Manager) Dir

func (m *Manager) Dir() string

Dir is the cache directory of the pinned version.

func (*Manager) Install

func (m *Manager) Install(ctx context.Context) (bin string, already bool, err error)

Install downloads the pinned release, verifies its checksum before extracting and caches it. already is true when a verified install was cached and nothing was downloaded. A mismatch leaves nothing in the cache.

func (*Manager) Resolve

func (m *Manager) Resolve(ctx context.Context, download bool) (string, string, error)

Resolve returns the tinygo executable and where it came from ("override", "cache" or "download"). Without download it returns ErrMissing when nothing is cached.

func (*Manager) Status

func (m *Manager) Status() Status

Status reports the pinned and cached toolchain without downloading.

func (*Manager) Update

func (m *Manager) Update(ctx context.Context) (bin string, already bool, removed []string, err error)

Update installs the pinned version when it isn't cached and removes cached installs of other versions. It returns the removed directories.

type Runner

type Runner func(ctx context.Context, writable, workdir string, argv, env []string, out io.Writer) error

Runner runs argv in workdir with env, writing its output to out. TinyAgent passes one that confines the command with the OS sandbox: writes only inside writable, no network.

type Status

type Status struct {
	Pinned, Platform, Checksum string
	Override                   string
	Installed                  bool   // pinned version cached and verified
	Path                       string // executable that would be used
	Others                     []string
}

Status describes the toolchain.

Jump to

Keyboard shortcuts

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