compile

package
v0.6.0-20a Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package compile turns factory source into a buildable Go module: it parses and validates the stack, resolves its imports, reads each Go library's schema, runs the compile-time checks, generates main.go and one package per UB library, and optionally runs `go build`. The CLI's compile command is a thin flag layer over Run.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeriveStackName

func DeriveStackName(stackPath string) string

DeriveStackName returns the stack name a source path implies: the lowercased basename of the file's directory.

func GoMajorMinor

func GoMajorMinor() string

GoMajorMinor returns the running Go toolchain's `<major>.<minor>` so the generated go.mod's `go` directive matches the current toolchain.

func LockedVersions

func LockedVersions(dir string) (map[string]string, error)

LockedVersions reads unobin.lock from dir and returns each repository's selected version, or nil when no lock is present, in which case the walk uses the version on each import string.

func NewProjectResolver

func NewProjectResolver(stackDir string) (resolve.Resolver, error)

NewProjectResolver returns the resolver compile uses to fetch import sources: a local resolver for relative paths and a remote resolver for everything else.

func PrintSchemaWarnings

func PrintSchemaWarnings(out io.Writer, alias string, warnings []string)

PrintSchemaWarnings emits each warning string to out prefixed with the import alias the schema came from.

func ReadGoSchema

func ReadGoSchema(sourcePath string) (*ubruntime.LibrarySchema, []string, error)

ReadGoSchema reads a fetched Go library's source from sourcePath and returns its schema plus any warnings about registered types whose sibling Output struct could not be located. A missing path returns nil values with no error, which lets fake resolvers in tests fall through without having to write a real library to disk. Any other failure mode (missing Library() function, parse error, malformed source) is propagated so a broken import fails the compile.

func Run

func Run(opts Options) error

Run compiles a factory per the options.

func WrapReplaces

func WrapReplaces(
	resolver resolve.Resolver, root, replaceUnobin string, replace map[deps.Dependency]string,
) (resolve.Resolver, error)

WrapReplaces wraps resolver so that a replaced unobin and each manifest replace entry resolve to a local directory instead of fetching. Replace paths are taken relative to root.

Types

type Options

type Options struct {
	// StackPath is the factory source to compile.
	StackPath string
	// OutDir receives main.go, go.mod, and the generated UB-library
	// packages; `-` streams main.go to Stdout instead.
	OutDir string
	// StackName overrides the stack name; empty derives it from the
	// stack file's parent directory.
	StackName string
	// LibraryPath is the library-path identity to embed in the binary.
	LibraryPath string
	// GoVersion is the toolchain version the generated go.mod declares.
	GoVersion string
	// Version is the release version stamped into the built binary.
	Version string
	// CLIVersion is the compiling CLI's own version; the generated
	// go.mod pins unobin to it so the factory links the runtime its
	// compile checks ran with. "dev" requires a replace.
	CLIVersion string
	// ReplaceUnobin substitutes a local path for the unobin repository.
	ReplaceUnobin string
	// ReplaceGoModules maps a Go module path to the local path that
	// serves it, for both the import resolver and the generated go.mod.
	ReplaceGoModules map[string]string
	// Build runs `go build` in OutDir after writing the source.
	Build bool
	// NewResolver constructs the import resolver for a stack directory;
	// nil uses NewProjectResolver.
	NewResolver func(stackDir string) (resolve.Resolver, error)
	// Stdout and Stderr receive the run's output; nil defaults to the
	// process streams.
	Stdout io.Writer
	Stderr io.Writer
	// TypeObserver, when set, receives every expression the stack's
	// type checks infer, with its type. The residual-Unknown harness
	// uses it; nil compiles without recording.
	TypeObserver func(e lang.Expr, t typecheck.Type)
}

Options configures one compile run.

Jump to

Keyboard shortcuts

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