machdocs
Home Ecosystem Changelog

Manifest

mach.toml declares a project. It separates the axes of a build: what is produced ([artifact.*]), where it runs ([target.*]), how it is compiled ([profile.*]), and what it links or must run first ([link.*], [step.*]). The build takes their product. Nothing is inferred from another key.

Totality

Every key has one rule, the same in every manifest, a dependency's included. A key may be left out only when leaving it out means it does not apply: no entries, nothing exported, no extensions. Every other key is required, and an unknown, removed or mistyped key is an error pointing at the line, never a silent default. A dependency's manifest is held to the same rules, but only its export surface is used to build the consumer, so a library cannot impose its build choices on you.

The schema

The manifest mach init writes, with one of its six targets shown and the optional keys commented:

[project]
id      = "demo"                       # required: root of every module path
version = "0.1.0"                      # required
mach    = "^7"                         # required: the compiler range
src     = "src"                        # required: source dir, project-root-relative
work    = "out/{target.name}/{profile.name}"  # required: the work directory

[target.linux-x86_64]                  # a platform: a fully spelled tuple
arch = "x86_64"
sys  = "linux"
abi  = "sysv64"
# env = "gnu"                          # optional: the system's environment
# isa = "x86-64-v3"                    # optional: the instruction set every machine has
# ext = ["sha"]                        # optional: extensions the target may assume
# runner = ["wine", "{artifact.out}"]  # optional: what mach run and mach test launch through

[artifact.demo]                        # a produced artifact
kind    = "bin"                        # "bin" | "static" | "shared" | "object" | "module"
entry   = "bin/main.mach"              # entry source, relative to src
out     = "{project.work}/bin/demo{artifact.suffix}"
targets = ["*"]                        # which declared targets build it ("*" = all)
# link = ["m"]                         # optional: [link.X] entries it links
# need = ["step.generate"]             # optional: steps and artifacts it needs first

[profile.debug]                        # a build variant: optimize, debug and simd are required
default  = true
optimize = false
debug    = true
simd     = "scalarize"

[profile.release]
optimize = true
debug    = false
simd     = "scalarize"

[dep.std]                              # a dependency: key, directory and project id match
git = "https://github.com/briar-systems/mach-std"
ref = "branch/dev"

[project]

KeyTypeMeaning
idstringRoot segment of every module path the project exposes: a file at <src>/foo/bar.mach is <id>.foo.bar. It starts with a letter or _ and holds only letters, digits and _, so a use path can spell it. Read by $project.id.
versionstringProject version. Read by $project.version and $project.version.{major,minor,patch}, and stamped into a Windows executable's version resource. A tag vX.Y.Z is a release only when this matches it.
machstringThe compiler versions this project builds with, as a version range such as "^7". Required in every manifest. See Compiler range.
srcstringSource root, project-root-relative. Module paths resolve under it.
workstringThe work directory template: everything a build writes besides its artifacts, referenced as {project.work}. -w names another one for one build.
Restriction

[project] is exactly these five keys, and every one is required. Any other key, name and description included, is an unknown-key error. The previous major's out is refused with the rename to work, which mach migrate writes.

The work directory

Everything a build and its cache write besides its artifacts lands under the expanded work, in one layout:

PathHolds
obj/one object per module, each carrying its cache key. It is the object cache, and is read by developers and tooling too.
ir/, asm/the human-readable views --emit ir and --emit asm write
.cache/compiler-only state, read and written by nothing but the compiler
.cache/steps/one fingerprint stamp per build step
.stage/build step scratch space, one directory per step, reset before the step runs
test/<artifact>/the test dispatcher of a tested artifact, and log/ with a failing test's captured output
dep/<id>/a dependency's artifact outputs

Test objects sit in obj/ beside the module objects, as obj/<project>/<module>.test.o. An artifact goes wherever its own out names. mach build and mach test read obj/ as the object cache: an edit rebuilds only that module and the modules whose view of it changed, a warm build links the same binary a cold one does, and an object that is missing or carries another key is rebuilt, never linked stale. --no-cache forces an uncached build. mach clean removes the whole layout along with every artifact output.

