An open API service indexing awesome lists of open source software.

https://github.com/tinywasm/tinygo

Automated TinyGo installer for tinywasm ecosystem with cross-platform support
https://github.com/tinywasm/tinygo

Last synced: 2 months ago
JSON representation

Automated TinyGo installer for tinywasm ecosystem with cross-platform support

Awesome Lists containing this project

README

          

# tinygo

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.

## Features

- **Zero-Admin**: Installs into `~/.tinywasm/tinygo/`, avoiding the need for `sudo`.
- **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.

## Installation

```go
import "github.com/tinywasm/tinygo"
```

## Usage

### Ensure TinyGo is Installed

The most common use case is ensuring TinyGo is available before running a build.

```go
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)
```

### Detection

Check if TinyGo is already in the system PATH or locally installed.

```go
if tinygo.IsInstalled() {
path, _ := tinygo.GetPath()
version, _ := tinygo.GetVersion()
fmt.Printf("Found TinyGo %s at %s\n", version, path)
}
```

### Manual Installation

Explicitly trigger an installation of a specific version.

```go
err := tinygo.Install(
tinygo.WithVersion("0.40.1"),
tinygo.WithInstallDir("/custom/path"),
)
```

### Environment for Subprocesses

When TinyGo is installed locally, consumers must inject `TINYGOROOT` into any subprocess that invokes `tinygo build`:

```go
binPath, _ := tinygo.EnsureInstalled()
cmd := exec.Command(binPath, "build", "-o", "out.wasm", ".")
cmd.Env = tinygo.GetEnv() // injects TINYGOROOT + PATH
out, err := cmd.CombinedOutput()
```

## How it Works

See the [Install Flow diagram](docs/diagrams/install_flow.md) for the full decision tree.

1. **Detection**: Checks if `tinygo` is available in the system `PATH`.
2. **Fallback**: If not found, checks for a local install at `~/.tinywasm/tinygo/`.
3. **Download**: If missing, downloads the official release from GitHub.
4. **Extraction**: `.tar.gz` for Linux/macOS, `.zip` for Windows.
5. **Verification**: Runs `tinygo version` to confirm the binary is functional.

## Testing

```bash
go test ./...
```

See [docs/architecture.md](docs/architecture.md) for the full testing strategy and design decisions.

## License

MIT