Build System
A Maxon project is a directory of .maxon files marked by a <name>.maxproj project file at its
root. maxon build <directory> compiles every source file beneath a directory, and maxon build with no
path builds a target the project file describes.
myproject/├── myproject.maxproj # the project file: where the project begins, and how it is built├── myproject.maxtasks # the tasks `maxon run` offers, if it has any├── main.maxon # entry point├── lib.maxon├── lib.maxtest # tests: compiled only by maxon test└── utils/ └── math.maxon # subdirectories are includedA build compiles the .maxon files. Each other kind of file has its own reader:
.maxproj— the project file;maxon buildruns its targets..maxtasks— the task file;maxon runruns its tasks..maxtest— test files;maxon testcompiles them with the project’s.maxonsources.
A directory walk also skips any directory containing a .maxonignore file, with everything beneath
it. A .maxonignore excludes a directory the walk discovers; naming a path explicitly on the command
line — a file or a directory — compiles it whatever marker sits above it or on it. A file named
project.maxon or tasks.maxon is ordinary source. See
Project Structure for the full layout rules.
A Project File Is a Program
Section titled “A Project File Is a Program”A .maxproj file is ordinary Maxon with the whole standard library available. The compiler compiles it
for the host, runs the chosen target, and performs the build that target describes. A build can therefore
compute what it compiles — list a directory, choose sources by host, derive a version from git — as
well as spell it out.
Its targets are its exported (or public) functions of no parameters returning ExitCode. A
non-zero return or a crash fails the build before anything is compiled. Every build checks every
target when the project file compiles, before it runs: one that declares a parameter, a defaulted one
included, is E3225, one that does not return ExitCode is E3002, and one that throws is
E3054, whichever target is asked for. A helper function in the project file drops its export
(or public), which makes it no target. A function an inactive #if excludes is no target of the
build.
export function build() returns ExitCode Build.build("src") return 0end 'build'A build that states no output is written to .maxon/<name>, <name> being the project file’s own name —
.maxon/hello here. A stated output omits the extension: the compiler adds the target’s (.exe on
Windows, .wasm for wasm32-wasi, none on Linux and macOS). Relative paths resolve against the project
file’s directory.
maxon build with no path builds the project’s only target. A project with several targets names
one on the command line, each _ of the function’s name written -:
export function app() returns ExitCode Build.build("app", output: "out/app", version: "1.2.3") return 0end 'app'
export function gen_tool() returns ExitCode Build.build("tool", output: "out/tool", debugInfo: false) return 0end 'gen_tool'maxon build with no argument then lists app and gen-tool and compiles nothing; maxon build app
and maxon build gen-tool build one each. Every target is an entry point of the project file, so an
exported target is exempt from E3092.
One project per tree. A .maxproj file inside another project’s directory tree is E2074, reported
from either project; a directory holds one .maxproj file at most.
Describing the Build
Section titled “Describing the Build”Build (in the standard library) writes the build description the compiler reads back. A target
describes one build; describing a second in the same run is an error.
| Call | Meaning |
|---|---|
Build.build(source, output: "", debugInfo: true, version: "", defines:, rebuildWithOutput: false) |
compile one file or directory to one output |
Build.buildWithConfig(config) |
build one BuildConfig, whose sources may list several files and directories compiled as one program, in order |
Build.delegate(directory, target: "") |
hand the whole description to a target of another directory’s .maxproj file, run there |
debugInfocontrols the debug-information sidecar written beside the executable.versionstamps a dotted version into the executable’s metadata.definesis aStringArrayof"name=value"entries, each replacing the written default of a top-levelStringconstant — the same asmaxon build --define. This is how a project file passes a value it computed, such as a version derived from git, into the program.rebuildWithOutputruns the written program with the same command line once the build succeeds, as a compiler building itself does; see Building again with the written program.targetnames one of the delegated project’s targets the waymaxon builddoes; empty means its only one.
Several sources in one program use a BuildConfig:
export function build() returns ExitCode let sources = StringArray.create(0) sources.push("src") sources.push("vendor/thirdparty")
Build.buildWithConfig(BuildConfig.create(sources, output: "out/myprogram")) return 0end 'build'Sources are compiled in exactly the order listed. An empty sources list is refused
(myprogram.maxproj named no sources to compile), so a build always names what it compiles.
The Command Line Wins
Section titled “The Command Line Wins”Flags typed on the command line outrank the described build: --output= replaces the output path,
--target chooses the target (the project file itself always runs on the host), a --define is applied
after the described build’s defines, and debug information is written only if both the described build
and the command line allow it.
The CLI reference documents maxon build and its flags.
A directory may also hold a <name>.maxtasks file, and maxon run <task> runs one of its exported
no-parameter ExitCode functions with the caller’s own streams and exit code. The task is named the way
a target is, each _ written -, and maxon run alone lists them. It is the same language and the
same standard library as a project file, and the two files divide one job in two:
export function build() returns ExitCode Build.delegate("compiler") return 0end 'build'
export function check_format() returns ExitCode return 0end 'check_format'A .maxtasks file marks nothing, so it can sit in any directory: what says where a project begins is
a .maxproj file. A task may describe a build, as build does above, and the compiler performs it once
the task exits 0; with no stated output it is written to .maxon/<name>, <name> being the task file’s
own. Every task is an entry point, exempt from E3092 like a target.