golang

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package golang provides spell incantations for Go toolchain commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompileFormula

func CompileFormula(opts ...Option) []string

CompileFormula compiles the formula for shared Go toolchain command options.

Types

type MixinImproveDebugging

type MixinImproveDebugging struct{}

MixinImproveDebugging is a spell.Mixin for golang.Options to add linker flags to improve the debugging of binary artifacts. This includes the disabling of inlining and all compiler optimizations tp improve the compatibility for debuggers.

Note that this mixin adds the "all" prefix for "-gcflags" parameters to make sure all packages are affected. If you disabled the "all" prefix on purpose you need to handle this conflict on your own, e.g. by creating more than one binary artifact each with different build options.

Run `go help build`, `go tool compile -help` for the documentation of supported flags. See the official Go documentations and other resources for more details:

func (MixinImproveDebugging) Apply

Apply applies the mixin to the given spell.Options that must be of type golang.Options.

type MixinImproveEscapeAnalysis

type MixinImproveEscapeAnalysis struct{}

MixinImproveEscapeAnalysis is a spell.Mixin for golang.Options to add linker flags to improve the escape analysis of binary artifacts. Enables 2/4 level for reporting verbosity, higher levels are too noisy and rarely necessary.

Note that this mixin removes the "all" prefix for "-gcflags" parameters to make sure only the target package is affected, otherwise reports for (traverse) dependencies would be included as well. If you enabled the "all" prefix on purpose you need to handle this conflict on your own, e.g. by creating more than one binary artifact each with different build options.

Run `go help build`, `go tool compile -help` for the documentation of supported flags. See the official Go documentations and other resources for more details:

func (MixinImproveEscapeAnalysis) Apply

Apply applies the mixin to the given spell.Options that must be of type golang.Options.

type MixinInjectBuildTimeVariableValues

type MixinInjectBuildTimeVariableValues struct {
	// Data is the map of key/value pairs to inject to variables at build-time.
	// The key must be the path to the variable in form of "<IMPORT_PATH>.<VARIABLE_NAME>",
	// e.g. "pkg/internal/support/app.version".
	// The value is the actual value that will be assigned to the variable, e.g. the application version.
	Data map[string]string

	// GoModuleID is the ID of the target Go module to inject the given key/value pairs into.
	GoModuleID *project.GoModuleID
}

MixinInjectBuildTimeVariableValues is a spell.Mixin for golang.Options to inject build-time values through the `-X` linker flags to populate e.g. application metadata variables.

See `go help build`, `go tool compile -help` and the `go` command documentations for more details:

func (MixinInjectBuildTimeVariableValues) Apply

Apply applies the mixin to the given spell.Options that must be of type golang.Options.

type MixinStripDebugMetadata

type MixinStripDebugMetadata struct{}

MixinStripDebugMetadata is a spell.Mixin for golang.Options to add linker flags to strip debug information from binary artifacts. This includes DWARF tables needed for debuggers, but keeps annotations needed for stack traces so panics are still readable. It also shrinks the file size and memory overhead as well as reducing the chance for possible security related problems due to enabled development features or debug information leaks.

Run `go tool compile -help`, `go doc cmd/link` for the documentation of supported flags.

See the official Go documentations and other resources for more details:

Note that this mixin adds the "all" prefix for "-gcflags" parameters to make sure all packages are affected If you disabled the "all" prefix on purpose you need to handle this conflict on your own, e.g. by creating more than one binary artifact each with different build options.

See `go help build`, `go tool compile -help` and the `go` command documentations for more details:

