compileopts

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: BSD-3-Clause Imports: 14 Imported by: 1

Documentation

Overview

Package compileopts contains the configuration for a single to-be-built binary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MuslArchitecture added in v0.21.0

func MuslArchitecture(triple string) string

MuslArchitecture returns the architecture name as used in musl libc. It is usually the same as the first part of the LLVM triple, but not always.

Types

type Config

type Config struct {
	Options        *Options
	Target         *TargetSpec
	GoMinorVersion int
	ClangHeaders   string // Clang built-in header include path
	TestConfig     TestConfig
}

Config keeps all configuration affecting the build in a single struct.

func (*Config) ABI added in v0.27.0

func (c *Config) ABI() string

ABI returns the -mabi= flag for this target (like -mabi=lp64). A zero-length string is returned if the target doesn't specify an ABI.

func (*Config) AutomaticStackSize added in v0.15.0

func (c *Config) AutomaticStackSize() bool

AutomaticStackSize returns whether goroutine stack sizes should be determined automatically at compile time, if possible. If it is false, no attempt is made.

func (*Config) BinaryFormat added in v0.15.0

func (c *Config) BinaryFormat(ext string) string

BinaryFormat returns an appropriate binary format, based on the file extension and the configured binary format in the target JSON file.

func (*Config) BuildTags

func (c *Config) BuildTags() []string

BuildTags returns the complete list of build tags used during this build.

func (*Config) CFlags

func (c *Config) CFlags() []string

CFlags returns the flags to pass to the C compiler. This is necessary for CGo preprocessing.

func (*Config) CPU

func (c *Config) CPU() string

CPU returns the LLVM CPU name, like atmega328p or arm7tdmi. It may return an empty string if the CPU name is not known.

func (*Config) CgoEnabled added in v0.12.0

func (c *Config) CgoEnabled() bool

CgoEnabled returns true if (and only if) CGo is enabled. It is true by default and false if CGO_ENABLED is set to "0".

func (*Config) CodeModel added in v0.14.0

func (c *Config) CodeModel() string

CodeModel returns the code model used on this platform.

func (*Config) Debug

func (c *Config) Debug() bool

Debug returns whether debug (DWARF) information should be retained by the linker. By default, debug information is retained, but it can be removed with the -no-debug flag.

func (*Config) DefaultBinaryExtension added in v0.23.0

func (c *Config) DefaultBinaryExtension() string

DefaultBinaryExtension returns the default extension for binaries, such as .exe, .wasm, or no extension (depending on the target).

func (*Config) DumpSSA

func (c *Config) DumpSSA() bool

DumpSSA returns whether to dump Go SSA while compiling (-dumpssa flag). Only enable this for debugging.

func (*Config) Emulator added in v0.22.0

func (c *Config) Emulator(format, binary string) ([]string, error)

Emulator returns a ready-to-run command to run the given binary in an emulator. Give it the format (returned by EmulatorFormat()) and the path to the compiled binary.

func (*Config) EmulatorFormat added in v0.23.0

func (c *Config) EmulatorFormat() (format, fileExt string)

EmulatorFormat returns the binary format for the emulator and the associated file extension. An empty string means to pass directly whatever the linker produces directly without conversion (usually ELF format).

func (*Config) EmulatorName added in v0.23.0

func (c *Config) EmulatorName() string

EmulatorName is a shorthand to get the command for this emulator, something like qemu-system-arm or simavr.

func (*Config) ExtraFiles

func (c *Config) ExtraFiles() []string

ExtraFiles returns the list of extra files to be built and linked with the executable. This can include extra C and assembly files.

func (*Config) Features

func (c *Config) Features() string

Features returns a list of features this CPU supports. For example, for a RISC-V processor, that could be "+a,+c,+m". For many targets, an empty list will be returned.

func (*Config) GC

func (c *Config) GC() string

GC returns the garbage collection strategy in use on this platform. Valid values are "none", "leaking", "conservative" and "precise".

func (*Config) GOARCH

func (c *Config) GOARCH() string

GOARCH returns the GOARCH of the target. This might not always be the actual archtecture: for example, the AVR target is not supported by the Go standard library so such targets will usually pretend to be linux/arm.

func (*Config) GOARM added in v0.21.0

func (c *Config) GOARM() string