Compiler range

mach states which compilers a project builds with. Every command that reads the dependency closure, build, check, test, mach dep verify and the language server, checks it for the root and for every realized dependency. A compiler outside any of those ranges is refused once, naming every unmet requirement and the chain that states it.

Every manifest must state mach, and one without it is refused like any missing required key. mach init writes ^N for the running major N, so every 7.x compiler writes mach = "^7". Dependency resolution reads it too: a release whose range excludes the running compiler is never selected. The compiler's version is the last release it was built from, so a project cannot require an unreleased feature by version.

Targets

Each <name> in [target.<name>] is a selector you pass to -t <name>. A target is a fully spelled platform tuple. native is reserved: it names whichever declared target matches the host.

KeyReqMeaning
archyesArchitecture, such as x86_64 or riscv32. Read by $project.target.arch.
sysyesSystem, such as linux or freestanding. Read by $project.target.sys.
abiyesThe calling convention, by its real name, such as sysv64 or darwinpcs. Read by $project.target.abi.
envabsent: the system's defaultThe environment the system runs the program under: gnu on linux (needed to link the C library), macos on darwin, msvc on windows, vulkan1.0 to vulkan1.3 on vulkan, preview1 on wasi.
isaabsent: the system's floor. Required on freestandingThe instruction set every machine of the target has, such as x86-64-v3 or rv32imc.
extabsent: noneInstruction-set extensions the target may assume, such as ["sha"]. Read by $mach.build.ext.<name>.
runnerabsent: the host runs its own programs, and no other target'sArray of argv templates that mach run and mach test launch the target's programs through, such as ["qemu-aarch64", "{artifact.out}"].
ofabsent: the system's formatObject-format override, such as "flat" for a freestanding image.
baseabsent: the system's baseLoad-address override. An address above the TOML integer range is written as a string: base = "0xFFFF800000000000".
platformabsent: noneOpen platform tag, surfaced to comptime as $mach.build.platform. A support library keys its backend on it.
stack_reserve, stack_commitabsent: the format's defaultMain stack size and, on PE, commit, in bytes. A freestanding image whose entry sets up a stack must state stack_reserve.
code_modelabsent: the target's defaultThe code model, by its psABI name, such as medany.
Restriction

A target has no default key. With no -t a command takes the declared target matching the host, and two that match are refused as ambiguous. The previous major's os, isa naming an architecture, extensions and default are refused with the rewrite mach migrate applies.

Accepted tuple values

KeyValues
archx86_64, aarch64, riscv64, riscv32, spirv, wasm32
syslinux, windows, darwin, freestanding, uefi, vulkan, opencl, wasi
abisysv64, win64, aapcs64, darwinpcs, aapcs64win, arm64ec, lp64, lp64f, lp64d, ilp32, ilp32f, ilp32d, ilp32e, shader, kernel, basic
ofelf, macho, coff, flat, spirv, wasm

mach info targets lists every <sys>-<arch> this compiler builds, with the environments, ABIs, code models and linkages each accepts, its defaults marked *. A value a target does not accept is refused naming what it does accept, and a retired spelling (of = "raw", an aapcs64 darwin target, a spirv target on freestanding) is refused with the spelling to write.

RISC-V is a family of ABIs

lp64 means soft float: arguments ride integer registers even where the hardware has an FPU. lp64f passes single-precision floats in float registers and lp64d passes both, which is what a Linux riscv64 toolchain means by its default. ilp32, ilp32f and ilp32d are the same three on 32-bit RISC-V. Passing lp64 where lp64d was meant is an ABI mismatch against every C object on the system, not a performance choice.

A freestanding target names its instruction set and gets an ELF image with no loader construct in it by default, or a flat image with of = "flat". A bare-metal platform is not its own system: it is sys = "freestanding" plus a base and a platform tag.

[target.metal]
arch          = "x86_64"
sys           = "freestanding"
abi           = "sysv64"
isa           = "x86-64"
of            = "flat"
base          = "0x100000"
platform      = "bmos"
stack_reserve = 65536

Finished-module targets

