Skip to main content
Dryft uses a flexible target system that defines how source code is compiled into executable programs. Each target specifies a backend, intermediate representation format, and the external tools needed to complete the build process.

Built-in Targets

Dryft includes two built-in targets located in src/targets/:

GCC Target (gcc.toml)

The default target that compiles Dryft code to C99 and uses GCC for final compilation.
[unix]
backend = "C99"
dependencies = [ "gcc" ]
intermediate = "build/ir.c"
stdlib = "gcc native/stdc/std.c -c -fPIE -o build/stdc.o"
assemble = "gcc -c -o build/ir.o -w build/ir.c"
link = "gcc build/ir.o build/stdc.o -o a.out"
interpret = "./a.out"
Characteristics:
  • Backend: C99 - Generates portable C code
  • Output: C source file compiled to native executable
  • Dependencies: GCC compiler
  • Use case: Default target for maximum portability

ELF Target (elf.toml)

Direct compilation to x86-64 assembly using NASM.
[unix]
backend = "x86"
intermediate = "build/ir.asm"
stdlib = ""
assemble = "nasm -f elf64 -o build/obj.o build/ir.asm"
link = "ld build/obj.o -o a.out"
interpret = "./a.out"
Characteristics:
  • Backend: x86 - Generates x86-64 assembly
  • Output: Native ELF executable
  • Dependencies: NASM assembler, ld linker
  • Note: No standard library compilation (currently limited)
  • Warning: Not stable in REPL environment

Target Structure

A target file is a TOML configuration that defines platform-specific compilation pipelines.

Platform Sections

Targets support multiple platforms:
[unix]
# Configuration for Unix-like systems (Linux, macOS)

[windows]
# Configuration for Windows systems
The compiler automatically selects the appropriate section based on the host OS family.

Target Fields

backend
string
required
The code generation backend to use. Available backends:
  • C99 - Generates C99-compliant C code
  • x86 - Generates x86-64 NASM assembly
intermediate
path
required
File path where the compiler writes the generated intermediate representation.Examples:
  • build/ir.c for C99 backend
  • build/ir.asm for x86 backend
dependencies
array
List of external tools required by this target. Currently informational only.Example:
dependencies = ["gcc", "make"]
stdlib
string
Shell command to compile the Dryft standard library for this target.Example:
stdlib = "gcc native/stdc/std.c -c -fPIE -o build/stdc.o"
assemble
string
Shell command to assemble/compile the intermediate representation into an object file.Example:
assemble = "gcc -c -o build/ir.o -w build/ir.c"
Shell command to link object files into the final executable.Example:
link = "gcc build/ir.o build/stdc.o -o a.out"
interpret
string
Command to execute the final product. Used with the --run flag and in REPL mode.Default: ./a.outExample:
interpret = "./a.out"

Available Backends

Backends are the code generation engines in Dryft. Each backend implements the Backend trait defined in src/backends.rs.

C99 Backend

  • Name: C99
  • Implementation: src/backends/c99/
  • Output format: C99-compliant C code
  • Features: Full language support, portable
  • Use case: Production builds requiring portability

x86 Backend

  • Name: x86
  • Implementation: src/backends/x86/
  • Output format: NASM x86-64 assembly
  • Features: Direct assembly generation
  • Limitations: REPL instability, limited stdlib support
  • Use case: Low-level systems programming, education

Creating Custom Targets

You can create custom target files to support new platforms or compilation workflows.

Example: LLVM Target

[unix]
backend = "C99"
intermediate = "build/ir.ll"
assemble = "clang -c -o build/ir.o build/ir.ll"
link = "clang build/ir.o -o a.out"
interpret = "./a.out"

Example: Cross-Compilation Target

[unix]
backend = "C99"
intermediate = "build/ir.c"
stdlib = "arm-linux-gnueabi-gcc native/stdc/std.c -c -o build/stdc.o"
assemble = "arm-linux-gnueabi-gcc -c -o build/ir.o build/ir.c"
link = "arm-linux-gnueabi-gcc build/ir.o build/stdc.o -o a.out"
interpret = "qemu-arm ./a.out"

Using Custom Targets

Specify your custom target file with the --custom-target flag:
dryftc --custom-target my-target.toml program.dry

Build Pipeline

The target system orchestrates a multi-stage build pipeline. See Build Process for details on how targets integrate with the compilation workflow.

Build docs developers (and LLMs) love