build

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Overview

Package build is the Zig-style build system (ADR 0021, design/08 §1). `cljgo build` with no file arg loads ./build.cljgo, evaluates its (defn build [b] …) through the interpreter against the embedded cljgo.build library (core/build.cljg), reads back a plain-data build plan (the step DAG), and executes the requested step.

The plan crosses the Go↔cljgo boundary as ordinary persistent data — an atom of maps/vectors — so no host object leaks; LoadPlan derefs it once and reads it with lang.Get / lang.ToSlice. Step execution (emit the artifact, synthesize go.mod, `go get` third-party modules, `go build`) lives here in Go, reusing the pkg/emit machinery `cljgo build <file>` already uses.

Index

Constants

View Source
const BuildFileName = "build.cljgo"

BuildFileName is the canonical project-root build description name (ADR 0021) — what `cljgo new` emits and what error messages name. `cljgo build` accepts any of BuildFileNames (ADR 0055).

Variables

View Source
var BuildFileNames = []string{"build.cljgo", "build.cljg", "build.clj"}

BuildFileNames are the accepted build-description names, most-specific-first (ADR 0055): cljgo-native `.cljgo`/`.cljg` before the portable `.clj`.

Functions

func FindBuildFile added in v0.3.0

func FindBuildFile(dir string) string

FindBuildFile returns the first accepted build file present in dir (ADR 0055 precedence), or "" if none exists.

func ResolveProjectDeps added in v0.3.0

func ResolveProjectDeps(buildFile string) error

ResolveProjectDeps loads buildFile and, if it declares (dep …) dependencies, resolves them and publishes their source roots for the interpreter load path (ADR 0052 slot 3). It is used by the `cljgo run` bootstrap so a project with locked dependencies resolves them the same way `cljgo build` does — one resolver, one order, no REPL-vs-binary divergence. It never evaluates a dependency's build fn (decision 5); it reads the lock and manifests as data.

Types

type Artifact

type Artifact struct {
	Name string
	Main string
	Kind string
	// Module is a library artifact's Go module path / Clojure coordinate
	// (ADR 0054 `lib`), used by `cljgo publish`. Empty for exe artifacts.
	Module string
}

Artifact is one buildable output declared by (exe b …) (lib/kinds are later milestones). Main is the entry .cljg path, relative to the build.cljgo directory.

type GoRequire

type GoRequire struct {
	Path    string
	Version string
}

GoRequire is a pinned third-party Go module from (go-require art …) — this replaces deps.edn (ADR 0021 B2).

type Plan

type Plan struct {
	ProjectDir string
	Artifacts  []Artifact
	GoRequires []GoRequire
	// Deps are the declared (dep …) dependencies (ADR 0052), resolved before
	// compilation; their source roots feed the interpreter load path (slot 3)
	// and their Go-requires merge into the consumer go.mod.
	Deps           []deps.Dep
	AcceptVersions map[string]string // (accept-version …): module -> version
	AllowCaps      map[string]bool   // (allow-capability …): acknowledged capabilities
	Steps          []Step
	Default        string // default step type when `cljgo build` gets no step arg
}

Plan is the finalized build graph read back from the builder atom.

func LoadPlan

func LoadPlan(buildFile string) (*Plan, error)

LoadPlan evaluates buildFile's (defn build [b] …) through a fresh interpreter and returns the resulting plan. The build description gets the full language (comptime context, ADR 0021 decision 4).

func (*Plan) LibArtifact added in v0.3.0

func (p *Plan) LibArtifact(name string) (Artifact, error)

LibArtifact returns the library artifact (ADR 0054 `lib`) to publish: the one named, or — when name is "" — the sole lib artifact. It errors when there is no lib, or when name is "" and more than one lib is declared (ambiguous).

func (*Plan) Run

func (p *Plan) Run(stepArg string, opts emit.Options, keepGen bool) error

Run executes the build. stepArg is the requested step ("" → the default install step, mirroring `zig build`; "run" → build+exec, `zig build run`). keepGen keeps the generated module dirs (else they're removed on success).

type Step

type Step struct {
	Type string // "install" | "run"
	Name string // artifact name
}

Step is a node in the executed DAG: an install or run of an artifact.

Jump to

Keyboard shortcuts

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