A spirv target's output is a complete module a runtime loads rather than a link input. Its artifact is kind = "module", written at its out, and no executable or library is built for it. mach test builds such a cell and reports it skipped.

[target.gpu]
arch = "spirv"
sys  = "vulkan"
abi  = "shader"
env  = "vulkan1.3"

[artifact.shader]
kind    = "module"
entry   = "shaders/fill.mach"
out     = "{project.work}/fill.spv"
targets = ["gpu"]

Artifacts

Every artifact is declared explicitly and named by its table key. $bin.name reads the selected artifact's name. An artifact's build is rooted at its entry and follows use and fwd from there, so a file no entry reaches is not part of it.

KeyReqMeaning
kindyes"bin", "static", "shared", "object" or "module".
entryyesEntry source, relative to src. By convention bin/<name>.mach for an executable and lib/<name>.mach for a library.
outevery kind but objectOutput path, relative to the project root like every other path. Write {project.work}/... to place it under the work directory, and {artifact.suffix} for the target's file suffix.
targetsyesDeclared target names this artifact builds for. ["*"] means every one.
linkageabsent: the target's defaultHow a bin links: "pie", "dynamic" or "static".
linkabsent: nothingThe [link.X] entries this artifact links.
needabsent: nothingCategory-qualified requirements built first, such as step.generate or artifact.shader. A glob matches only within its category. A required artifact's output is {artifact.<name>.out}, which an #[embed] may name.
defaultabsent: not markedtrue puts the artifact in the default selection, which a command takes when no -a names one.
exportabsent: not exportedtrue marks the one library, static or shared, whose requirements travel to consumers.
subsystemabsent: the system's defaultA PE subsystem as mink spells it, such as "console" or "windows". Refused on a target whose image has none.
icon, manifestabsent: noneA .ico file and an application manifest embedded in a Windows executable's resources. bin only.

Windows subsystem and resources

A PE executable records which environment it wants, and the Windows loader honours it: "console" gets a console window, "windows" does not, so a graphical application sets it to stop an empty console from opening behind it.

[artifact.gui]
kind      = "bin"
entry     = "bin/gui.mach"
out       = "{project.work}/bin/gui{artifact.suffix}"
targets   = ["windows-x86_64"]
subsystem = "windows"
icon      = "assets/app.ico"
manifest  = "assets/app.manifest"

--set subsystem=<name> overrides the key for one invocation.

Profiles

A [profile.<name>] is a build variant. Every manifest declares at least one, and nothing is synthesized.

KeyReqMeaning
optimizeyesWhether the optimization passes run. The legalization passes run at every setting.
debugyesEmit debug information. Gates emission only, never the optimizer.
simdyes"scalarize" gives a vector operation no unit of the target computes a defined scalar expansion. "require" makes every such expansion an error naming the operation.
passesabsent: every pass follows optimizeOptimization passes turned on or off one by one, such as passes = { licm = false }.
relaxabsent: exact semanticsDepartures from exact semantics the build permits. The one there is, "float-reassoc", lets a float reduction be regrouped, and is the only profile key that can change a computed answer.
allowabsent: nothing silencedWarning keys this profile silences, such as ["import.unused"]. An error is never silenced.
symbolsabsent: truefalse leaves the symbol table out of the image.
sectionsabsent: truefalse leaves the section headers out of an ELF executable. Refused for a PE, Mach-O or wasm executable, whose loader reads them.
unwindabsent: truefalse leaves every unwind table out of the image.
linker_relaxabsent: trueWhether the linker may relax the code, as RISC-V linker relaxation does.
defaultabsent: not markedtrue marks the profile a build uses when several are declared and -p is absent.
[profile.release]
optimize = true
debug    = false
simd     = "scalarize"
relax    = ["float-reassoc"]

[profile.release.passes]
licm = false                           # every other pass runs, loop invariant motion does not

[profile.small]
optimize = true
debug    = false
simd     = "scalarize"
symbols  = false
sections = false
unwind   = false

