build

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 93 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTestFailed = errors.New("test failed")

ErrTestFailed reports tests whose package results have already been printed. Return it instead of exiting inside Build so temporary coverage files are cleaned up before the command chooses its exit status and final summary.

Functions

func Clean

func Clean(patterns []string, conf *Config) error

func DefaultBuildTags

func DefaultBuildTags() string

DefaultBuildTags returns the build tags LLGo always enables.

func IsFullRpathEnabled

func IsFullRpathEnabled() bool

func IsFuncInfoEnabled

func IsFuncInfoEnabled() bool

func IsFuncInfoSitesEnabled

func IsFuncInfoSitesEnabled() bool

IsFuncInfoSitesEnabled controls the body-embedded site records independently of the funcinfo tables (LLGO_FUNCINFO_SITES=0 keeps the metadata but drops entry and PC-line inline-asm sites). Useful for isolating codegen perturbation caused by the in-body asm anchors.

func IsOptimizeEnabled

func IsOptimizeEnabled() bool

func IsStdioNobuf

func IsStdioNobuf() bool

func IsTraceEnabled

func IsTraceEnabled() bool

func Plan9ASMPkgs

func Plan9ASMPkgs() string

func RunnerExitCode added in v1.0.7

func RunnerExitCode(err error) (int, bool)

RunnerExitCode reports a guest program's exit status from llgo run. Setup, timeout, and test-runner failures are host errors and keep the CLI's status 1.

func ValidateBuildMode

func ValidateBuildMode(mode string) error

ValidateBuildMode checks if the build mode is valid

func WasmRuntime

func WasmRuntime() string

Types

type Artifact added in v1.0.7

type Artifact struct {
	Role   ArtifactRole
	Format string
	Path   string
	Size   int64
}

Artifact describes one final build output. Size is the on-disk byte size; deployment formats therefore remain distinct from their host debug image.

func CollectArtifacts added in v1.0.7

func CollectArtifacts(conf *Config, out *OutFmtDetails) ([]Artifact, error)

CollectArtifacts returns the final artifacts represented by out. It should be called after post-link packaging and target format conversion complete.

type ArtifactRole added in v1.0.7

type ArtifactRole string

ArtifactRole distinguishes debugger-owned metadata from bytes delivered to a target and from optional runtime symbolization data.

const (
	ArtifactRoleDebug           ArtifactRole = "debug"
	ArtifactRoleDeployment      ArtifactRole = "deployment"
	ArtifactRoleDebugDeployment ArtifactRole = "debug+deployment"
	ArtifactRoleRuntimeSymbols  ArtifactRole = "runtime-symbols"
)

type BuildMode

type BuildMode string
const (
	BuildModeExe      BuildMode = "exe"
	BuildModeCArchive BuildMode = "c-archive"
	BuildModeCShared  BuildMode = "c-shared"
)

type Config

