build

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendNativeBuildEnv

func AppendNativeBuildEnv(env []string) []string

this ensure we do not build cross-platform while building native binary

func BuildGoBinray added in v1.1.4

func BuildGoBinray(goroot string, flags []string, outputName string) (string, error)

func BuildGoDebugBinary added in v1.1.4

func BuildGoDebugBinary(goroot string) (string, error)

debug

func BuildGoToolCompileDebugBinary added in v1.1.4

func BuildGoToolCompileDebugBinary(goroot string) (string, error)

func BuildNativeBinary added in v1.1.3

func BuildNativeBinary(goroot string, dir string, flags []string, outputDir string, outputName string, arg string) (string, error)

func BuildToolBinray added in v1.1.4

func BuildToolBinray(goroot string, flags []string, arg string, outputName string) (string, error)

func EnvForNative added in v1.1.3

func EnvForNative(env []string, goroot string) []string

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 ExternalLinkerFlags(goVersion *goinfo.GoVersion) []string

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.

See: https://pkg.go.dev/cmd/go#hdr-Environment_variables

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.

See: https://pkg.go.dev/cmd/go#hdr-Environment_variables

func GetToolPath

func GetToolPath(goroot string) (string, error)

$GOROOT/pkg/tool/linux_amd64

func MakeGorootEnv

func MakeGorootEnv(env []string, goroot string) []string

MakeGorootEnv makes a new env with GOROOT and PATH set

func NeedExternalLinker added in v1.2.0

func NeedExternalLinker(goVersion *goinfo.GoVersion) bool

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 RebuildGoBinary(goroot string, goVersion *goinfo.GoVersion) error

func RebuildGoToolCompile added in v1.1.4

func RebuildGoToolCompile(goroot string, goVersion *goinfo.GoVersion) error

func RebuildGoToolCover added in v1.1.4

func RebuildGoToolCover(goroot string, goVersion *goinfo.GoVersion) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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