build

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: EUPL-1.2 Imports: 15 Imported by: 0

Documentation

Overview

Package build provides project type detection and cross-compilation for the Core build system.

Package build provides project type detection and cross-compilation for the Core build system. It supports Go, Wails, Node.js, and PHP projects with automatic detection based on marker files (go.mod, wails.json, package.json, composer.json).

Package build provides project type detection and cross-compilation for the Core build system.

Package build provides project type detection and cross-compilation for the Core build system. This file handles configuration loading from .core/build.yaml files.

Index

Constants

View Source
const ConfigDir = ".core"

ConfigDir is the directory where build configuration is stored.

View Source
const ConfigFileName = "build.yaml"

ConfigFileName is the name of the build configuration file.

Variables

This section is empty.

Functions

func ConfigExists

func ConfigExists(dir string) bool

ConfigExists checks if a build config file exists in the given directory.

func ConfigPath

func ConfigPath(dir string) string

ConfigPath returns the path to the build config file for a given directory.

func IsGoProject

func IsGoProject(dir string) bool

IsGoProject checks if the directory contains a Go project (go.mod or wails.json).

func IsNodeProject

func IsNodeProject(dir string) bool

IsNodeProject checks if the directory contains a Node.js project.

func IsPHPProject

func IsPHPProject(dir string) bool

IsPHPProject checks if the directory contains a PHP project.

func IsWailsProject

func IsWailsProject(dir string) bool

IsWailsProject checks if the directory contains a Wails project.

func WriteChecksumFile

func WriteChecksumFile(artifacts []Artifact, path string) error

WriteChecksumFile writes a CHECKSUMS.txt file with the format:

sha256hash  filename1
sha256hash  filename2

The artifacts should have their Checksum fields filled (call ChecksumAll first). Filenames are relative to the output directory (just the basename).

Types

type Artifact

type Artifact struct {
	Path     string
	OS       string
	Arch     string
	Checksum string
}

Artifact represents a build output file.

func Archive

func Archive(artifact Artifact) (Artifact, error)

Archive creates an archive for a single artifact. Uses tar.gz for linux/darwin and zip for windows. The archive is created alongside the binary (e.g., dist/myapp_linux_amd64.tar.gz). Returns a new Artifact with Path pointing to the archive.

func ArchiveAll

func ArchiveAll(artifacts []Artifact) ([]Artifact, error)

ArchiveAll archives all artifacts. Returns a slice of new artifacts pointing to the archives.

func Checksum

func Checksum(artifact Artifact) (Artifact, error)

Checksum computes SHA256 for an artifact and returns the artifact with the Checksum field filled.

func ChecksumAll

func ChecksumAll(artifacts []Artifact) ([]Artifact, error)

ChecksumAll computes checksums for all artifacts. Returns a slice of artifacts with their Checksum fields filled.

type Build

type Build struct {
	// CGO enables CGO for the build.
	CGO bool `yaml:"cgo"`
	// Flags are additional build flags (e.g., ["-trimpath"]).
	Flags []string `yaml:"flags"`
	// LDFlags are linker flags (e.g., ["-s", "-w"]).
	LDFlags []string `yaml:"ldflags"`
	// Env are additional environment variables.
	Env []string `yaml:"env"`
}

Build holds build-time settings.

type BuildConfig

type BuildConfig struct {
	// Version is the config file format version.
	Version int `yaml:"version"`
	// Project contains project metadata.
	Project Project `yaml:"project"`
	// Build contains build settings.
	Build Build `yaml:"build"`
	// Targets defines the build targets.
	Targets []TargetConfig `yaml:"targets"`
	// Sign contains code signing configuration.
	Sign signing.SignConfig `yaml:"sign,omitempty"`
}

BuildConfig holds the complete build configuration loaded from .core/build.yaml. This is distinct from Config which holds runtime build parameters.

func DefaultConfig

func DefaultConfig() *BuildConfig

DefaultConfig returns sensible defaults for Go projects.

func LoadConfig

func LoadConfig(dir string) (*BuildConfig, error)

LoadConfig loads build configuration from the .core/build.yaml file in the given directory. If the config file does not exist, it returns DefaultConfig(). Returns an error if the file exists but cannot be parsed.