type Config struct {
	Goos               string
	Goarch             string
	GO386              string // 386 floating-point implementation: sse2 or softfloat
	GOAMD64            string // amd64 microarchitecture level: v1 through v4
	GOARM              string // arm architecture and floating-point implementation
	GOARM64            string // arm64 ISA version and optional lse/crypto extensions
	GOEXPERIMENT       string // Go experiments; empty inherits cmd/go configuration, "none" disables defaults
	Target             string // target name (e.g., "rp2040", "wasi") - takes precedence over Goos/Goarch
	OptLevel           optlevel.Level
	LTO                lto.Mode
	LTOPlugin          lto.PassPlugin
	BinPath            string
	AppExt             string  // ".exe" on Windows, empty on Unix
	OutFile            string  // output file, or directory for ModeBuild package executables
	OutFmts            OutFmts // Output format specifications (only for Target != "")
	CompileOnly        bool    // compile test binary but do not run it (only valid for ModeTest)
	RetainTestBinary   bool    // profiling keeps the test executable in the invocation directory
	Emulator           bool    // run in emulator mode
	Port               string  // target port for flashing
	BaudRate           int     // baudrate for serial communication
	RunArgs            []string
	Exec               []string      // Explicit execution wrapper, before the artifact and RunArgs.
	RunnerTimeout      time.Duration // Host execution limit; zero disables it.
	Mode               Mode
	BuildMode          BuildMode // Build mode: exe, c-archive, c-shared
	GenExpect          bool      // only valid for ModeCmpTest
	Verbose            bool
	PrintPackages      bool // print package paths after successful compilation
	PrintCommands      bool
	GenLL              bool // generate pkg .ll files
	DeadcodeDrop       bool // enable Go dead code drop (development builds only)
	CollectPackageMeta bool // collect package metadata without enabling dead code drop
	CheckLLFiles       bool // check .ll files valid
	CheckLinkArgs      bool // check linkargs valid
	ForceEspClang      bool // force to use esp-clang
	ForceRebuild       bool // force rebuilding of packages that are already up-to-date
	Tags               string
	SizeReport         bool   // print size report after successful build
	SizeFormat         string // size report format: text,json (default text)
	SizeLevel          string // size aggregation level: full,module,package (default module)
	CompilerHash       string // metadata hash for the running compiler (development builds only)
	GoVersion          string // Go language version accepted by the frontend (for example, "go1.22")
	NoErrorColumn      bool   // omit source columns from frontend diagnostics
	// GoBuildFlags contains normalized raw Go build flags forwarded to
	// go/packages. Callers use internal/goflags to parse supported compiler and
	// linker semantics into typed Config fields before calling Do.
	GoBuildFlags []string
	// GoFlagsParsed means the command layer has consumed GOFLAGS into native
	// configuration. Package probes must not parse those command defaults again.
	GoFlagsParsed bool
	// BuildParallelism is the package-build, test-link, and test-run concurrency
	// requested by Go's -p build flag. Zero uses the Go default, GOMAXPROCS.
	BuildParallelism int
	// BuildTrace is an optional Chrome Trace Event JSON output path. Relative
	// paths are resolved from the build invocation directory.
	BuildTrace string
	// TestRunSequential disables concurrent test binary execution when test
	// flags share output paths or otherwise require one active binary.
	TestRunSequential bool
	// TestFailFast stops launching test binaries after the first failure.
	TestFailFast bool
	// TestJSON streams package-attributed test2json events.
	TestJSON bool

	LinkOptions       LinkOptions
	DebugArtifactMode DebugArtifactMode
	// DebugArtifactModeSet distinguishes an explicit mode from the build default.
	DebugArtifactModeSet bool

	// OmitDWARFByDefault controls linked builds only when -w was not
	// explicitly specified. Explicit -w and -w=false always win.
	OmitDWARFByDefault bool
	PCLNMode           PCLNMode
	// PCLNModeSet marks PCLNMode as authoritative. Command flags set it for
	// explicit requests; Do sets it after resolving the legacy environment
	// default.
	PCLNModeSet bool
	AllowNoBody bool // allow declarations without bodies, as go tool compile does
	// DisableBoundsChecks disables index, slice, and slice-to-array conversion
	// bounds checks while retaining required integer conversions and nil checks.
	DisableBoundsChecks bool
	// SaturatingFloatToInt enables Go's experimental converthash behavior
	// for float-to-integer conversions.
	SaturatingFloatToInt bool

	// PthreadStackSize sets a custom stack size, in bytes, for native and Wasm
	// goroutines. A zero value keeps the backend's default.
	PthreadStackSize int64
	// PthreadStackSizeSet marks PthreadStackSize as explicitly requested. It
	// keeps an explicit value, including zero, from being replaced by the
	// host-only test default.
	PthreadStackSizeSet bool

	// DisableGoGlobalDCE disables Go-specific global DCE metadata emission
	// when it would otherwise be enabled by full LTO.
	DisableGoGlobalDCE bool

	// GlobalRewrites specifies compile-time overrides for global string variables.
	// Keys are fully qualified package paths (e.g. "main" or "github.com/user/pkg").
	// Each Rewrites entry maps variable names to replacement string values. Only
	// string-typed globals are supported and "main" applies to all root main
	// packages in the current build.
	GlobalRewrites map[string]Rewrites
	ModuleHook     ModuleHook
	Overlay        map[string][]byte
	// SourceOverlay contains absolute paths from the public -overlay JSON.
	// The Go loader and LLGo parser share this view, including file deletions.
	SourceOverlay map[string]SourceOverlayFile

	// TestPythonPackage supplies the synthetic Python ABI root used by compiler
	// fixtures that intentionally avoid importing github.com/goplus/lib/py.
	// Production callers leave this nil; the provider is evaluated once per Do.
	TestPythonPackage func() *types.Package

	// Coverage enables source coverage for builds/tests. Nil leaves the build
	// unchanged; coverage holds only per-invocation temporary state.
	Coverage *CoverageConfig
	// contains filtered or unexported fields
}

