Documentation
¶
Index ¶
- func AppendNativeBuildEnv(env []string) []string
- func BuildGoBinray(goroot string, flags []string, outputName string) (string, error)
- func BuildGoDebugBinary(goroot string) (string, error)
- func BuildGoToolCompileDebugBinary(goroot string) (string, error)
- func BuildNativeBinary(goroot string, dir string, flags []string, outputDir string, outputName string, ...) (string, error)
- func BuildToolBinray(goroot string, flags []string, arg string, outputName string) (string, error)
- func EnvForNative(env []string, goroot string) []string
- func ExternalLinkerFlags(goVersion *goinfo.GoVersion) []string
- func GetHostGOARCH() string
- func GetHostGOOS() string
- func GetTargetGOARCH() string
- func GetTargetGOOS() string
- func GetToolPath(goroot string) (string, error)
- func MakeGorootEnv(env []string, goroot string) []string
- func NeedExternalLinker(goVersion *goinfo.GoVersion) bool
- func RebuildGoBinary(goroot string, goVersion *goinfo.GoVersion) error
- func RebuildGoToolCompile(goroot string, goVersion *goinfo.GoVersion) error
- func RebuildGoToolCover(goroot string, goVersion *goinfo.GoVersion) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendNativeBuildEnv ¶
this ensure we do not build cross-platform while building native binary
func BuildGoBinray ¶ added in v1.1.4
func BuildGoDebugBinary ¶ added in v1.1.4
debug
func BuildGoToolCompileDebugBinary ¶ added in v1.1.4
func BuildNativeBinary ¶ added in v1.1.3
func BuildToolBinray ¶ added in v1.1.4
func EnvForNative ¶ added in v1.1.3
see https://github.com/xhd2015/xgo/issues/320 the GOEXPERIMENT,GOOS and GOARCH could affect building process. we make a fresh env
func ExternalLinkerFlags ¶ added in v1.2.0
func GetHostGOARCH ¶ added in v1.2.0
func GetHostGOARCH() string
GetHostGOARCH returns the architecture of the machine running the current process. This is always runtime.GOARCH.
Example: on an Apple Silicon Mac, this returns "arm64".
func GetHostGOOS ¶ added in v1.2.0
func GetHostGOOS() string
GetHostGOOS returns the OS of the machine running the current process (the compiler host). This is always runtime.GOOS.
Example: on an Apple Silicon Mac, this returns "darwin".
func GetTargetGOARCH ¶ added in v1.2.0
func GetTargetGOARCH() string
GetTargetGOARCH returns the architecture that the compiled binary will run on. If the GOARCH env var is set, that value is returned; otherwise falls back to GetHostGOARCH().
Unlike GOOS, cross-compiling GOARCH within the same OS is usually supported (e.g. darwin/arm64 host → darwin/amd64 target using the macOS linker). This distinction is important when choosing linker flags.
func GetTargetGOOS ¶ added in v1.2.0
func GetTargetGOOS() string
GetTargetGOOS returns the OS that the compiled binary will run on. If the GOOS env var is set, that value is returned; otherwise falls back to GetHostGOOS().
Host vs target matters for cross-compilation. For example, when compiling on a macOS host for a Linux target (GOOS=linux), the macOS system linker (clang/ld) cannot produce Linux binaries — so build flags like -linkmode=external must only be used for darwin targets.
func MakeGorootEnv ¶
MakeGorootEnv makes a new env with GOROOT and PATH set
func NeedExternalLinker ¶ added in v1.2.0
NeedExternalLinker reports whether binaries should be built with -linkmode=external on the current host for the current target.
On macOS 26+ (arm64), dyld requires all executables to have an LC_UUID load command. The Go internal linker added LC_UUID emission in Go 1.22.9 / 1.23.3 / 1.24+. For older Go versions, we use -linkmode=external to invoke the system linker (clang/ld), which always emits LC_UUID.
Empirically, go1.22.12 (which should include the 1.22.9 backport) still produces binaries without LC_UUID on some systems. To be safe, we apply external linking for all Go versions below 1.23.
External linking only works when the target OS matches the host OS (both darwin). When cross-compiling to e.g. linux, the macOS system linker cannot produce the target binary, so this returns false.
See: https://github.com/golang/go/issues/68678, #78012
func RebuildGoBinary ¶ added in v1.1.4
func RebuildGoToolCompile ¶ added in v1.1.4
Types ¶
This section is empty.