Files
dcr/docs-crowdin-export/ru-RU/docs/reference/build-system.mdx.mdx
2026-07-06 02:21:36 +08:00

132 lines
6.0 KiB
Plaintext

---
sidebar_label: Система сборки
---
# Build System
## Compiler Backends
DCR поддерживает 4 бэкенда компиляции. Выбор происходит автоматически на основе расширения файла и target triple.
| Backend | Файлы | Когда используется |
| --------- | --------------------------------------- | ------------------------------- |
| `unix_cc` | `.c`, `.cpp`, `.cxx`, `.cc`, `.s`, `.S` | gcc/clang на Linux/macOS/BSD |
| `msvc` | `.c`, `.cpp`, `.cxx`, `.cc` | Windows (cl, clang-cl) |
| `gas` | `.s`, `.S` | ARM/ARM64 ассемблер |
| `nasm` | `.asm`, `.s` | x86/x86_64 ассемблер |
| `masm` | `.asm` | MASM (ml/ml64) on Windows |
| `fasm` | `.asm`, `.fasm` | Flat Assembler |
| `llvm_ir` | `.ll` | LLVM IR via `llc -filetype=obj` |
## Qt Support
DCR provides native Qt support for automatic meta-object handling (MOC, UIC, RCC).
Enable it by setting `build.qt = true` in `dcr.toml`. DCR will automatically detect Qt-related files (`.ui`, `.qrc`, `.h` with `Q_OBJECT`) and process them.
```toml
[build]
qt = true
```
*Note: Requires `qt6` modules (Core, Widgets, Gui, Svg) installed via `pkg-config`.*
Advanced customization is still possible via `build.steps` if special handling is needed:
```toml
[build.steps]
moc = "moc {in} -o {out}"
```
### Unix CC
* Компилятор определяется через `resolve_compiler()`: CC/CXX из [toolchain], DCR_COMPILER/env, PATH
* Поддерживает генерацию `.d` файлов для header dependency tracking
* Флаги: `-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
* Поддерживает cl.exe и clang-cl.exe
* Флаги: `/std:`, `/Fo:`, `/Fe:`, `/I`, `/link`
### GAS / NASM
* GAS: `-I`, `-c -o`, `--defsym`
* NASM: `-I`, `-c -o`, `-D`, `-f` (формат: win64/elf64/macho64/macho32/elf32)
* MASM: `/nologo /c /Fo\<obj> <source>`
* FASM: `<source> \<output>` (output path is the object file)
* LLVM IR: `-filetype=obj <source> -o \<output>`
## Incremental Builds
Три уровня инкрементальности:
1. **mtime** — если выходной файл новее всех входных, файл не перекомпилируется
2. **`.d` files** — отслеживание изменений в заголовочных файлах (включая транзитивные)
3. **SHA256 fingerprint** — если флаги компиляции изменились, файл перекомпилируется (fingerprint хранится в `.dcr_fingerprint`)
## Parallel Compilation
* Используется `thread::scope` для создания пула потоков
* Атомарная очередь задач (`AtomicU64`)
* Мьютекс на запись в stdout (`OUTPUT_MUTEX`)
* Thread count = `available_parallelism()`, capped by `build.codegen-units` if set
## Build Kinds
| Kind | Тип | Path (Linux example) |
| ----------- | ------------------------------------ | ----------------------------------------------------------------------------------------------- |
| `bin` | Executable | `target/\<profile>/\<name>` (.exe) |
| `staticlib` | Статическая библиотека | `target/\<profile>/lib\<name>.a` (.lib) |
| `sharedlib` | Динамическая библиотека | `target/\<profile>/lib\<name>.so` (.dll/.dylib) |
| `efi` | UEFI приложение | `target/\<profile>/\<name>.efi` |
| `elf` | ELF без стандартной библиотеки | `target/\<profile>/\<name>` |
| `none` | Compile only, no link | — |
| `custom` | Полный контроль filename + extension | `target/\<profile>/\<filename>.\<extension>` |
## Build Steps
DCR поддерживает pre-build и post-build шаги через Qt codegen:
* `build.steps` — commands before compilation
* `build.post_steps` — commands after compilation
Подстановки: `{stem}`, `{in}`, `{out}`.
`rcc` — Resource Compiler: `{stem}.qrc → qrc_{stem}.cpp`
```toml
[build.steps]
moc = "moc {in} -o {out}"
```
## pkg-config
Automatic lookup (read from raw config):
```toml
[build]
pkg_config = ["sdl2", "gl"]
```
DCR вызывает `pkg-config --cflags sdl2 gl` и `pkg-config --libs sdl2 gl` и добавляет результат в флаги компиляции/линковки.
## Variable Substitution
Supported variables:
| Variable | Описание |
| ----------------------- | ------------------------------- |
| `{version}` | Версия пакета |
| `{version_major}` | Major version part |
| `{version_minor}` | Minor version part |
| `{version_patch}` | Переменная |
| `{version_suffix}` | Suffix (e.g., `-rc1`) |
| `{version_suffix_dash}` | Suffix with dash |
| `{profile}` | Имя профиля (debug/release/...) |
| `{name}` | Имя пакета |