GOARM will return the GOARM environment variable given to the compiler when building a program.

func (*Config) GOOS

func (c *Config) GOOS() string

GOOS returns the GOOS of the target. This might not always be the actual OS: for example, bare-metal targets will usually pretend to be linux to get the standard library to compile.

func (*Config) LDFlags

func (c *Config) LDFlags() []string

LDFlags returns the flags to pass to the linker. A few more flags are needed (like the one for the compiler runtime), but this represents the majority of the flags.

func (*Config) LibcPath added in v0.21.0

func (c *Config) LibcPath(name string) (path string, precompiled bool)

LibcPath returns the path to the libc directory. The libc path will be either a precompiled libc shipped with a TinyGo build, or a libc path in the cache directory (which might not yet be built).

func (*Config) NeedsStackObjects

func (c *Config) NeedsStackObjects() bool

NeedsStackObjects returns true if the compiler should insert stack objects that can be traced by the garbage collector.

func (*Config) OpenOCDConfiguration

func (c *Config) OpenOCDConfiguration() (args []string, err error)

OpenOCDConfiguration returns a list of command line arguments to OpenOCD. This list of command-line arguments is based on the various OpenOCD-related flags in the target specification.

func (*Config) OptLevels added in v0.18.0

func (c *Config) OptLevels() (optLevel, sizeLevel int, inlinerThreshold uint)

OptLevels returns the optimization level (0-2), size level (0-2), and inliner threshold as used in the LLVM optimization pipeline.

func (*Config) PanicStrategy

func (c *Config) PanicStrategy() string

PanicStrategy returns the panic strategy selected for this target. Valid values are "print" (print the panic value, then exit) or "trap" (issue a trap instruction).

func (*Config) Programmer

func (c *Config) Programmer() (method, openocdInterface string)

Programmer returns the flash method and OpenOCD interface name given a particular configuration. It may either be all configured in the target JSON file or be modified using the -programmmer command-line option.

func (*Config) RP2040BootPatch added in v0.19.0

func (c *Config) RP2040BootPatch() bool

RP2040BootPatch returns whether the RP2040 boot patch should be applied that calculates and patches in the checksum for the 2nd stage bootloader.

func (*Config) RelocationModel added in v0.14.0

func (c *Config) RelocationModel() string

RelocationModel returns the relocation model in use on this platform. Valid values are "static", "pic", "dynamicnopic".

func (*Config) Scheduler

func (c *Config) Scheduler() string

Scheduler returns the scheduler implementation. Valid values are "none", "asyncify" and "tasks".

func (*Config) Serial added in v0.19.0

func (c *Config) Serial() string

Serial returns the serial implementation for this build configuration: uart, usb (meaning USB-CDC), or none.

func (*Config) StackSize added in v0.26.0

func (c *Config) StackSize() uint64

StackSize returns the default stack size to be used for goroutines, if the stack size could not be determined automatically at compile time.

func (*Config) Triple

func (c *Config) Triple() string

Triple returns the LLVM target triple, like armv6m-unknown-unknown-eabi.

func (*Config) VerifyIR

func (c *Config) VerifyIR() bool

VerifyIR returns whether to run extra checks on the IR. This is normally disabled but enabled during testing.

type Options

type Options struct {
	GOOS            string // environment variable
	GOARCH          string // environment variable
	GOARM           string // environment variable (only used with GOARCH=arm)
	Target          string
	Opt             string
	GC              string
	PanicStrategy   string
	Scheduler       string
	StackSize       uint64 // goroutine stack size (if none could be automatically determined)
	Serial          string
	Work            bool // -work flag to print temporary build directory
	InterpTimeout   time.Duration
	PrintIR         bool
	DumpSSA         bool
	VerifyIR        bool
	SkipDWARF       bool
	PrintCommands   func(cmd string, args ...string) `json:"-"`
	Semaphore       chan struct{}                    `json:"-"` // -p flag controls cap
	Debug           bool
	PrintSizes      string
	PrintAllocs     *regexp.Regexp // regexp string
	PrintStacks     bool
	Tags            []string
	GlobalValues    map[string]map[string]string // map[pkgpath]map[varname]value
	TestConfig      TestConfig
	Programmer      string
	OpenOCDCommands []string
	LLVMFeatures    string
	Directory       string
	PrintJSON       bool
	Monitor         bool
	BaudRate        int
	Timeout         time.Duration
}

