toolexec

package
v0.0.1-beta.2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package toolexec runs a -toolexec program (go build -toolexec) for goesm.

goesm never runs the Go compiler: it reads Go source with go/packages. Tools that hook into the go command with -toolexec, such as OpenTelemetry's compile-time instrumentation (otelc), change the source the compiler sees instead: they rewrite the Go files of a compile command, add files to it, and hand the rewritten command on to the compiler. goesm runs the same build for its target (GOOS=js GOARCH=wasm, go list -export) with the program as -toolexec, and puts a recorder between the program and the compiler. The recorder notes the Go files of every compile and then runs the compiler. The files that differ from the package's own become an overlay, so goesm lowers exactly the source the compiler would compile.

The go command caches compiles, and a cached compile runs no tools. The recorder keeps what it saw in a store next to the build cache, keyed by the action ID of the compile, and goesm marks the compiler's version so that these compiles do not share cache entries with ordinary builds.

Index

Constants

View Source
const ShimCommand = "__toolexec"

ShimCommand is the goesm subcommand the go command runs as -toolexec.

Variables

This section is empty.

Functions

func Capture

func Capture(opts Options) (map[string][]byte, error)

Capture runs the build of opts.Patterns through opts.Program and returns the source the compiles saw as an overlay: file contents keyed by absolute path, for every file a tool replaced or added.

func FromGOFLAGS

func FromGOFLAGS(goflags string) string

FromGOFLAGS returns the -toolexec program set in GOFLAGS, which is how tools such as otelc are plugged into builds they do not run themselves.

func IsRecorder

func IsRecorder() bool

IsRecorder reports whether this process is the recorder, run by a -toolexec program in place of the compiler.

func Record

func Record(args []string) int

Record is the recorder: it notes the Go files of a compile command (args) and runs the compiler on it.

func Shim

func Shim(args []string) int

Shim is goesm run by the go command as -toolexec: args are the tool and its arguments. It runs the user's -toolexec program on them, with the recorder in place of the compiler, and returns the exit status.

Types

type Options

type Options struct {
	Dir        string   // working directory of the build
	Program    string   // the -toolexec program, as for go build
	Env        []string // environment of the go command (target GOOS/GOARCH)
	BuildFlags []string // e.g. -tags
	Patterns   []string
}

Options of a capture.

Jump to

Keyboard shortcuts

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