Documentation ¶
Overview ¶
Package compileopts contains the configuration for a single to-be-built binary.
Index ¶
- func MuslArchitecture(triple string) string
- type Config
- func (c *Config) ABI() string
- func (c *Config) AutomaticStackSize() bool
- func (c *Config) BinaryFormat(ext string) string
- func (c *Config) BuildTags() []string
- func (c *Config) CFlags() []string
- func (c *Config) CPU() string
- func (c *Config) CgoEnabled() bool
- func (c *Config) CodeModel() string
- func (c *Config) Debug() bool
- func (c *Config) DefaultBinaryExtension() string
- func (c *Config) DumpSSA() bool
- func (c *Config) Emulator(format, binary string) ([]string, error)
- func (c *Config) EmulatorFormat() (format, fileExt string)
- func (c *Config) EmulatorName() string
- func (c *Config) ExtraFiles() []string
- func (c *Config) Features() string
- func (c *Config) GC() string
- func (c *Config) GOARCH() string
- func (c *Config) GOARM() string
- func (c *Config) GOOS() string
- func (c *Config) LDFlags() []string
- func (c *Config) LibcPath(name string) (path string, precompiled bool)
- func (c *Config) NeedsStackObjects() bool
- func (c *Config) OpenOCDConfiguration() (args []string, err error)
- func (c *Config) OptLevels() (optLevel, sizeLevel int, inlinerThreshold uint)
- func (c *Config) PanicStrategy() string
- func (c *Config) Programmer() (method, openocdInterface string)
- func (c *Config) RP2040BootPatch() bool
- func (c *Config) RelocationModel() string
- func (c *Config) Scheduler() string
- func (c *Config) Serial() string
- func (c *Config) StackSize() uint64
- func (c *Config) Triple() string
- func (c *Config) VerifyIR() bool
- type Options
- type TargetSpec
- type TestConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MuslArchitecture ¶ added in v0.21.0
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
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
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
BinaryFormat returns an appropriate binary format, based on the file extension and the configured binary format in the target JSON file.
func (*Config) BuildTags ¶
BuildTags returns the complete list of build tags used during this build.
func (*Config) CFlags ¶
CFlags returns the flags to pass to the C compiler. This is necessary for CGo preprocessing.
func (*Config) CPU ¶
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
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) Debug ¶
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
DefaultBinaryExtension returns the default extension for binaries, such as .exe, .wasm, or no extension (depending on the target).
func (*Config) DumpSSA ¶
DumpSSA returns whether to dump Go SSA while compiling (-dumpssa flag). Only enable this for debugging.
func (*Config) Emulator ¶ added in v0.22.0
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
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
EmulatorName is a shorthand to get the command for this emulator, something like qemu-system-arm or simavr.
func (*Config) ExtraFiles ¶
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 ¶
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 ¶
GC returns the garbage collection strategy in use on this platform. Valid values are "none", "leaking", "conservative" and "precise".
func (*Config) GOARCH ¶
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
GOARM will return the GOARM environment variable given to the compiler when building a program.
func (*Config) GOOS ¶
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 ¶
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
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 ¶
NeedsStackObjects returns true if the compiler should insert stack objects that can be traced by the garbage collector.
func (*Config) OpenOCDConfiguration ¶
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
OptLevels returns the optimization level (0-2), size level (0-2), and inliner threshold as used in the LLVM optimization pipeline.
func (*Config) PanicStrategy ¶
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 ¶
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
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
RelocationModel returns the relocation model in use on this platform. Valid values are "static", "pic", "dynamicnopic".
func (*Config) Scheduler ¶
Scheduler returns the scheduler implementation. Valid values are "none", "asyncify" and "tasks".
func (*Config) Serial ¶ added in v0.19.0
Serial returns the serial implementation for this build configuration: uart, usb (meaning USB-CDC), or none.
func (*Config) StackSize ¶ added in v0.26.0
StackSize returns the default stack size to be used for goroutines, if the stack size could not be determined automatically at compile time.
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.
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.