A subsequent optimization could be the usage of UPX (https://github.com/upx/upx) to compress the binary artifact afterwards.

func (MixinStripDebugMetadata) Apply

Apply applies the mixin to the given spell.Options that must be of type golang.Options.

type Option

type Option func(*Options)

Option is a pencil option.

func WithAsmFlags

func WithAsmFlags(asmFlags ...string) Option

WithAsmFlags sets flags to pass on each `go tool asm` invocation.

See `go help buildmode`, `go help build` and the `go` command documentations for more details:

func WithEnv

func WithEnv(env map[string]string) Option

WithEnv adds or overrides Go toolchain command specific environment variables.

func WithFlags

func WithFlags(flags ...string) Option

WithFlags sets additional Go toolchain command flags.

See `go help build` and the `go` command documentations for more details:

func WithFlagsPrefixAll

func WithFlagsPrefixAll(flagsPrefixAll bool) Option

WithFlagsPrefixAll indicates whether the values of `-asmflags` and `-gcflags` should be prefixed with the `all=` pattern in order to apply to all packages. As of Go 1.10 (https://golang.org/doc/go1.10#build), the value specified to `-asmflags` and `-gcflags` are only applied to the current package, therefore the `all=` pattern is used to apply the flag to all packages.

See `go help build` and the `go` command documentations for more details:

func WithGcFlags

func WithGcFlags(gcFlags ...string) Option

WithGcFlags sets flags to pass on each `go tool compile` invocation.

See `go help buildmode`, `go help build` and the `go` command documentations for more details:

func WithLdFlags

func WithLdFlags(ldFlags ...string) Option

WithLdFlags sets flags to pass on each `go tool link` invocation.

See `go help buildmode`, `go help build` and the `go` command documentations for more details:

func WithMixins

func WithMixins(mixins ...spell.Mixin) Option

WithMixins sets spell mixins that can be applied by option consumers.

func WithRaceDetector

func WithRaceDetector(enableRaceDetector bool) Option

WithRaceDetector indicates whether the race detector should be enabled.

See `go help build` and the `go` command documentations for more details:

func WithTags

func WithTags(tags ...string) Option

WithTags sets Go toolchain tags.

See `go help build` and the `go` command documentations for more details:

func WithTrimmedPath

func WithTrimmedPath(enableTrimPath bool) Option

WithTrimmedPath indicates whether all file system paths should be removed from the resulting executable. This is done by adding compiler and linker flags to remove the absolute path to the project root directory from binary artifacts.

See `go help build` and the `go` command documentations for more details:

type Options

type Options struct {
	// AsmFlags are the arguments for the `-asmflags` flag that are passed to each `go tool asm` invocation.
	//
	// See `go help buildmode`, `go help build` and the `go` command documentations for more details:
	//   - https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies
	AsmFlags []string

	// EnableRaceDetector indicates whether the race detector should be enabled.
	//
	// See `go help build` and the `go` command documentations for more details:
	//   - https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies
	//   - https://golang.org/cmd/go/#hdr-Testing_flags
	EnableRaceDetector bool

	// EnableTrimPath indicates whether all file system paths should be removed from the resulting executable.
	// This is done by adding compiler and linker flags to remove the absolute path to the project root directory from
	// binary artifacts.
	//
	// See `go help build` and the `go` command documentations for more details:
	//   - https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies
	//   - https://golang.org/doc/go1.13#go-command
	EnableTrimPath bool

	// Env are Go toolchain command specific environment variables.
	Env map[string]string

	// Flags are additional flags passed to the `go` command.
	//
	// See `go help build` and the `go` command documentations for more details:
	//   - https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies
	Flags []string

	// FlagsPrefixAll indicates whether the values of `-asmflags` and `-gcflags` should be prefixed with the `all=`
	// pattern in order to apply to all packages.
	// As of Go 1.10 (https://golang.org/doc/go1.10#build), the value specified to `-asmflags` and `-gcflags` are only
	// applied to the current package, therefore the `all=` pattern is used to apply the flag to all packages.
	//
	// See `go help build` and the `go` command documentations for more details:
	//   - https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies
	//   - https://golang.org/doc/go1.10#build
	FlagsPrefixAll bool

	// GcFlags are the arguments for the `-gcflags` flag that are passed to each `go tool compile` invocation.
	//
	// See `go help buildmode`, `go help build` and the `go` command documentations for more details:
	//   - https://golang.org/cmd/go/#hdr-Build_modes
	//   - https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies
	GcFlags []string

	// LdFlags are the arguments for the `-ldflags` flag that are passed to each `go tool link` invocation.
	//
	// See `go help buildmode`, `go help build` and the `go` command documentations for more details:
	//   - https://golang.org/cmd/go/#hdr-Build_modes
	//   - https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies
	LdFlags []string

	// Tags are the Go tags.
	//
	// See `go help build` and the `go` command documentations for more details:
	//   - https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies
	Tags []string
	// contains filtered or unexported fields
}

Options are shared Go toolchain commands options.

References

- https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies

func NewOptions

func NewOptions(opts ...Option) *Options

NewOptions creates new shared Go toolchain command options.

Directories

Path Synopsis
Package build provides a spell incantation for the "build" command of the Go toolchain.
Package build provides a spell incantation for the "build" command of the Go toolchain.
Package test provide a spell incantation for the "test" command of the Go toolchain.
Package test provide a spell incantation for the "test" command of the Go toolchain.

Jump to

Keyboard shortcuts

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