Automated TinyGo installer for the tinywasm ecosystem. This package provides a standalone, cross-platform (Linux, macOS, Windows) solution to manage TinyGo installations without requiring administrator privileges or user interaction.
- Zero-Admin: Installs into
~/.tinywasm/tinygo/, avoiding the need forsudo. - Cross-Platform: Full support for Linux (amd64/arm64), macOS (amd64/arm64), and Windows (amd64).
- Automated: Handles downloading, extracting (tar.gz/zip), and binary verification.
- Unattended: Designed for CI/CD and developer environment bootstrap.
- Idempotent: Won't re-download if the specified version is already present.
import "github.com/tinywasm/tinygo"The most common use case is ensuring TinyGo is available before running a build.
binPath, err := tinygo.EnsureInstalled(
tinygo.WithLogger(func(msg string) {
fmt.Println(msg)
}),
)
if err != nil {
log.Fatal(err)
}
fmt.Printf("TinyGo is ready at: %s\n", binPath)Check if TinyGo is already in the system PATH or locally installed.
if tinygo.IsInstalled() {
path, _ := tinygo.GetPath()
version, _ := tinygo.GetVersion()
fmt.Printf("Found TinyGo %s at %s\n", version, path)
}Explicitly trigger an installation of a specific version.
err := tinygo.Install(
tinygo.WithVersion("0.40.1"),
tinygo.WithInstallDir("/custom/path"),
)When TinyGo is installed locally, consumers must inject TINYGOROOT into any subprocess that invokes tinygo build:
binPath, _ := tinygo.EnsureInstalled()
cmd := exec.Command(binPath, "build", "-o", "out.wasm", ".")
cmd.Env = tinygo.GetEnv() // injects TINYGOROOT + PATH
out, err := cmd.CombinedOutput()See the Install Flow diagram for the full decision tree.
- Detection: Checks if
tinygois available in the systemPATH. - Fallback: If not found, checks for a local install at
~/.tinywasm/tinygo/. - Download: If missing, downloads the official release from GitHub.
- Extraction:
.tar.gzfor Linux/macOS,.zipfor Windows. - Verification: Runs
tinygo versionto confirm the binary is functional.
go test ./...See docs/architecture.md for the full testing strategy and design decisions.
MIT