func NewDefaultConf

func NewDefaultConf(mode Mode) *Config

type CoverageConfig added in v1.0.5

type CoverageConfig struct {
	Mode      string
	Packages  string
	Profile   string
	OutputDir string
}

CoverageConfig describes Go's source coverage for builds and tests. A non-nil configuration enables coverage; Mode defaults to set. Profile and OutputDir are test-only; application binaries use GOCOVERDIR at execution time.

type DWARFCompressionMode added in v1.0.8

type DWARFCompressionMode uint8

DWARFCompressionMode distinguishes platform defaults from an explicit -compressdwarf request. Mach-O/PE compression is experimental and opt-in.

const (
	DWARFCompressionDefault DWARFCompressionMode = iota
	DWARFCompressionEnabled
	DWARFCompressionDisabled
)

type DWARFMode

type DWARFMode uint8

DWARFMode records whether the command layer requested that the backend preserve or omit DWARF. DWARFDefault leaves the decision to other link options.

const (
	DWARFDefault DWARFMode = iota
	DWARFPreserve
	DWARFOmit
)

type DebugArtifactMode added in v1.0.7

type DebugArtifactMode uint8

DebugArtifactMode controls where debugger-owned DWARF is packaged. It is independent of runtime pclntab packaging.

const (
	// DebugArtifactDefault derives the effective mode from -w and the current
	// build default. It is valid only before build configuration is resolved.
	DebugArtifactDefault DebugArtifactMode = iota
	// DebugArtifactEmbedded retains DWARF in a Wasm module. Native builds only
	// request DWARF preservation and use the platform toolchain's default
	// packaging; a self-contained executable is not guaranteed.
	DebugArtifactEmbedded
	// DebugArtifactExternal writes a debugger-owned sidecar referenced by the
	// executable or module.
	DebugArtifactExternal
	// DebugArtifactHost retains a full host-side debug executable and derives a
	// separate deployment image from it.
	DebugArtifactHost
	// DebugArtifactNone omits LLGo DWARF, equivalent to an effective -w.
	DebugArtifactNone
)

func (DebugArtifactMode) IsValid added in v1.0.7

func (m DebugArtifactMode) IsValid() bool

IsValid reports whether m is a recognized debug-artifact mode.

func (DebugArtifactMode) String added in v1.0.7

func (m DebugArtifactMode) String() string

type Invocation

type Invocation struct {
	Args   []string
	Config *Config
	Dir    string
	// contains filtered or unexported fields
}

Invocation contains the explicit inputs used by one build. An empty Dir uses the working directory captured when Build starts. Build inherits one snapshot of the process environment; per-invocation overrides are not supported.

type LinkOptions

type LinkOptions struct {
	// OmitSymbolTable implements -s for native ELF/Mach-O linked outputs,
	// after runtime PCLN has consumed the linker's ordinary symbols.
	OmitSymbolTable bool
	DWARF           DWARFMode
	// Native Linux links compress retained DWARF by default. Other native
	// formats require an explicit -compressdwarf=true request.
	DWARFCompression DWARFCompressionMode
	// ExternalLinker and ExternalLinkerFlags retain the Go linker's -extld
	// command and -extldflags argument-list spelling. The native toolchain
	// resolver applies Go's quoted command parsing after target selection.
	ExternalLinker      string
	ExternalLinkerFlags string
}

