--- sidebar_label: Build system --- # Build System ## Compiler Backends DCR supports 4 compilation backends. Selection is automatic based on file extension. | Backend | Files | When used | |---------|-------|-----------| | `unix_cc` | `.c`, `.cpp`, `.cxx`, `.cc`, `.S` | gcc/clang on Linux/macOS/BSD | | `msvc` | `.c`, `.cpp`, `.cxx`, `.cc` | Windows (cl, clang-cl) | | `gas` | `.s` | ARM/ARM64 assembler (no preprocessor) | | `nasm` | `.asm` | x86/x86_64 assembler | ### Unix CC - Compiler resolved via `resolve_compiler()`: `DCR_COMPILER` > `DCR_CC` > `[toolchain]` > `build.compiler` > `PATH` - Supports `.d` files for header dependency tracking - Flags: `-std=`, `-MMD -MF`, `-c -o`, `-I`, `-L`, `-l` - Conditional flags based on config: - `freestanding` or bare-metal target: `-ffreestanding` (compile), `-nostdlib -static` (link) - `lto`: `-flto` (compile + link) - `panic = "abort"`: `-fno-exceptions` (C++ only), `-fno-unwind-tables`, `-fno-asynchronous-unwind-tables` ### MSVC - Supports cl.exe and clang-cl.exe - Flags: `/std:`, `/Fo:`, `/Fe:`, `/I`, `/link` ### GAS / NASM - GAS: `-I`, `-c -o`, `--defsym` - NASM: `-I`, `-o`, `-D`, `-f` (format: win64/elf64/macho64/macho32/elf32) ## Incremental Builds Three levels of incrementality: 1. **mtime** — if output is newer than all inputs, skip 2. **`.d` files** — header change tracking (including transitive) 3. **SHA256 fingerprint** — recompile if compiler flags changed (stored in `.dcr_fingerprint`) ## Parallel Compilation - `thread::scope` for thread pool - Atomic task queue (`AtomicU64`) - Mutex on stdout (`OUTPUT_MUTEX`) - Thread count = `available_parallelism()` ## Build Kinds | Kind | Type | Path (Linux example) | |------|------|---------------------| | `bin` | Executable | `target///` (.exe on Windows) | | `staticlib` | Static library | `target///lib.a` (.lib) | | `sharedlib` | Dynamic library | `target///lib.so` (.dll/.dylib) | | `efi` | UEFI application | `target///.efi` | | `elf` | ELF without stdlib | `target///` | | `none` | Compile only, no link | — | | `custom` | Full filename+extension control | `target///.` | ## Build Steps DCR supports pre-build and post-build steps: - `build.steps` — commands before compilation - `build.post_steps` — commands after compilation Substitutions: `{stem}`, `{in}`, `{out}`, `{profile}`, `{version}`, `{name}`. Example Qt codegen via build steps: ```toml [build.steps] moc = "moc {in} -o {out}" ``` ## pkg-config Automatic lookup (read from raw config): ```toml [build] pkg_config = ["sdl2", "gl"] ``` DCR runs `pkg-config --cflags sdl2 gl` and `pkg-config --libs sdl2 gl` and adds results to compiler/linker flags. ## Variable Substitution Supported variables: | Variable | Description | |----------|-------------| | `{version}` | Package version | | `{version_major}` | Major version part | | `{version_minor}` | Minor version part | | `{version_patch}` | Patch version | | `{version_suffix}` | Suffix (e.g., `-rc1`) | | `{version_suffix_dash}` | Suffix with dash | | `{profile}` | Profile name (debug/release) | | `{name}` | Package name |