Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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:

TripleMeaning
x86_64-linux-gnux86-64 Linux with glibc
x86_64-linux-muslx86-64 Linux with musl libc
aarch64-linux-gnuARM64 Linux with glibc
x86_64-macosx86-64 macOS
x86_64-windows-msvcx86-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:

ModeMeaning
debugNo optimization, full debug info
release-safeOptimized with safety checks
release-fastMaximum speed, no safety checks
release-smallMinimize 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

KindExample CLIDefault type
bool-Dverbose=truefalse
int-Djobs=80
str-Dprefix=/usr""
enum-Dbackend=llvmfirst value
path-Droot=src/main.fol""
target-Dtarget=x86_64-linux-gnuhost target
optimize-Doptimize=release-fastdebug

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.