golang

package
v0.0.0-...-d8fbaca Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: BSD-3-Clause Imports: 11 Imported by: 16

Documentation

Overview

Package golang is an API to the Go compiler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildOpts

type BuildOpts struct {
	// NoStrip builds an unstripped binary.
	//
	// Symbols and Build ID will be left in the binary.
	//
	// If NoTrimPath and NoStrip are false, the binary produced will be
	// reproducible.
	NoStrip bool

	// EnableInlining enables function inlining.
	EnableInlining bool

	// NoTrimPath produces a binary whose stack traces contain the module
	// root dirs, GOPATHs, and GOROOTs.
	//
	// If NoTrimPath and NoStrip are false, the binary produced will be
	// reproducible.
	NoTrimPath bool

	// ExtraArgs to `go build`.
	ExtraArgs []string
}

Optional arguments to Environ.BuildDir.

func (*BuildOpts) RegisterFlags

func (b *BuildOpts) RegisterFlags(f *flag.FlagSet)

RegisterFlags registers flags for BuildOpts.

type Environ

type Environ struct {
	build.Context

	GO111MODULE string
	Mod         ModBehavior
	GBBDEBUG    bool
}

Environ are the environment variables for the Go compiler.

func Default

func Default(opts ...Opt) *Environ

Default is the default build environment comprised of the default GOPATH, GOROOT, GOOS, GOARCH, and CGO_ENABLED values.

func (*Environ) Apply

func (c *Environ) Apply(opts ...Opt)

Apply applies additional opts to the environment.

func (Environ) Build

func (c Environ) Build(binaryPath string, pattern []string, opts *BuildOpts) error

Build compiles the pattern.

func (Environ) BuildDir

func (c Environ) BuildDir(dirPath string, binaryPath string, opts *BuildOpts) error

BuildDir compiles the package in the directory `dirPath`, writing the build object to `binaryPath`.

func (*Environ) Copy

func (c *Environ) Copy(opts ...Opt) *Environ

Copy makes a copy of Environ with the given changes.

func (Environ) Env

func (c Environ) Env() []string

Env returns all environment variables for invoking a Go command.

func (Environ) EnvHuman

func (c Environ) EnvHuman() []string

func (Environ) GoCmd

func (c Environ) GoCmd(gocmd string, args ...string) *exec.Cmd

GoCmd runs a go command in the environment.

func (*Environ) Lookup

func (c *Environ) Lookup(mode packages.LoadMode, patterns ...string) ([]*packages.Package, error)

Lookup looks up packages by patterns relative to dir, using the Go environment from c.

func (*Environ) RegisterFlags

func (c *Environ) RegisterFlags(f *flag.FlagSet)

RegisterFlags registers flags for Environ.

func (Environ) String

func (c Environ) String() string

String returns all environment variables for Go invocations.

func (Environ) Valid

func (c Environ) Valid() error

Valid returns an error if GOARCH, GOROOT, or GOOS are unset.

func (Environ) Version

func (c Environ) Version() (string, error)

Version returns the Go version string that runtime.Version would return for the Go compiler in this environ.

type ModBehavior

type ModBehavior string
const (
	ModNone     ModBehavior = ""
	ModOnly     ModBehavior = "mod"
	ModReadonly ModBehavior = "readonly"
	ModVendor   ModBehavior = "vendor"
)

type Opt

type Opt func(*Environ)

Opt is an option function applied to Environ.

func DisableCGO

func DisableCGO() Opt

DisableCGO is an option that disables cgo.

func WithBuildTag

func WithBuildTag(tag ...string) Opt

WithBuildTag is an option that appends build tags.

func WithGO111MODULE

func WithGO111MODULE(go111module string) Opt

WithGO111MODULE is an option that overrides GO111MODULE.

func WithGOARCH

func WithGOARCH(goarch string) Opt

WithGOARCH is an option that overrides GOARCH.

func WithGOOS

func WithGOOS(goos string) Opt

WithGOOS is an option that overrides GOOS.

func WithGOPATH

func WithGOPATH(gopath string) Opt

WithGOPATH is an option that overrides GOPATH.

func WithGOROOT

func WithGOROOT(goroot string) Opt

WithGOROOT is an option that overrides GOROOT.

func WithMod

func WithMod(mod ModBehavior) Opt

WithMod is an option that overrides module behavior.

func WithWorkingDir

func WithWorkingDir(wd string) Opt

WithWorkingDir sets the working directory for calls to `go`.

Jump to

Keyboard shortcuts

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