func (*BuildConfig) ToTargets

func (cfg *BuildConfig) ToTargets() []Target

ToTargets converts TargetConfig slice to Target slice for use with builders.

type Builder

type Builder interface {
	// Name returns the builder's identifier.
	Name() string
	// Detect checks if this builder can handle the project in the given directory.
	Detect(dir string) (bool, error)
	// Build compiles the project for the specified targets.
	Build(ctx context.Context, cfg *Config, targets []Target) ([]Artifact, error)
}

Builder defines the interface for project-specific build implementations.

type Config

type Config struct {
	// ProjectDir is the root directory of the project.
	ProjectDir string
	// OutputDir is where build artifacts are placed.
	OutputDir string
	// Name is the output binary name.
	Name string
	// Version is the build version string.
	Version string
	// LDFlags are additional linker flags.
	LDFlags []string

	// Docker-specific config
	Dockerfile string            // Path to Dockerfile (default: Dockerfile)
	Registry   string            // Container registry (default: ghcr.io)
	Image      string            // Image name (owner/repo format)
	Tags       []string          // Additional tags to apply
	BuildArgs  map[string]string // Docker build arguments
	Push       bool              // Whether to push after build

	// LinuxKit-specific config
	LinuxKitConfig string   // Path to LinuxKit YAML config
	Formats        []string // Output formats (iso, qcow2, raw, vmdk)
}

Config holds build configuration.

type Project

type Project struct {
	// Name is the project name.
	Name string `yaml:"name"`
	// Description is a brief description of the project.
	Description string `yaml:"description"`
	// Main is the path to the main package (e.g., ./cmd/core).
	Main string `yaml:"main"`
	// Binary is the output binary name.
	Binary string `yaml:"binary"`
}

Project holds project metadata.

type ProjectType

type ProjectType string

ProjectType represents a detected project type.

const (
	// ProjectTypeGo indicates a standard Go project with go.mod.
	ProjectTypeGo ProjectType = "go"
	// ProjectTypeWails indicates a Wails desktop application.
	ProjectTypeWails ProjectType = "wails"
	// ProjectTypeNode indicates a Node.js project with package.json.
	ProjectTypeNode ProjectType = "node"
	// ProjectTypePHP indicates a PHP/Laravel project with composer.json.
	ProjectTypePHP ProjectType = "php"
	// ProjectTypeDocker indicates a Docker-based project with Dockerfile.
	ProjectTypeDocker ProjectType = "docker"
	// ProjectTypeLinuxKit indicates a LinuxKit VM configuration.
	ProjectTypeLinuxKit ProjectType = "linuxkit"
	// ProjectTypeTaskfile indicates a project using Taskfile automation.
	ProjectTypeTaskfile ProjectType = "taskfile"
)

Project type constants for build detection.

func Discover

func Discover(dir string) ([]ProjectType, error)

Discover detects project types in the given directory by checking for marker files. Returns a slice of detected project types, ordered by priority (most specific first). For example, a Wails project returns [wails, go] since it has both wails.json and go.mod.

func PrimaryType

func PrimaryType(dir string) (ProjectType, error)

PrimaryType returns the most specific project type detected in the directory. Returns empty string if no project type is detected.

type Target

type Target struct {
	OS   string
	Arch string
}

Target represents a build target platform.

func (Target) String

func (t Target) String() string

String returns the target in GOOS/GOARCH format.

type TargetConfig

type TargetConfig struct {
	// OS is the target operating system (e.g., "linux", "darwin", "windows").
	OS string `yaml:"os"`
	// Arch is the target architecture (e.g., "amd64", "arm64").
	Arch string `yaml:"arch"`
}

TargetConfig defines a build target in the config file. This is separate from Target to allow for additional config-specific fields.

Directories

Path Synopsis
Package buildcmd provides project build commands with auto-detection.
Package buildcmd provides project build commands with auto-detection.
Package builders provides build implementations for different project types.
Package builders provides build implementations for different project types.
Package signing provides code signing for build artifacts.
Package signing provides code signing for build artifacts.

Jump to

Keyboard shortcuts

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