tinygo

package
v0.0.0-...-bd06792 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package tinygo reads target and port metadata from the TinyGo command-line interface. Commands are executed directly rather than through a shell, and command-derived names are constrained before they reach generated tasks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanFlash

func CanFlash(info Info) bool

CanFlash reports whether TinyGo provides either a flash method or a custom flash command for the target.

func PortRelevant

func PortRelevant(info Info) bool

PortRelevant reports whether flashing the target may require an explicit serial port. Mass-storage targets intentionally return false even if their metadata also advertises reset behavior.

func ValidatePort

func ValidatePort(port string) error

ValidatePort accepts an empty value for automatic port detection. Non-empty values are restricted to characters used by Unix device paths and Windows COM ports so generated task arguments cannot smuggle shell syntax.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client runs a specific TinyGo executable from a project root. Target metadata is cached per client and may be queried concurrently.

func New

func New(executable, root string) *Client

New returns a client that invokes executable with root as its working directory. It does not verify either path until a command is run.

func (*Client) Info

func (c *Client) Info(ctx context.Context, target string) (Info, error)

Info returns complete metadata for target. Successful results are cached, so callers must treat the returned Info as read-only; cancellation affects only cache misses that start a subprocess.

func (*Client) Ports

func (c *Client) Ports(ctx context.Context) ([]Port, error)

Ports returns devices reported by TinyGo, sorted by port name. An empty list is valid; malformed or unsafe port names fail the entire query.

func (*Client) Targets

func (c *Client) Targets(ctx context.Context) ([]string, error)

Targets returns the sorted, unique target names reported by TinyGo. It rejects empty output and names that would be unsafe to place in generated task arguments.

func (*Client) ValidateTarget

func (c *Client) ValidateTarget(ctx context.Context, target string) error

ValidateTarget requires target to be both syntactically safe and present in `tinygo targets`, then verifies that complete metadata can be loaded for it.

type Info

type Info struct {
	// Target contains the flashing fields from TinyGo's resolved target spec.
	Target struct {
		// FlashMethod selects TinyGo's built-in flashing implementation.
		FlashMethod string `json:"flash-method"`
		// FlashCommand is a target-provided external flashing command template.
		FlashCommand string `json:"flash-command"`
		// PortReset records whether TinyGo performs a 1200-baud port reset.
		PortReset string `json:"flash-1200-bps-reset"`
	} `json:"target"`
	// GOROOT is TinyGo's generated Go root for this target and TinyGo version.
	GOROOT string `json:"goroot"`
	// GOOS and GOARCH select the target platform presented to Go tooling.
	GOOS   string `json:"goos"`
	GOARCH string `json:"goarch"`
	// GOARM and GOMIPS contain optional architecture tuning values.
	GOARM  string `json:"goarm"`
	GOMIPS string `json:"gomips"`
	// BuildTags are the complete target tags required for package discovery.
	BuildTags []string `json:"build_tags"`
}

Info is the subset of `tinygo info -json` required to configure gopls and decide whether a target supports flashing or needs a serial port.

type Port

type Port struct {
	// Name is the device path or COM port accepted by TinyGo's -port flag.
	Name string
	// ID is the hardware identifier reported by TinyGo.
	ID string
	// Boards is TinyGo's optional human-readable board match.
	Boards string
}

Port describes one device reported by `tinygo ports`.

Jump to

Keyboard shortcuts

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