const DefaultPkgConfig = `pkg-config`
Global build parameters (used during package load)
var (
Goos = envOr("GOOS", build.Default.GOOS)
Goarch = envOr("GOARCH", build.Default.GOARCH)
ExeSuffix = exeSuffix()
// ModulesEnabled specifies whether the go command is running
// in module-aware mode (as opposed to GOPATH mode).
// It is equal to modload.Enabled, but not all packages can import modload.
ModulesEnabled bool
)
These are general "build flags" used by build and other commands.
var (
BuildA bool // -a flag
BuildBuildmode string // -buildmode flag
BuildBuildvcs = "auto" // -buildvcs flag: "true", "false", or "auto"
BuildContext = defaultContext()
BuildMod string // -mod flag
BuildModExplicit bool // whether -mod was set explicitly
BuildModReason string // reason -mod was set, if set by default
bool // -linkshared flag
BuildMSan bool // -msan flag
BuildASan bool // -asan flag
BuildCover bool // -cover flag
BuildCoverMode string // -covermode flag
BuildCoverPkg []string // -coverpkg flag
BuildJSON bool // -json flag
BuildN bool // -n flag
BuildO string // -o flag
BuildP = runtime.GOMAXPROCS(0) // -p flag
BuildPGO string // -pgo flag
BuildPkgdir string // -pkgdir flag
BuildRace bool // -race flag
BuildToolexec []string // -toolexec flag
BuildToolchainName string
BuildToolchainCompiler func() string
BuildToolchainLinker func() string
BuildTrimpath bool // -trimpath flag
BuildV bool // -v flag
BuildWork bool // -work flag
BuildX bool // -x flag
ModCacheRW bool // -modcacherw flag
ModFile string // -modfile flag
CmdName string // "build", "install", "list", "mod tidy", etc.
DebugActiongraph string // -debug-actiongraph flag (undocumented, unstable)
DebugTrace string // -debug-trace flag
DebugRuntimeTrace string // -debug-runtime-trace flag (undocumented, unstable)
// GoPathError is set when GOPATH is not set. it contains an
// explanation why GOPATH is unset.
GoPathError string
GOPATHChanged bool
CGOChanged bool
)
Experiment configuration.
var (
// RawGOEXPERIMENT is the GOEXPERIMENT value set by the user.
RawGOEXPERIMENT = envOr("GOEXPERIMENT", buildcfg.DefaultGOEXPERIMENT)
// CleanGOEXPERIMENT is the minimal GOEXPERIMENT value needed to reproduce the
// experiments enabled by RawGOEXPERIMENT.
CleanGOEXPERIMENT = RawGOEXPERIMENT
Experiment *buildcfg.ExperimentFlags
ExperimentErr error
)
var (
GOROOT string
// Either empty or produced by filepath.Join(GOROOT, …).
GOROOTbin string
GOROOTpkg string
GOROOTsrc string
GOBIN = Getenv("GOBIN")
GOCACHEPROG, GOCACHEPROGChanged = EnvOrAndChanged("GOCACHEPROG", "")
GOMODCACHE, GOMODCACHEChanged = EnvOrAndChanged("GOMODCACHE", gopathDir("pkg/mod"))
// Used in envcmd.MkEnv and build ID computations.
GOARM64, _ = EnvOrAndChanged("GOARM64", buildcfg.DefaultGOARM64)
GOARM, _ = EnvOrAndChanged("GOARM", buildcfg.DefaultGOARM)
GO386, _ = EnvOrAndChanged("GO386", buildcfg.DefaultGO386)
GOAMD64, _ = EnvOrAndChanged("GOAMD64", buildcfg.DefaultGOAMD64)
GOMIPS, _ = EnvOrAndChanged("GOMIPS", buildcfg.DefaultGOMIPS)
GOMIPS64, _ = EnvOrAndChanged("GOMIPS64", buildcfg.DefaultGOMIPS64)
GOPPC64, _ = EnvOrAndChanged("GOPPC64", buildcfg.DefaultGOPPC64)
GORISCV64, _ = EnvOrAndChanged("GORISCV64", buildcfg.DefaultGORISCV64)
GOWASM, _ = EnvOrAndChanged("GOWASM", fmt.Sprint(buildcfg.GOWASM))
GOFIPS140, GOFIPS140Changed = EnvOrAndChanged("GOFIPS140", buildcfg.DefaultGOFIPS140)
GOPROXY, GOPROXYChanged = EnvOrAndChanged("GOPROXY", "")
GOSUMDB, GOSUMDBChanged = EnvOrAndChanged("GOSUMDB", "")
GOPRIVATE = Getenv("GOPRIVATE")
GONOPROXY, GONOPROXYChanged = EnvOrAndChanged("GONOPROXY", GOPRIVATE)
GONOSUMDB, GONOSUMDBChanged = EnvOrAndChanged("GONOSUMDB", GOPRIVATE)
GOINSECURE = Getenv("GOINSECURE")
GOVCS = Getenv("GOVCS")
GOAUTH, GOAUTHChanged = EnvOrAndChanged("GOAUTH", "netrc")
)
CmdEnv is the new environment for running go tool commands. User binaries (during go test or go run) are run with OrigEnv, not CmdEnv.
var CmdEnv []EnvVar
OrigEnv is the original environment of the program at startup.
var OrigEnv []string
var SumdbDir = gopathDir("pkg/sumdb")
func BuildXWriter(ctx context.Context) (io.Writer, bool)
BuildXWriter returns nil if BuildX is false, or the writer to which BuildX output should be written otherwise.
func CanGetenv(key string) bool
CanGetenv reports whether key is a valid go/env configuration key.
func DefaultCC(goos, goarch string) string
func DefaultCXX(goos, goarch string) string
func EnvFile() (string, bool, error)
EnvFile returns the name of the Go environment configuration file, and reports whether the effective value differs from the default.
func EnvOrAndChanged(name, def string) (v string, changed bool)
EnvOrAndChanged returns the environment variable value and reports whether it differs from the default value.
func ForceHost()
ForceHost forces GOOS and GOARCH to runtime.GOOS and runtime.GOARCH. This is used by go tool to build tools for the go command's own GOOS and GOARCH.
func GetArchEnv() (key, val string, changed bool)
GetArchEnv returns the name and setting of the GOARCH-specific architecture environment variable. If the current architecture has no GOARCH-specific variable, GetArchEnv returns empty key and value.
func Getenv(key string) string
Getenv gets the value for the configuration key. It consults the operating system environment and then the go/env file. If Getenv is called for a key that cannot be set in the go/env file (for example GODEBUG), it panics. This ensures that CanGetenv is accurate, so that 'go env -w' stays in sync with what Getenv can retrieve.
func SetGOROOT(goroot string, isTestGo bool)
SetGOROOT sets GOROOT and associated variables to the given values.
If isTestGo is true, build.ToolDir is set based on the TESTGO_GOHOSTOS and TESTGO_GOHOSTARCH environment variables instead of runtime.GOOS and runtime.GOARCH.
func ToolExeSuffix() string
ToolExeSuffix returns the suffix for executables installed in build.ToolDir.
func WithBuildXWriter(ctx context.Context, xLog io.Writer) context.Context
WithBuildXWriter returns a Context in which BuildX output is written to given io.Writer.
An EnvVar is an environment variable Name=Value.
type EnvVar struct {
Name string
Value string
Changed bool // effective Value differs from default
}