The optimization passes are inline, split, promote, reassociate, fold, algebraic, reduce, effects, cse, forward, dse, bypass, thread, ifconvert, demanded, licm, vectorise, hoist, unroll, rotate, dce and switch. The previous major's opt, vectorize and float_reassoc are refused with the rewrite mach migrate applies.

On the command line, -O and --no-optimize set optimize, --debug and --no-debug set debug, and --set <key>=<value> writes any profile key for one invocation (--set simd=require, --set passes.licm=false). The levers are always the consumer's: a dependency's profiles are never read to build it.

A [link.<name>] is a named external link requirement. An artifact lists entries in its link, and an entry whose filters do not match the cell is skipped. An entry with export = true also applies to every project that depends on this one, so a platform requirement lives once, in the manifest that needs it. The table key is the entry's identity, the name #[library("...")] binds to.

KeyReqMeaning
sourceyes"system" (a library found by name), "framework" (a macOS framework), or "local" (a file).
nameshapeThe library or framework name: required for system and framework, forbidden for local.
pathshapeThe file: required for local, forbidden otherwise. A template.
kindabsent: "shared"What a system library named by a bare name must be: "shared" or "static", with no fallback either way, or "module", an import module a wasm host supplies.
sys, arch, abiyesFilter axes, each an array of values or ["*"]. [] matches nothing. An entry applies to a cell when all three match.
symbolsabsent: noneSymbols this library provides, for imports with no ext declaration to decorate, as a vendored archive leaves.
exportabsent: not exportedtrue cascades the entry to consumers.
includeabsent: "always""referenced" names a dynamic library in the image only when a live import uses it.
[link.m]
source = "system"
name   = "m"
kind   = "shared"
sys    = ["linux"]
arch   = ["*"]
abi    = ["*"]

On linux a system library is found through the C library's environment, so the target states env = "gnu". On PE and Mach-O a shared system library is linked from the claims the objects carry, so a Windows or macOS program cross-links from any host with no import library or SDK. A local entry's path must match a step's out, which demands that step, or already exist.

Build steps

A [step.<name>] is a command, make-recipe style, that produces files a build consumes, typically a local link input such as a vendored C object.

KeyReqMeaning
argvyesNonempty array of strings, spawned directly with no shell. Templates expand in every element. To use a shell, write ["sh", "-c", "..."].
inyesDeclared input files. Globs (*, **) expand sorted, and one that matches nothing is an error.
outyesDeclared output files. Concrete paths only.
needabsent: nothingstep.<name> requirements this step runs after.
envabsent: nothing addedTable of values added to the step's environment.
env_inabsent: noneInherited variables the step reads, such as CC, which then key its cache.
timeoutabsent: no limitA duration such as "30s" after which the step's process group is stopped and the build fails.

Steps carry no filters and never run on their own. A step runs only when demanded: by a selected [link.X] whose local path matches its out, by another step's need, or by an artifact's need. A step is cached by content, its inputs, executable, arguments and declared environment, and skipped when nothing changed and its outputs still hold the bytes it wrote. Every step receives the cell's target as MACH_TARGET_ARCH, MACH_TARGET_SYS and MACH_TARGET_ABI.

Dependencies

Each [dep.<id>] names a dependency held in dep/<id>/. The key, the directory and the dependency's own [project].id are one name, and a use path whose first segment is that id resolves into its source tree. A stanza declares exactly one source, git or path, and a git stanza exactly one selector, ref or version.

KeyMeaning
gitGit URL. The dependency is checked out at dep/<id>/ and pinned by its commit. Requires ref or version.
refSelector: branch/<name>, tag/<name> or commit/<full-object-id>. Any other spelling is rejected.
versionA version range over the dependency's vX.Y.Z release tags, such as "^0.1.0". Resolved by mach dep add and update, never by a build.
pathA local project tree, relative to this manifest and never fetched. mach dep copies its files into dep/<id>/.
[dep.std]
git = "https://github.com/briar-systems/mach-std"
ref = "branch/dev"

[dep.vlib]
git     = "https://example.com/vlib"
version = "^0.1.0"

[dep.helper]
path = "../helper"

