civ build system and pkg manager

Civstack is a full developer tech stack, and the bedrock of that is the build system -- which is this command (civ).

A "build system" is fundamentally a mechanism to convert a set of files and configuration (a package) into runnable (and testable) software. A package manager is then a way to depend on other packages.

A good build system has two other primary features:

PKG.luk

The PKG.luk file is is how you specify how to build a package and what is exported from that package. Below is an example one which we will walk though. Before we do, a few notes:

Example PKG.luk:

local P = { summary = "Does foo and some bar" }

--- Imports a function to help us create Target
local lua = import'sys:lua.luk' -- Lua build targets

-- Set up metadata for this PKG.luk file, this must be
-- returned at the end with the targets and PoD to provide
-- clients.
--
-- This also creates the global `P` value, which is the data
-- (build information) exported by this file.
P.foo = lua {
  mod = 'foo',
  src = { 'foo.lua' },
  dep = {
    'civ:lib',           -- depend on entire civ lib
    'myhub:foo#libfoo',  -- depend on next target
  },
}

-- test rule
P.test = lua.test {
  src = 'test.lua',
  dep = { 'myhub:foo' },
}

-- C build target with lua linked.
P.libfoo = lua.cc {
  hdr = { 'foo.h' },  -- C headers
  src = { 'foo.c' },  -- C source files
  dep = {
    'myhub:bar#libbar', -- depend on another target
  },
}

return P

Every value assigned to P must be either a concrete type or a #civ.core.Target.

civ output directory

By default, civ build puts files in .civ/. Wherever it puts it's output (whether during build or installation), the output structure under that directory is as follows:

Command civ

civ command

Subcmd init

Usage: civ init
Initialize the repository. This should be run when starting a new repo. Arguments:

Subcmd build

Usage: civ build hub:tgt#name
Build targets which match the pattern. Arguments:

Subcmd test

Usage: civ test hub:tgt#name
Test targets which match the pattern. Arguments:

Subcmd run

Usage: civ run hub:tgt#name -- ...args
Build+run a single build target which has a single bin or link output. Arguments:

Subcmd install

Usage: civ install hub:tgt#name
Install targets which match the pattern. Arguments:

Mod civ.core

civ.core contains types used by the civ build system.

If you are just a user of civ this is likely not useful. This library is

useful primarily for those who want to extend civ and/or write their own

build/test macros.

Types: TargetName Target Hub Cfg BuilderCfg Civ

Functions

Record TargetName

Represents a pkgname.target parsed from a string

Fields:

Methods

Record Target

A build target, the result of compiling a package.

Fields:

Methods

Record Hub

A hub configuration

Fields:

Record Cfg

The user configuration, typically at ./.civconfig.lua

Fields:

Methods

Record BuilderCfg

Cfg.builder settings

Fields:

Record Civ

Holds top-level data structures and algorithms for processing civ build graphs (pkgname graphs).

Fields:

Methods

Record civ.Worker

civ.Worker encapsulates a single civ worker, i.e. the process which actually performs build/test actions.

If you are just a user of civ this is likely not useful. This library is useful primarily for those who want to extend civ and/or write their own build/test macros.

Fields:

Methods