build

package
v0.21.3 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const PrefixPlaceholder = "@@GALE_PREFIX@@"

PrefixPlaceholder is embedded in text files during build to replace the build-time temp prefix. At install time, RestorePrefixPlaceholder replaces it with the actual store path. This avoids hardcoded temp paths in scripts.

Variables

View Source
var ErrUnsupportedPlatform = errors.New("unsupported platform")

ErrUnsupportedPlatform is returned when a recipe restricts platforms and the current platform is not in the list.

Functions

func AddDepRpaths added in v0.7.0

func AddDepRpaths(prefixDir string, depStoreDirs []string) error

AddDepRpaths sets the ELF RUNPATH of binaries under prefixDir so shared libraries from gale deps resolve at runtime without LD_LIBRARY_PATH. The dep dylibs are reached through the shared lib farm via a RELATIVE ($ORIGIN-anchored) rpath, so the shipped artifact needs no install-time rewrite and installs byte-for-byte with what CI built and attested. No absolute .gale/pkg or .gale/lib path is baked in. This mirrors the darwin AddDepRpaths design — see docs/dev/relocatable-binaries.md.

func EnsureCodeSigned added in v0.12.0

func EnsureCodeSigned(prefixDir string) error

EnsureCodeSigned is a no-op on Linux. Exists so platform- neutral callers can invoke it without build-tag shims.

func FixupBinaries

func FixupBinaries(prefixDir string) error

FixupBinaries rewrites ELF rpath entries so binaries find shared libraries relative to themselves via an $ORIGIN-anchored path to the package's lib/ directory.

func FixupPkgConfig added in v0.7.0

func FixupPkgConfig(prefixDir string) error

FixupPkgConfig rewrites prefix= lines in .pc files to use ${pcfiledir}/../.. so they resolve correctly from any install location. Build-time prefixes (temp dirs, CI paths) become stale after install — relative paths always work.

func RelocateStalePathsInTextFiles added in v0.12.0

func RelocateStalePathsInTextFiles(prefixDir, currentStoreRoot string) error

RelocateStalePathsInTextFiles rewrites foreign .gale/pkg/ paths embedded in text files under prefixDir so they use currentStoreRoot instead. This fixes CI-baked paths (e.g. /Users/runner/.gale/pkg/...) that appear in scripts and pkg-config files after a binary install. Directories scanned: textFixupDirs. Binary files and files larger than 10 MB are skipped.

func RelocateStaleRpaths added in v0.10.1

func RelocateStaleRpaths(prefixDir, storeRoot string) error

RelocateStaleRpaths rewrites ELF RUNPATH entries that contain a foreign .gale/pkg/ store prefix to use the local store root. This handles prebuilt binaries from CI where rpaths are baked to the CI runner's home dir.

func ReplacePrefixInTextFiles added in v0.9.0

func ReplacePrefixInTextFiles(prefixDir, replacement string) error

ReplacePrefixInTextFiles walks prefixDir and replaces all occurrences of buildPrefix in text files with replacement. Binary files (those containing null bytes in the first 512 bytes) are skipped. Directories scanned: textFixupDirs (lib for .la files and scripts, include for generated config headers).

func RestorePrefixPlaceholder added in v0.9.0

func RestorePrefixPlaceholder(storeDir string) error

RestorePrefixPlaceholder replaces PrefixPlaceholder with storeDir in all text files under storeDir. Called after extracting a build archive into the package store.

func RestorePrefixPlaceholderTo added in v0.16.0

func RestorePrefixPlaceholderTo(rootDir, replacement string) error

RestorePrefixPlaceholderTo replaces PrefixPlaceholder with replacement in all text files under rootDir. This is used when install output is staged in a temporary directory before being moved into its final store path.

func SetOutput

func SetOutput(o *output.Output)

SetOutput overrides the build output writer.

func SystemDeps added in v0.6.0

func SystemDeps(system string) []string

SystemDeps returns implicit build dependencies for a build system. These are added alongside explicit [dependencies.build] entries.

func TmpDir added in v0.3.0

func TmpDir() string

TmpDir returns the path to ~/.gale/tmp/, creating it if needed. Falls back to system temp if unavailable.

Types

type BuildContext added in v0.10.0

type BuildContext struct {
	PrefixDir string
	SourceDir string
	Jobs      string
	Version   string
	System    string
	Toolchain string
	Debug     bool
	Env       map[string]string // extra env vars from recipe [build] env
	Deps      *BuildDeps

	// SourceDateEpoch is the deterministic Unix timestamp
	// exported to build steps as SOURCE_DATE_EPOCH. Set by
	// buildFromDir from sourceDateEpoch(r). Recipes that
	// honour it (flit_core, dh_strip_nondeterminism,
	// cmake's CPack, etc.) use it for embedded timestamps
	// in archives and wheels. Clamped to >= 1980-01-01
	// (the ZIP epoch floor) so Python 3.14's strict
	// zipfile.from_file doesn't reject wheels (gh#21).
	SourceDateEpoch int64
}

BuildContext holds parameters passed through build steps and environment construction.

type BuildDeps added in v0.4.0

type BuildDeps struct {
	// BinDirs holds bin/ dirs from explicit [dependencies.build]
	// entries (and their transitive closures). They take PATH
	// priority so an explicit toolchain pin (e.g. zig15) wins over
	// the implicit system toolchain (gale#174).
	BinDirs []string
	// SystemBinDirs holds bin/ dirs from implicit system-build
	// tools merged in by withSystemDeps (e.g. "zig" for
	// system = "zig"). Joined after BinDirs so an explicit pin of
	// the same tool family shadows the implicit default rather than
	// the reverse.
	SystemBinDirs []string
	StoreDirs     []string          // root store dirs for lib/include/pkgconfig
	NamedDirs     map[string]string // dep name → store directory
}

BuildDeps holds paths from installed build dependencies, used to construct the build environment.

func (*BuildDeps) Canonicalize added in v0.21.0

func (d *BuildDeps) Canonicalize()

Canonicalize sorts and dedupes the slice fields in place. The installer records deps in goroutine-completion order, so without this the -L/-Wl,-rpath flags and the build PATH shuffle between runs of the same build — the shipped Mach-O then differs in LC_RPATH order and, through the linker's content-based hash, in LC_UUID (gale-recipes#79). Deterministic dep ordering is a precondition for byte-reproducible artifacts.

type BuildResult

type BuildResult struct {
	Archive string // path to the tar.zst file
	SHA256  string // hex-encoded hash of the archive
}

BuildResult holds the output of a successful build.

func Build

func Build(r *recipe.Recipe, outputDir string, debug bool, deps *BuildDeps) (*BuildResult, error)

Build builds a recipe from source and packages the result. outputDir is where the tar.zst will be written. Optional extraPaths are prepended to the build environment PATH.

func BuildGit added in v0.3.0

func BuildGit(r *recipe.Recipe, outputDir string, debug bool, deps *BuildDeps) (*BuildResult, string, error)

BuildGit clones a git repo and builds from the clone. Returns the build result and the short commit hash used as the version. The recipe's version is overridden with the hash.

func BuildLocal

func BuildLocal(r *recipe.Recipe, sourceDir, outputDir string, debug bool, deps *BuildDeps) (*BuildResult, error)

BuildLocal builds a recipe using a local source directory instead of downloading. The source directory is used as the build root directly.

Jump to

Keyboard shortcuts

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