Build Options
Build options are named values passed from the command line into build.fol.
They follow Zig’s -D convention.
Syntax
fol code build -Dname=value
Multiple options can be passed in one command:
fol code build -Dtarget=x86_64-linux-gnu -Doptimize=release-fast -Dstrip=true
Standard Options
Two options are pre-defined by the build system: target and optimize.
They are read via dedicated graph methods.
Target
var target = graph.standard_target();
CLI: -Dtarget=arch-os-env
Format: arch-os-env triple. Examples:
| Triple | Meaning |
|---|---|
x86_64-linux-gnu | x86-64 Linux with glibc |
x86_64-linux-musl | x86-64 Linux with musl libc |
aarch64-linux-gnu | ARM64 Linux with glibc |
x86_64-macos | x86-64 macOS |
x86_64-windows-msvc | x86-64 Windows with MSVC |
Supported architectures: x86_64, aarch64.
Supported operating systems: linux, macos, windows.
Supported environments: gnu, musl, msvc.
If not set, the host target is used.
To pass the resolved value to an artifact:
var target = graph.standard_target();
var app = graph.add_exe({
name = "app",
root = "src/main.fol",
target = target,
});
Optimize
var optimize = graph.standard_optimize();
CLI: -Doptimize=mode
Valid modes:
| Mode | Meaning |
|---|---|
debug | No optimization, full debug info |
release-safe | Optimized with safety checks |
release-fast | Maximum speed, no safety checks |
release-small | Minimize binary size |
Default: debug.
To pass the resolved value to an artifact:
var optimize = graph.standard_optimize();
var app = graph.add_exe({
name = "app",
root = "src/main.fol",
optimize = optimize,
});
User Options
graph.option(...) declares a named option specific to the package.
var strip = graph.option({
name = "strip",
kind = "bool",
default = false,
});
CLI: -Dstrip=true
Option Kinds
| Kind | Example CLI | Default type |
|---|---|---|
bool | -Dverbose=true | false |
int | -Djobs=8 | 0 |
str | -Dprefix=/usr | "" |
enum | -Dbackend=llvm | first value |
path | -Droot=src/main.fol | "" |
target | -Dtarget=x86_64-linux-gnu | host target |
optimize | -Doptimize=release-fast | debug |
Using Option Values
Option handle values can be interpolated into strings or compared with ==:
var root_opt = graph.option({ name = "root", kind = "path", default = "src/main.fol" });
var app = graph.add_exe({ name = "app", root = root_opt });
Comparing in a when condition:
var strip = graph.option({ name = "strip", kind = "bool", default = false });
when(strip == true) {
{
var strip_step = graph.step("strip");
}
};
Shorthand vs Long Form
Both of these are equivalent:
fol code build -Dtarget=x86_64-linux-gnu
fol code build --build-option target=x86_64-linux-gnu
-D is the shorthand. -Dtarget= and -Doptimize= route to the dedicated
standard option slots. All other -Dname=value pairs route to user-declared
options.