Options contains extra options to give to the compiler. These options are usually passed from the command line, but can also be passed in environment variables for example.

func (*Options) Verify added in v0.14.0

func (o *Options) Verify() error

Verify performs a validation on the given options, raising an error if options are not valid.

type TargetSpec

type TargetSpec struct {
	Inherits         []string `json:"inherits,omitempty"`
	Triple           string   `json:"llvm-target,omitempty"`
	CPU              string   `json:"cpu,omitempty"`
	ABI              string   `json:"target-abi,omitempty"` // rougly equivalent to -mabi= flag
	Features         string   `json:"features,omitempty"`
	GOOS             string   `json:"goos,omitempty"`
	GOARCH           string   `json:"goarch,omitempty"`
	BuildTags        []string `json:"build-tags,omitempty"`
	GC               string   `json:"gc,omitempty"`
	Scheduler        string   `json:"scheduler,omitempty"`
	Serial           string   `json:"serial,omitempty"` // which serial output to use (uart, usb, none)
	Linker           string   `json:"linker,omitempty"`
	RTLib            string   `json:"rtlib,omitempty"` // compiler runtime library (libgcc, compiler-rt)
	Libc             string   `json:"libc,omitempty"`
	AutoStackSize    *bool    `json:"automatic-stack-size,omitempty"` // Determine stack size automatically at compile time.
	DefaultStackSize uint64   `json:"default-stack-size,omitempty"`   // Default stack size if the size couldn't be determined at compile time.
	CFlags           []string `json:"cflags,omitempty"`
	LDFlags          []string `json:"ldflags,omitempty"`
	LinkerScript     string   `json:"linkerscript,omitempty"`
	ExtraFiles       []string `json:"extra-files,omitempty"`
	RP2040BootPatch  *bool    `json:"rp2040-boot-patch,omitempty"` // Patch RP2040 2nd stage bootloader checksum
	Emulator         string   `json:"emulator,omitempty"`
	FlashCommand     string   `json:"flash-command,omitempty"`
	GDB              []string `json:"gdb,omitempty"`
	PortReset        string   `json:"flash-1200-bps-reset,omitempty"`
	SerialPort       []string `json:"serial-port,omitempty"` // serial port IDs in the form "vid:pid"
	FlashMethod      string   `json:"flash-method,omitempty"`
	FlashVolume      []string `json:"msd-volume-name,omitempty"`
	FlashFilename    string   `json:"msd-firmware-name,omitempty"`
	UF2FamilyID      string   `json:"uf2-family-id,omitempty"`
	BinaryFormat     string   `json:"binary-format,omitempty"`
	OpenOCDInterface string   `json:"openocd-interface,omitempty"`
	OpenOCDTarget    string   `json:"openocd-target,omitempty"`
	OpenOCDTransport string   `json:"openocd-transport,omitempty"`
	OpenOCDCommands  []string `json:"openocd-commands,omitempty"`
	OpenOCDVerify    *bool    `json:"openocd-verify,omitempty"` // enable verify when flashing with openocd
	JLinkDevice      string   `json:"jlink-device,omitempty"`
	CodeModel        string   `json:"code-model,omitempty"`
	RelocationModel  string   `json:"relocation-model,omitempty"`
}

Target specification for a given target. Used for bare metal targets.

The target specification is mostly inspired by Rust: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target/spec/struct.TargetOptions.html https://github.com/shepmaster/rust-arduino-blink-led-no-core-with-cargo/blob/master/blink/arduino.json

func LoadTarget

func LoadTarget(options *Options) (*TargetSpec, error)

Load a target specification.

func (*TargetSpec) LookupGDB added in v0.18.0

func (spec *TargetSpec) LookupGDB() (string, error)

LookupGDB looks up a gdb executable.

type TestConfig

type TestConfig struct {
	CompileTestBinary bool
	CompileOnly       bool
	Verbose           bool
	Short             bool
	RunRegexp         string
	SkipRegexp        string
	Count             *int
	BenchRegexp       string
	BenchTime         string
	BenchMem          bool
	Shuffle           string
}

Jump to

Keyboard shortcuts

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