mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 17:09:35 +00:00
102 lines
2.9 KiB
Plaintext
102 lines
2.9 KiB
Plaintext
---
|
|
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`
|
|
|
|
### 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/<triple>/<profile>/<name>` (.exe on Windows) |
|
|
| `staticlib` | Static library | `target/<triple>/<profile>/lib<name>.a` (.lib) |
|
|
| `sharedlib` | Dynamic library | `target/<triple>/<profile>/lib<name>.so` (.dll/.dylib) |
|
|
| `efi` | UEFI application | `target/<triple>/<profile>/<name>.efi` |
|
|
| `elf` | ELF without stdlib | `target/<triple>/<profile>/<name>` |
|
|
| `none` | Compile only, no link | — |
|
|
| `custom` | Full filename+extension control | `target/<triple>/<profile>/<filename>.<extension>` |
|
|
|
|
## 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 |
|