LinkOptions is the typed linker intent consumed by the build backend. Command packages are responsible for parsing user-facing flag syntax into this representation.

func (LinkOptions) EffectiveOmitDWARF

func (o LinkOptions) EffectiveOmitDWARF() bool

EffectiveOmitDWARF reports whether the backend should omit DWARF. As in cmd/link, an explicit -w value takes precedence; otherwise -s implies -w.

type Mode

type Mode int
const (
	ModeBuild Mode = iota
	ModeInstall
	ModeRun
	ModeTest
	ModeCmpTest
	ModeGen
)

type ModuleHook

type ModuleHook func(pkg Package)

ModuleHook observes a package module immediately after it is generated and before TransformModule mutates it. The callback runs synchronously and receives the live llvm.Module, so callers that need a stable snapshot should consume it immediately (for example, by calling mod.String() inside the hook).

type OutFmtDetails

type OutFmtDetails struct {
	Out   string // Base output file path
	DWARF string // External debugger-owned DWARF container (.debug.wasm)
	DSYM  string // Native Darwin debugger-owned .dSYM bundle
	PCLN  string // PCLN sidecar output file path (.pclntab)
	Bin   string // Binary output file path (.bin)
	Hex   string // Intel hex output file path (.hex)
	Img   string // Image output file path (.img)
	Uf2   string // UF2 output file path (.uf2)
	Zip   string // ZIP/DFU output file path (.zip)
	// contains filtered or unexported fields
}

OutFmtDetails contains detailed output file paths for each format

func (*OutFmtDetails) ToEnvMap

func (details *OutFmtDetails) ToEnvMap() map[string]string

ToEnvMap converts OutFmtDetails to a map for template substitution

type OutFmts

type OutFmts struct {
	Bin bool // Generate binary output (.bin)
	Hex bool // Generate Intel hex output (.hex)
	Img bool // Generate image output (.img)
	Uf2 bool // Generate UF2 output (.uf2)
	Zip bool // Generate ZIP/DFU output (.zip)
}

OutFmts contains output format specifications for embedded targets

type OutputCfg

type OutputCfg struct {
	OutPath   string // Final output file path
	IntPath   string // Intermediate file path (for two-stage conversion)
	OutExt    string // Output file extension
	FileFmt   string // File format (from conf.FileFormat or extracted from emulator)
	BinFmt    string // Binary format for firmware conversion (may have -img suffix)
	NeedFwGen bool   // Whether firmware image generation is needed
	DirectGen bool   // True if can generate firmware directly without intermediate file
}

OutputCfg contains the generated output paths and conversion configuration

type PCLNMode

type PCLNMode uint8

PCLNMode controls how Go program counter and line metadata is packaged.

const (
	// PCLNEmbedded keeps the metadata in the executable. It is the default.
	PCLNEmbedded PCLNMode = iota
	// PCLNExternal writes the metadata to an optional sidecar file.
	PCLNExternal
	// PCLNNone omits the metadata and its loading support.
	PCLNNone
)

func (PCLNMode) IsValid

func (m PCLNMode) IsValid() bool

IsValid reports whether m is a recognized PCLN mode.

func (PCLNMode) String

func (m PCLNMode) String() string

type Package

type Package = *aPackage

func Build

func Build(inv Invocation) ([]Package, error)

Build executes one build invocation.

func Do

func Do(args []string, conf *Config) ([]Package, error)

type Rewrites

type Rewrites map[string]string

type SourceOverlayFile added in v1.0.7

type SourceOverlayFile struct {
	BackingFile string
	Contents    []byte
}

SourceOverlayFile holds one validated replacement. An empty BackingFile deletes the logical file from package selection.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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