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
- Variables
- func Build(ctx context.Context, tinygoBin string, files map[string][]byte, run Runner) ([]byte, error)
- func Sources(dir string) (map[string][]byte, string, error)
- type Manager
- func (m *Manager) Bin() string
- func (m *Manager) Checksum() (string, error)
- func (m *Manager) Dir() string
- func (m *Manager) Install(ctx context.Context) (bin string, already bool, err error)
- func (m *Manager) Resolve(ctx context.Context, download bool) (string, string, error)
- func (m *Manager) Status() Status
- func (m *Manager) Update(ctx context.Context) (bin string, already bool, removed []string, err error)
- type Runner
- type Status
Constants ¶
const DefaultBaseURL = "https://github.com/tinygo-org/tinygo/releases/download"
DefaultBaseURL serves the release archives.
const EnvOverride = "TINYAGENT_TINYGO"
EnvOverride names the environment variable pointing at an existing tinygo executable.
const MaxArchiveBytes = 1 << 30
MaxArchiveBytes caps a download.
const MaxSourceBytes = 4 << 20
MaxSourceBytes caps the Go source of one module.
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).
const Version = "0.44.0"
Version is the pinned TinyGo release.
Variables ¶
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.
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.
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 ¶
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) Install ¶
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 ¶
Resolve returns the tinygo executable and where it came from ("override", "cache" or "download"). Without download it returns ErrMissing when nothing is cached.