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 ¶
const ShimCommand = "__toolexec"
ShimCommand is the goesm subcommand the go command runs as -toolexec.
Variables ¶
This section is empty.
Functions ¶
func Capture ¶
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 ¶
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.