Build

karkain build compiles a .kark file into a native executable without running it.

Usage

$ karkain build <file.kark> [-o <output>]

Options:

  • -o <path> — set the output executable path (default: main.exe on Windows, a.out on other platforms)

  • --target <triple> — cross-compile for a different target (see Cross-Compilation)

  • --verbose — show the full compilation pipeline

  • -c / --compile-only — emit C but do not invoke gcc/clang

Examples

# Build hello.kark → hello (Linux/macOS) or hello.exe (Windows)
$ karkain build hello.kark

# Build with a custom output name
$ karkain build hello.kark -o hello_world

# Cross-compile for Linux amd64 on a Windows host
$ karkain build hello.kark --target x86_64-linux -o hello_linux

# Emit C only (no gcc/clang invocation)
$ karkain build hello.kark --compile-only

# Show pipeline steps
$ karkain build hello.kark --verbose

Incremental builds

When the --incremental flag is used, the compiler caches compiled assembly modules. On a no-op build (no source changes), the compiler skips recompilation and reuses the cached output:

$ karkain build main.kark --incremental
$ karkain build main.kark --incremental   # much faster: cached

The incremental cache is stored in .karkain-cache/ at the project root. To clear it:

$ karkain clean

Engine selection

The default compilation engine is kcc (the self-hosted compiler). To use the Go front end instead:

$ karkain build --engine go hello.kark

See The Self-Hosted kcc Engine for more on the two engines.

Exit codes

  • 0 — success

  • 3 — compilation failure (lexer, parser, semantic, or codegen error)

  • 6 — environment failure (no usable C compiler found)

See also

Run — compile and run in one step. Build — the CLI reference, including -c/--compile-only for emitting C without compiling. Cross-Compilation — building for a different platform.