A build reads what dep/ holds and nothing else: it never fetches, resolves or writes there, and a dependency that is not checked out is refused naming mach dep pull. See Dependencies for pins, ranges and resolution.

Path templates

Paths, step argv entries and target runner entries expand over a closed set of variables:

VariableExpands to
{project.work}the root project's expanded work, in every manifest of the closure
{target.name}the resolved target name (never the literal native)
{target.arch}, {target.sys}, {target.abi}the resolved target's arch, sys and abi
{profile.name}the selected profile name
{artifact.suffix}the file suffix of the artifact's kind on the target (.exe, .a, .so, ...). Only in an artifact's own out.
{artifact.<name>.out}the output path of a required artifact
{artifact.out}the program a runner launches. Only in a runner.

No output path is rooted for you: an artifact's out, a step's out and a local link's path name {project.work} where they mean the build output. That is what homes a dependency's build products in the consumer's tree rather than in the dependency's copy. An unknown {...} reference or an unterminated { is refused where it is written.

The build matrix

A build cell is one artifact for one target and one profile. -a, -t and -p select each axis by name or glob, and --all fills every axis no selector names.

native target resolution

native resolves the host's architecture and system against the declared targets only. Exactly one match is chosen, and several are an ambiguity error naming them. With no match it is an error, so a cross-only project selects its target with -t. An artifact whose only target is not hosted, such as a freestanding or spirv one, is selected with that target when the artifact is named. A manifest with no [target.*] table has the host's target.

Annotated example

A project that builds for linux and windows, links libm on linux, and vendors a C object through a build step. Note where the conditions live: [step.miniz] carries no filter, so it runs only because [link.miniz] demands it, and that entry is gated to sys = ["linux"] since the host cc emits an ELF object. On the windows cell the entry filters out, so the step never runs. The windows target names wine as its runner, so mach run . -t windows-x86_64 works on a Linux host. The source guards its ext fun declarations with $if on $mach.build.sys.

[project]
id      = "demo"
version = "0.1.0"
mach    = "^7"
src     = "src"
work    = "out/{target.name}/{profile.name}"

[target.linux-x86_64]
arch = "x86_64"
sys  = "linux"
env  = "gnu"                             # the c library's environment, for libm
abi  = "sysv64"

[target.windows-x86_64]
arch   = "x86_64"
sys    = "windows"
env    = "msvc"
abi    = "win64"
runner = ["wine", "{artifact.out}"]

[profile.debug]
default  = true
optimize = false
debug    = true
simd     = "scalarize"

[profile.release]
optimize = true
debug    = false
simd     = "scalarize"

[step.miniz]                             # builds the object the link entry below demands
argv = ["cc", "-c", "-fPIC", "vendor/miniz.c", "-o", "{project.work}/vendor/miniz.o"]
in   = ["vendor/miniz.c"]
out  = ["{project.work}/vendor/miniz.o"]

[link.miniz]
source = "local"
path   = "{project.work}/vendor/miniz.o"   # matches step.miniz's out, so it demands that step
sys    = ["linux"]                         # host cc emits an ELF object
arch   = ["*"]
abi    = ["*"]

[link.m]
source = "system"
name   = "m"
sys    = ["linux"]                         # skipped on the windows cell
arch   = ["*"]
abi    = ["*"]

[artifact.demo]
kind    = "bin"
entry   = "bin/main.mach"
out     = "{project.work}/bin/demo{artifact.suffix}"
targets = ["*"]
link    = ["miniz", "m"]

[dep.std]
git = "https://github.com/briar-systems/mach-std"
ref = "branch/dev"
$ mach build . --all
     built  target          artifact  profile  modules       size   time
            linux-x86_64    demo      debug    52 modules  83 KiB  457ms
            windows-x86_64  demo      debug    52 modules  88 KiB  499ms
            linux-x86_64    demo      release  52 modules  26 KiB  440ms
            windows-x86_64  demo      release  52 modules  11 KiB  530ms

See also

  • CLI - the flags that select a target, profile, and artifact
  • Dependencies - version ranges, release resolution, mach dep, and pins
  • Project layout - how src maps to module paths
  • Decorators - #[library], which binds to a [link.X] key