build

command module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: Apache-2.0 Imports: 1 Imported by: 0

README

build - a simpler build system

build is a build system inspired by GNU Make's target and recipe specification philosophy minus the complexities and quirks of GNU Make.

Features

  • Simple, clean syntax - Indentation-based, no tabs vs spaces issues
  • Pattern targets - build/{name}.o: src/{name}.c matches any file
  • Variable interpolation - {var} syntax with optional :raw modifier
  • Built-in functions - shell(), glob(), basename(), dirname(), replace()
  • Conditionals - if/elif/else/end and ifdef/ifndef blocks
  • Parallel execution - Built-in parallel job support with -j flag
  • Environment management - Docker, Podman, devcontainer, Nix, and Lima support
  • Include files - Split large buildfiles with .include:

Installation

go install github.com/vinayprograms/build@latest
Prerequisites
  • Go 1.25.3 or later (ensure $GOPATH/bin is in your PATH)

Quick Start

Create a Buildfile in your project:

# Set shell
.shell: bash

# Variables
cc = gcc
cflags = -Wall -O2

# Phony target (always runs)
@clean:
    rm -rf build/

# File target
app: build/main.o build/utils.o
    {cc} -o {target} {deps}

# Pattern target (matches any .o file)
build/{name}.o: src/{name}.c
    mkdir -p build
    {cc} {cflags} -c {in} -o {out}

Build your project:

build app     # Build the app target
build clean   # Run the clean target
build         # Build the default target (first defined)

Usage

build [options] [targets...]

Options:
  -f, --file PATH     Use alternate Buildfile
  -e, --env NAME      Use named environment
  -j, --jobs N        Parallel jobs (default: 1)
  -n, --dry-run       Show what would execute
  -v, --verbose       Verbose output
  --check-env         Verify environment requirements
  --show-install      Show install instructions
  --list-env          List available environments
  -V, --version       Show version
  -h, --help          Show help

Syntax Overview

Variables
# Immediate variable (evaluated at definition)
cc = gcc

# Lazy variable (evaluated at each use)
lazy timestamp = shell(date +%s)
Conditionals
if {os} == linux
    cc = gcc
elif {os} == darwin
    cc = clang
end

ifdef DEBUG
    cflags = -g -DDEBUG
end
Targets
# File target
output.txt: input.txt
    cp {in} {out}

# Phony target (no output file)
@test:
    go test ./...

# Phony target with phony dependencies
# Note: @ prefix is only needed for declaration, not for references
@all: build test
    echo "Done"

# Pattern target
build/{name}.o: src/{name}.c
    gcc -c {in} -o {out}
Automatic Variables
Variable Description
{target} Target file path
{out} Alias for target
{deps} All dependencies (space-separated)
{in} First dependency
{stem} Matched pattern capture
{target.dir} Directory part of target
{target.file} Filename part of target
Built-in Functions
sources = glob(src/*.c)
objects = replace({sources}, .c, .o)
dir = dirname(/path/to/file.c)
base = basename(/path/to/file.c)
result = shell(echo hello)
Environment Blocks
.environment:
    .using: docker
    .source: Dockerfile
    .args: --platform linux/amd64
    .requires: gcc@11 python3

Documentation

Exit Codes

Code Meaning
0 Success
1 Build failure (recipe returned non-zero)
2 Usage error (bad arguments)
3 Parse error (invalid Buildfile)
4 Environment error (missing requirements)

License

See LICENSE for details.

Documentation

Overview

Command build is a Make-inspired build tool with readable syntax.

Directories

Path Synopsis
cmd
build/cli
Debug commands for the build tool CLI.
Debug commands for the build tool CLI.
internal
ast
Package ast defines the Abstract Syntax Tree node types for Buildfile parsing.
Package ast defines the Abstract Syntax Tree node types for Buildfile parsing.
cache
Package cache provides caching for parsed Buildfiles.
Package cache provides caching for parsed Buildfiles.
environ
Package environ provides environment management for the build tool.
Package environ provides environment management for the build tool.
errors
Package errors provides structured error formatting for the build tool.
Package errors provides structured error formatting for the build tool.
eval
Package eval provides variable evaluation for Buildfiles.
Package eval provides variable evaluation for Buildfiles.
executor
Package executor provides recipe execution for Buildfiles.
Package executor provides recipe execution for Buildfiles.
lexer
Package lexer implements lexical analysis for Buildfiles.
Package lexer implements lexical analysis for Buildfiles.
output
Package output provides build output formatting and reporting.
Package output provides build output formatting and reporting.
parser
Package parser implements syntactic analysis for Buildfiles.
Package parser implements syntactic analysis for Buildfiles.
planner
Package planner provides build planning for Buildfiles.
Package planner provides build planning for Buildfiles.
platform
Package platform provides cross-platform utilities for path handling, shell execution, and platform detection.
Package platform provides cross-platform utilities for path handling, shell execution, and platform detection.
semantic
Package semantic provides semantic analysis for Buildfiles.
Package semantic provides semantic analysis for Buildfiles.

Jump to

Keyboard shortcuts

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